1From dc187b5597779b14d0de4087db4aa54752a15d07 Mon Sep 17 00:00:00 2001
2From: Michael Dickens <michael.dickens@ettus.com>
3Date: Fri, 2 Jul 2021 16:43:41 -0400
4Subject: [PATCH] core: remove boost::math in favor of std cmath
5
6YA Boost removal!!!
7
8Justification
9---
10const int if_freq_sign = boost::math::sign(fe_conn.get_if_freq());
11_dsp_freq_offset = if_freq * (-if_freq_sign);
12// boost::math::sign : 1 if x > 0, -1 if x < 0, and 0 if x is zero.
13// ==> if if_freq_sign > 0 then * by -1 else +1 (effectively)
14
15// std::signbit : true if arg is negative, false otherwise
16// ==> need 'not' of input argument to invert for same result as prior algorithm
17double fe_if_freq = fe_conn.get_if_freq();
18if (!std::signbit(fe_if_freq)) {
19  if_freq *= -1.0;
20}
21---
22The above should result in the same algorithm except possibly
23if fe_if_freq is exactly 0.0 in which case the results might be
24off by the sign (+0.0 versus -0.0).
25
26[Retrieved from:
27https://github.com/EttusResearch/uhd/commit/dc187b5597779b14d0de4087db4aa54752a15d07]
28Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
29---
30 host/lib/usrp/cores/rx_dsp_core_3000.cpp      | 15 ++++++++-------
31 host/lib/usrp/cores/rx_frontend_core_3000.cpp | 14 ++++++++------
32 2 files changed, 16 insertions(+), 13 deletions(-)
33
34diff --git a/host/lib/usrp/cores/rx_dsp_core_3000.cpp b/host/lib/usrp/cores/rx_dsp_core_3000.cpp
35index 879748fa2..1c15180ae 100644
36--- a/host/lib/usrp/cores/rx_dsp_core_3000.cpp
37+++ b/host/lib/usrp/cores/rx_dsp_core_3000.cpp
38@@ -8,7 +8,6 @@
39 #include <uhd/exception.hpp>
40 #include <uhd/types/dict.hpp>
41 #include <uhd/utils/log.hpp>
42-#include <uhd/utils/math.hpp>
43 #include <uhd/utils/safe_call.hpp>
44 #include <uhdlib/usrp/cores/dsp_core_utils.hpp>
45 #include <uhdlib/usrp/cores/rx_dsp_core_3000.hpp>
46@@ -81,19 +80,21 @@ class rx_dsp_core_3000_impl : public rx_dsp_core_3000
47         _iface->poke32(REG_DSP_RX_MUX, reg_val);
48
49         if (fe_conn.get_sampling_mode() == uhd::usrp::fe_connection_t::HETERODYNE) {
50-            // 1. Remember the sign of the IF frequency.
51-            //   It will be discarded in the next step
52-            int if_freq_sign = boost::math::sign(fe_conn.get_if_freq());
53+            // 1. Remember the IF frequency
54+            const double fe_if_freq = fe_conn.get_if_freq();
55             // 2. Map IF frequency to the range [0, _tick_rate)
56-            double if_freq = std::abs(std::fmod(fe_conn.get_if_freq(), _tick_rate));
57-            // 3. Map IF frequency to the range [-_tick_rate/2, _tick_rate/2)
58+            double if_freq = std::abs(std::fmod(fe_if_freq, _tick_rate));
59+            // 3. Map IF frequency to the range [-_tick_rate/2, _tick_rate/2]
60             //   This is the aliased frequency
61             if (if_freq > (_tick_rate / 2.0)) {
62                 if_freq -= _tick_rate;
63             }
64             // 4. Set DSP offset to spin the signal in the opposite
65             //   direction as the aliased frequency
66-            _dsp_freq_offset = if_freq * (-if_freq_sign);
67+            if (!std::signbit(fe_if_freq)) {
68+                if_freq *= -1.0;
69+            }
70+            _dsp_freq_offset = if_freq;
71         } else {
72             _dsp_freq_offset = 0.0;
73         }
74diff --git a/host/lib/usrp/cores/rx_frontend_core_3000.cpp b/host/lib/usrp/cores/rx_frontend_core_3000.cpp
75index eef25f27d..b9d908534 100644
76--- a/host/lib/usrp/cores/rx_frontend_core_3000.cpp
77+++ b/host/lib/usrp/cores/rx_frontend_core_3000.cpp
78@@ -119,19 +119,21 @@ class rx_frontend_core_3000_impl : public rx_frontend_core_3000
79
80         UHD_ASSERT_THROW(_adc_rate != 0.0)
81         if (fe_conn.get_sampling_mode() == fe_connection_t::HETERODYNE) {
82-            // 1. Remember the sign of the IF frequency.
83-            //   It will be discarded in the next step
84-            const int if_freq_sign = boost::math::sign(fe_conn.get_if_freq());
85+            // 1. Remember the IF frequency
86+            const double fe_if_freq = fe_conn.get_if_freq();
87             // 2. Map IF frequency to the range [0, _adc_rate)
88-            double if_freq = std::abs(std::fmod(fe_conn.get_if_freq(), _adc_rate));
89-            // 3. Map IF frequency to the range [-_adc_rate/2, _adc_rate/2)
90+            double if_freq = std::abs(std::fmod(fe_if_freq, _adc_rate));
91+            // 3. Map IF frequency to the range [-_adc_rate/2, _adc_rate/2]
92             //   This is the aliased frequency
93             if (if_freq > (_adc_rate / 2.0)) {
94                 if_freq -= _adc_rate;
95             }
96             // 4. Set DSP offset to spin the signal in the opposite
97             //   direction as the aliased frequency
98-            const double cordic_freq = if_freq * (-if_freq_sign);
99+            if (!std::signbit(fe_if_freq)) {
100+                if_freq *= -1.0;
101+            }
102+            const double cordic_freq = if_freq;
103             UHD_ASSERT_THROW(uhd::math::fp_compare::fp_compare_epsilon<double>(4.0)
104                              == std::abs(_adc_rate / cordic_freq));
105
106