aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-01-15 15:04:03 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-01-18 09:37:12 -0800
commit7fab6b807ef5b86c97577170b7b5fdc667e3fa20 (patch)
tree0cdb0ab0711599d36f192c77a6129abbf235ad73 /host
parent11c7e561fc29b56ade8ae6ec549b21c533540e8a (diff)
downloaduhd-7fab6b807ef5b86c97577170b7b5fdc667e3fa20.tar.gz
uhd-7fab6b807ef5b86c97577170b7b5fdc667e3fa20.tar.bz2
uhd-7fab6b807ef5b86c97577170b7b5fdc667e3fa20.zip
math: Replace boost::*::{lcm,gcd}() with portable versions
Boost changed the lcm() and gcd() functions in Boost 1.67. This creates portable UHD versions to be used instead. They use various Boost versions under the hood conditionally.
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/utils/math.hpp23
-rw-r--r--host/lib/include/uhdlib/usrp/common/adf535x.hpp9
-rw-r--r--host/lib/include/uhdlib/usrp/common/lmx2592.hpp1
-rw-r--r--host/lib/usrp/b100/clock_ctrl.cpp8
-rw-r--r--host/lib/usrp/b200/b200_io_impl.cpp3
-rw-r--r--host/tests/math_test.cpp10
6 files changed, 40 insertions, 14 deletions
diff --git a/host/include/uhd/utils/math.hpp b/host/include/uhd/utils/math.hpp
index 8606923fa..944e9a951 100644
--- a/host/include/uhd/utils/math.hpp
+++ b/host/include/uhd/utils/math.hpp
@@ -12,6 +12,15 @@
#include <stdint.h>
#include <boost/numeric/conversion/bounds.hpp>
#include <cmath>
+#if BOOST_VERSION >= 106700
+# include <boost/integer/common_factor.hpp>
+// "bmint" for "boost math integer"
+namespace _bmint = boost::integer;
+#else
+# include <boost/math/common_factor.hpp>
+namespace _bmint = boost::math;
+#endif
+
namespace uhd {
@@ -223,6 +232,20 @@ UHD_INLINE bool frequencies_are_equal(double lhs, double rhs)
== fp_compare::fp_compare_delta<double>(rhs, FREQ_COMPARISON_DELTA_HZ));
}
+//! Portable version of lcm() across Boost versions
+template <typename IntegerType> inline IntegerType lcm(IntegerType x, IntegerType y)
+{
+ // Note: _bmint is defined conditionally at the top of the file
+ return _bmint::lcm<IntegerType>(x, y);
+}
+
+//! Portable version of gcd() across Boost versions
+template <typename IntegerType> inline IntegerType gcd(IntegerType x, IntegerType y)
+{
+ // Note: _bmint is defined conditionally at the top of the file
+ return _bmint::gcd<IntegerType>(x, y);
+}
+
} // namespace math
} // namespace uhd
diff --git a/host/lib/include/uhdlib/usrp/common/adf535x.hpp b/host/lib/include/uhdlib/usrp/common/adf535x.hpp
index 200610d02..6350261ef 100644
--- a/host/lib/include/uhdlib/usrp/common/adf535x.hpp
+++ b/host/lib/include/uhdlib/usrp/common/adf535x.hpp
@@ -15,7 +15,6 @@
#include <stdint.h>
#include <boost/format.hpp>
#include <boost/function.hpp>
-#include <boost/math/common_factor_rt.hpp> //gcd
#include <algorithm>
#include <utility>
#include <vector>
@@ -376,8 +375,8 @@ inline double adf535x_impl<adf5355_regs_t>::_set_frequency(
const auto FRAC1 = static_cast<uint32_t>(floor((N - INT) * ADF535X_MOD1));
const double residue = (N - INT) * ADF535X_MOD1 - FRAC1;
- const double gcd =
- boost::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution));
+ const double gcd = double(
+ uhd::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution)));
const auto MOD2 = static_cast<uint16_t>(
std::min(floor(_pfd_freq / gcd), static_cast<double>(ADF535X_MAX_MOD2)));
const auto FRAC2 = static_cast<uint16_t>(
@@ -491,8 +490,8 @@ inline double adf535x_impl<adf5356_regs_t>::_set_frequency(
const auto FRAC1 = static_cast<uint32_t>(floor((N - INT) * ADF535X_MOD1));
const double residue = (N - INT) * ADF535X_MOD1 - FRAC1;
- const double gcd =
- boost::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution));
+ const double gcd = double(
+ uhd::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution)));
const auto MOD2 = static_cast<uint16_t>(
std::min(floor(_pfd_freq / gcd), static_cast<double>(ADF535X_MAX_MOD2)));
const auto FRAC2 = static_cast<uint16_t>(
diff --git a/host/lib/include/uhdlib/usrp/common/lmx2592.hpp b/host/lib/include/uhdlib/usrp/common/lmx2592.hpp
index f71ae0cf5..181b81269 100644
--- a/host/lib/include/uhdlib/usrp/common/lmx2592.hpp
+++ b/host/lib/include/uhdlib/usrp/common/lmx2592.hpp
@@ -13,7 +13,6 @@
#include <uhd/utils/safe_call.hpp>
#include <boost/format.hpp>
#include <boost/function.hpp>
-#include <boost/math/common_factor_rt.hpp> //gcd
#include <algorithm>
#include <cstdint>
#include <utility>
diff --git a/host/lib/usrp/b100/clock_ctrl.cpp b/host/lib/usrp/b100/clock_ctrl.cpp
index e30ca120f..676ebd981 100644
--- a/host/lib/usrp/b100/clock_ctrl.cpp
+++ b/host/lib/usrp/b100/clock_ctrl.cpp
@@ -11,10 +11,11 @@
#include <uhd/exception.hpp>
#include <uhd/utils/assert_has.hpp>
#include <uhd/utils/log.hpp>
+#include <uhd/utils/math.hpp>
#include <uhd/utils/safe_call.hpp>
+#include <uhdlib/utils/narrow.hpp>
#include <stdint.h>
#include <boost/format.hpp>
-#include <boost/math/common_factor_rt.hpp> //gcd
#include <algorithm>
#include <chrono>
#include <thread>
@@ -122,7 +123,8 @@ static clock_settings_type get_clock_settings(double rate)
const uint64_t out_rate = uint64_t(rate);
const uint64_t ref_rate = uint64_t(cs.get_ref_rate());
- const size_t gcd = size_t(boost::math::gcd(ref_rate, out_rate));
+ const size_t gcd =
+ uhd::narrow_cast<size_t>((uhd::math::gcd<size_t>(ref_rate, out_rate)));
for (size_t i = 1; i <= 100; i++) {
const size_t X = size_t(i * ref_rate / gcd);
@@ -312,7 +314,7 @@ public:
const double ref_rate = REFERENCE_INPUT_RATE * 2;
// bypass prescaler such that N = B
- long gcd = boost::math::gcd(long(ref_rate), long(rate));
+ long gcd = uhd::math::gcd(long(ref_rate), long(rate));
_ad9522_regs.set_r_counter(int(ref_rate / gcd));
_ad9522_regs.a_counter = 0;
_ad9522_regs.set_b_counter(int(rate / gcd));
diff --git a/host/lib/usrp/b200/b200_io_impl.cpp b/host/lib/usrp/b200/b200_io_impl.cpp
index 4f4eba052..69797017b 100644
--- a/host/lib/usrp/b200/b200_io_impl.cpp
+++ b/host/lib/usrp/b200/b200_io_impl.cpp
@@ -14,7 +14,6 @@
#include <uhdlib/usrp/common/validate_subdev_spec.hpp>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
-#include <boost/math/common_factor.hpp>
#include <set>
using namespace uhd;
@@ -111,7 +110,7 @@ void b200_impl::set_auto_tick_rate(
}
// Clean up floating point rounding errors if they crept in
this_dsp_rate = std::min(max_tick_rate, this_dsp_rate);
- lcm_rate = boost::math::lcm<uint32_t>(
+ lcm_rate = uhd::math::lcm<uint32_t>(
lcm_rate, static_cast<uint32_t>(floor(this_dsp_rate + 0.5)));
}
}
diff --git a/host/tests/math_test.cpp b/host/tests/math_test.cpp
index 575cfe071..4714f6625 100644
--- a/host/tests/math_test.cpp
+++ b/host/tests/math_test.cpp
@@ -9,8 +9,12 @@
#include <stdint.h>
#include <boost/test/unit_test.hpp>
-// We need an empty test
-BOOST_AUTO_TEST_CASE(test_)
+BOOST_AUTO_TEST_CASE(test_lcm)
{
- BOOST_CHECK_EQUAL(true, true);
+ BOOST_CHECK_EQUAL(uhd::math::lcm<int>(2, 3), 6);
+}
+
+BOOST_AUTO_TEST_CASE(test_gcd)
+{
+ BOOST_CHECK_EQUAL(uhd::math::gcd<int>(6, 15), 3);
}