diff options
author | Martin Braun <martin.braun@ettus.com> | 2021-06-19 00:06:52 +0200 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-06-24 12:00:49 -0500 |
commit | 188fbb17cfd18c87f60ec56f62476f97ef2779bb (patch) | |
tree | e88b9fb8436aa42f3ecbdc0403751a3e68bbbac8 /host/lib/usrp/dboard | |
parent | 78ec29b6becd53f79a0ae282ae22c38bedb887d1 (diff) | |
download | uhd-188fbb17cfd18c87f60ec56f62476f97ef2779bb.tar.gz uhd-188fbb17cfd18c87f60ec56f62476f97ef2779bb.tar.bz2 uhd-188fbb17cfd18c87f60ec56f62476f97ef2779bb.zip |
uhd: Remove all occurences of boost::math::*round()
Its behaviour is almost identical to std::lround, which we use instead.
The only downside of std::lround is that it always returns a long, which
we don't always need. We thus add some casts for those cases to make the
compiler happy.
Diffstat (limited to 'host/lib/usrp/dboard')
-rw-r--r-- | host/lib/usrp/dboard/db_dbsrx.cpp | 9 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_dbsrx2.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_rfx.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_tvrx2.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_wbx_common.cpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_wbx_version3.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_wbx_version4.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/dboard/db_xcvr2450.cpp | 24 | ||||
-rw-r--r-- | host/lib/usrp/dboard/twinrx/twinrx_experts.cpp | 4 |
9 files changed, 35 insertions, 29 deletions
diff --git a/host/lib/usrp/dboard/db_dbsrx.cpp b/host/lib/usrp/dboard/db_dbsrx.cpp index a55e5fc70..09690a3d1 100644 --- a/host/lib/usrp/dboard/db_dbsrx.cpp +++ b/host/lib/usrp/dboard/db_dbsrx.cpp @@ -21,7 +21,6 @@ #include <uhd/utils/static.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/round.hpp> #include <chrono> #include <cmath> #include <functional> @@ -491,11 +490,11 @@ static int gain_to_gc2_vga_reg(double& gain) // Half dB steps from 0-5dB, 1dB steps from 5-24dB if (gain < 5) { - reg = boost::math::iround(31.0 - gain / 0.5); - gain = double(boost::math::iround(gain) * 0.5); + reg = static_cast<int>(std::lround(31.0 - gain / 0.5)); + gain = std::round(gain) * 0.5; } else { - reg = boost::math::iround(22.0 - (gain - 4.0)); - gain = double(boost::math::iround(gain)); + reg = static_cast<int>(std::lround(22.0 - (gain - 4.0))); + gain = std::round(gain); } UHD_LOGGER_TRACE("DBSRX") << boost::format("DBSRX GC2 Gain: %f dB, reg: %d") % gain diff --git a/host/lib/usrp/dboard/db_dbsrx2.cpp b/host/lib/usrp/dboard/db_dbsrx2.cpp index 7635327b1..16a418417 100644 --- a/host/lib/usrp/dboard/db_dbsrx2.cpp +++ b/host/lib/usrp/dboard/db_dbsrx2.cpp @@ -19,8 +19,8 @@ #include <uhd/utils/static.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/round.hpp> #include <boost/thread.hpp> +#include <cmath> #include <functional> #include <utility> @@ -258,7 +258,7 @@ double dbsrx2::set_lo_freq(double target_freq) N = (target_freq * R * ext_div) / (ref_freq); // actual spec range is (19, 251) intdiv = int(std::floor(N)); // if (intdiv < 19 or intdiv > 251) continue; - fracdiv = boost::math::iround((N - intdiv) * double(1 << 20)); + fracdiv = static_cast<int>(std::lround((N - intdiv) * double(1 << 20))); // calculate the actual freq from the values above N = double(intdiv) + double(fracdiv) / double(1 << 20); @@ -305,7 +305,7 @@ double dbsrx2::set_lo_freq(double target_freq) */ static int gain_to_bbg_vga_reg(double& gain) { - int reg = boost::math::iround(dbsrx2_gain_ranges["BBG"].clip(gain)); + int reg = static_cast<int>(std::lround(dbsrx2_gain_ranges["BBG"].clip(gain))); gain = double(reg); diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index f4de7ccaa..ff26c2d29 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -35,7 +35,7 @@ #include <uhd/utils/static.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/round.hpp> +#include <cmath> #include <functional> using namespace uhd; @@ -441,7 +441,7 @@ double rfx_xcvr::set_lo_freq(dboard_iface::unit_t unit, double target_freq) // calculate B and A from N double N = target_freq * R / ref_freq; B = int(std::floor(N / P)); - A = boost::math::iround(N - P * B); + A = static_cast<int>(std::lround(N - P * B)); if (B < A or B > 8191 or B < 3 or A > 31) { continue; // constraints on A, B } diff --git a/host/lib/usrp/dboard/db_tvrx2.cpp b/host/lib/usrp/dboard/db_tvrx2.cpp index cc1249dee..6f7581953 100644 --- a/host/lib/usrp/dboard/db_tvrx2.cpp +++ b/host/lib/usrp/dboard/db_tvrx2.cpp @@ -54,9 +54,10 @@ #include <uhd/usrp/dboard_base.hpp> #include <uhd/usrp/dboard_manager.hpp> #include <boost/assign/list_of.hpp> +#include <uhdlib/utils/narrow.hpp> #include <boost/format.hpp> #include <boost/array.hpp> -#include <boost/math/special_functions/round.hpp> +#include <cmath> #include <utility> #include <cmath> #include <chrono> @@ -1966,7 +1967,8 @@ double tvrx2::set_gain(double gain, const std::string& name) **********************************************************************/ static tda18272hnm_regs_t::lp_fc_t bandwidth_to_lp_fc_reg(double& bandwidth) { - int reg = uhd::clip(boost::math::iround((bandwidth - 5.0e6) / 1.0e6), 0, 4); + int reg = + uhd::clip(uhd::narrow_cast<int>(std::lround((bandwidth - 5.0e6)) / 1.0e6), 0, 4); switch (reg) { case 0: diff --git a/host/lib/usrp/dboard/db_wbx_common.cpp b/host/lib/usrp/dboard/db_wbx_common.cpp index df89e3779..6e306f36b 100644 --- a/host/lib/usrp/dboard/db_wbx_common.cpp +++ b/host/lib/usrp/dboard/db_wbx_common.cpp @@ -12,6 +12,7 @@ #include <uhd/utils/algorithm.hpp> #include <uhd/utils/assert_has.hpp> #include <uhd/utils/log.hpp> +#include <cmath> #include <functional> using namespace uhd; @@ -31,7 +32,7 @@ static int rx_pga0_gain_to_iobits(double& gain) double attn = wbx_rx_gain_ranges["PGA0"].stop() - gain; // calculate the attenuation - int attn_code = boost::math::iround(attn * 2); + int attn_code = static_cast<int>(std::lround(attn * 2)); int iobits = ((~attn_code) << RX_ATTN_SHIFT) & RX_ATTN_MASK; UHD_LOGGER_TRACE("WBX") diff --git a/host/lib/usrp/dboard/db_wbx_version3.cpp b/host/lib/usrp/dboard/db_wbx_version3.cpp index 51902b3aa..599119899 100644 --- a/host/lib/usrp/dboard/db_wbx_version3.cpp +++ b/host/lib/usrp/dboard/db_wbx_version3.cpp @@ -16,7 +16,7 @@ #include <boost/algorithm/string.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/round.hpp> +#include <cmath> #include <functional> using namespace uhd; @@ -44,7 +44,7 @@ static int tx_pga0_gain_to_iobits(double& gain) double attn = wbx_v3_tx_gain_ranges["PGA0"].stop() - gain; // calculate the attenuation - int attn_code = boost::math::iround(attn); + int attn_code = static_cast<int>(std::lround(attn)); int iobits = ((attn_code & 16 ? 0 : TX_ATTN_16) | (attn_code & 8 ? 0 : TX_ATTN_8) | (attn_code & 4 ? 0 : TX_ATTN_4) | (attn_code & 2 ? 0 : TX_ATTN_2) | (attn_code & 1 ? 0 : TX_ATTN_1)) diff --git a/host/lib/usrp/dboard/db_wbx_version4.cpp b/host/lib/usrp/dboard/db_wbx_version4.cpp index 54c0a9c21..cc278dd0b 100644 --- a/host/lib/usrp/dboard/db_wbx_version4.cpp +++ b/host/lib/usrp/dboard/db_wbx_version4.cpp @@ -16,7 +16,7 @@ #include <boost/algorithm/string.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/round.hpp> +#include <cmath> #include <functional> using namespace uhd; @@ -45,7 +45,7 @@ static int tx_pga0_gain_to_iobits(double& gain) double attn = wbx_v4_tx_gain_ranges["PGA0"].stop() - gain; // calculate the attenuation - int attn_code = boost::math::iround(attn); + int attn_code = static_cast<int>(std::lround(attn)); int iobits = ((attn_code & 16 ? 0 : TX_ATTN_16) | (attn_code & 8 ? 0 : TX_ATTN_8) | (attn_code & 4 ? 0 : TX_ATTN_4) | (attn_code & 2 ? 0 : TX_ATTN_2) | (attn_code & 1 ? 0 : TX_ATTN_1)) diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index 26c0d5950..b6b8858e7 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -50,10 +50,11 @@ #include <uhd/utils/log.hpp> #include <uhd/utils/safe_call.hpp> #include <uhd/utils/static.hpp> +#include <uhdlib/utils/narrow.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> -#include <boost/math/special_functions/round.hpp> #include <chrono> +#include <cmath> #include <functional> #include <thread> #include <utility> @@ -410,7 +411,7 @@ double xcvr2450::set_lo_freq_core(double target_freq) for (R = 1; R <= 7; R++) { double N = (target_freq * scaler * R * _ad9515div) / ref_freq; intdiv = int(std::floor(N)); - fracdiv = boost::math::iround((N - intdiv) * double(1 << 16)); + fracdiv = uhd::narrow_cast<int>(std::lround((N - intdiv)) * double(1 << 16)); // actual minimum is 128, but most chips seems to require higher to lock if (intdiv < 131 or intdiv > 255) continue; @@ -504,7 +505,7 @@ void xcvr2450::set_rx_ant(const std::string& ant) static int gain_to_tx_vga_reg(double& gain) { // calculate the register value - int reg = uhd::clip(boost::math::iround(gain * 60 / 30.0) + 3, 0, 63); + int reg = uhd::clip(uhd::narrow_cast<int>(std::lround(gain * 60 / 30.0) + 3), 0, 63); // calculate the actual gain value if (reg < 4) @@ -526,7 +527,7 @@ static int gain_to_tx_vga_reg(double& gain) */ static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(double& gain) { - int reg = uhd::clip(boost::math::iround(gain * 3 / 5.0), 0, 3); + int reg = uhd::clip(uhd::narrow_cast<int>(std::lround<int>(gain * 3 / 5.0)), 0, 3); switch (reg) { case 0: gain = 0; @@ -552,7 +553,7 @@ static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(double& gain) */ static int gain_to_rx_vga_reg(double& gain) { - int reg = uhd::clip(boost::math::iround(gain / 2.0), 0, 31); + int reg = uhd::clip(uhd::narrow_cast<int>(std::lround(gain / 2.0)), 0, 31); gain = double(reg * 2); return reg; } @@ -565,7 +566,7 @@ static int gain_to_rx_vga_reg(double& gain) */ static int gain_to_rx_lna_reg(double& gain) { - int reg = uhd::clip(boost::math::iround(gain * 2 / 30.5) + 1, 0, 3); + int reg = uhd::clip(uhd::narrow_cast<int>(std::lround(gain * 2 / 30.5)) + 1, 0, 3); switch (reg) { case 0: case 1: @@ -620,7 +621,7 @@ double xcvr2450::set_rx_gain(double gain, const std::string& name) static max2829_regs_t::tx_lpf_coarse_adj_t bandwidth_to_tx_lpf_coarse_reg( double& bandwidth) { - int reg = uhd::clip(boost::math::iround((bandwidth - 6.0e6) / 6.0e6), 1, 3); + int reg = uhd::clip(uhd::narrow_cast<int>(std::lround((bandwidth - 6.0e6)) / 6.0e6), 1, 3); switch (reg) { case 1: // bandwidth < 15MHz @@ -639,8 +640,10 @@ static max2829_regs_t::tx_lpf_coarse_adj_t bandwidth_to_tx_lpf_coarse_reg( static max2829_regs_t::rx_lpf_fine_adj_t bandwidth_to_rx_lpf_fine_reg( double& bandwidth, double requested_bandwidth) { - int reg = - uhd::clip(boost::math::iround((requested_bandwidth / bandwidth) / 0.05), 18, 22); + int reg = uhd::clip( + uhd::narrow_cast<int>(std::lround((requested_bandwidth / bandwidth)) / 0.05), + 18, + 22); switch (reg) { case 18: // requested_bandwidth < 92.5% @@ -665,7 +668,8 @@ static max2829_regs_t::rx_lpf_fine_adj_t bandwidth_to_rx_lpf_fine_reg( static max2829_regs_t::rx_lpf_coarse_adj_t bandwidth_to_rx_lpf_coarse_reg( double& bandwidth) { - int reg = uhd::clip(boost::math::iround((bandwidth - 7.0e6) / 1.0e6), 0, 11); + int reg = + uhd::clip(uhd::narrow_cast<int>(std::lround((bandwidth - 7.0e6)) / 1.0e6), 0, 11); switch (reg) { case 0: // bandwidth < 7.5MHz diff --git a/host/lib/usrp/dboard/twinrx/twinrx_experts.cpp b/host/lib/usrp/dboard/twinrx/twinrx_experts.cpp index 8d3ba591b..58e22e089 100644 --- a/host/lib/usrp/dboard/twinrx/twinrx_experts.cpp +++ b/host/lib/usrp/dboard/twinrx/twinrx_experts.cpp @@ -13,7 +13,7 @@ #include <uhd/utils/log.hpp> #include <uhd/utils/math.hpp> #include <boost/assign/list_of.hpp> -#include <boost/math/special_functions/round.hpp> +#include <cmath> using namespace uhd::experts; using namespace uhd::math; @@ -271,7 +271,7 @@ void twinrx_chan_gain_expert::resolve() // Compute minimum gain. The user-specified gain value will be interpreted as // the gain applied on top of the minimum gain state. // If antennas are shared or swapped, the switch has 6dB of loss - size_t gain_index = std::min(static_cast<size_t>(boost::math::round(_gain.get())), + size_t gain_index = std::min(static_cast<size_t>(std::lround(_gain.get())), table.get_num_entries() - 1); // Translate gain to an index in the gain table |