diff options
author | ghostop14 <ghostop14@gmail.com> | 2020-01-29 17:20:16 -0500 |
---|---|---|
committer | Michael Dickens <michael.dickens@ettus.com> | 2020-02-14 10:05:12 -0500 |
commit | aa0bd44efbf8afdfd93d627e486c1427426b76f9 (patch) | |
tree | dd2acb4ebed83dc5a553678ba46b76424690b90a /gnuradio-runtime/include/gnuradio/math.h | |
parent | 36680f338e0b7ae7e5bcf7d2a860527ca7b14dfe (diff) |
gr-digital: Improve Performance of Costas Loop
This update is focused on improving the throughput of the Costas
loop, however some changes are more global performance enhancements
as this PR has evolved. Updates include an ENABLE_NATIVE added to
CMake, which is off by default but enables native compiling (including
FMA support) if desired; sincos was inlined in sincos.h and sincos.cc
was removed from the appropriate CMake to improve sincos speed, some
constants were added to math.h, inlined functions in costas loop and
nco.h, used switch instead of function pointer (much faster), and
used fast complex multiply to get around all the range checking in
the standard complex.h complex multiply function on all builds.
Diffstat (limited to 'gnuradio-runtime/include/gnuradio/math.h')
-rw-r--r-- | gnuradio-runtime/include/gnuradio/math.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/gnuradio-runtime/include/gnuradio/math.h b/gnuradio-runtime/include/gnuradio/math.h index c0e1a7dc88..f628a5875c 100644 --- a/gnuradio-runtime/include/gnuradio/math.h +++ b/gnuradio-runtime/include/gnuradio/math.h @@ -31,12 +31,30 @@ #define GR_M_LOG2E 1.4426950408889634074 /* log_2 e */ #define GR_M_PI 3.14159265358979323846 /* pi */ #define GR_M_PI_4 0.78539816339744830961566084582 /* pi/4 */ -#define GR_M_TWOPI (2 * GR_M_PI) /* 2*pi */ +#define GR_M_TWOPI 6.28318530717958647692 /* 2*pi */ #define GR_M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#define GR_M_ONE_OVER_2PI 0.15915494309189533577 /* 1 / (2*pi) */ +#define GR_M_MINUS_TWO_PI -6.28318530717958647692 /* - 2*pi */ namespace gr { +static inline void +fast_cc_multiply(gr_complex& out, const gr_complex cc1, const gr_complex cc2) +{ + // The built-in complex.h multiply has significant NaN/INF checking that + // considerably slows down performance. While on some compilers the + // -fcx-limit-range flag can be used, this fast function makes the math consistent + // in terms of performance for the Costas loop. + float o_r, o_i; + + o_r = (cc1.real() * cc2.real()) - (cc1.imag() * cc2.imag()); + o_i = (cc1.real() * cc2.imag()) + (cc1.imag() * cc2.real()); + + out.real(o_r); + out.imag(o_i); +} + static inline bool is_power_of_2(long x) { return x != 0 && (x & (x - 1)) == 0; } /*! @@ -62,10 +80,7 @@ static inline float fast_atan2f(gr_complex z) { return fast_atan2f(z.imag(), z.r /* This bounds x by +/- clip without a branch */ static inline float branchless_clip(float x, float clip) { - float x1 = fabsf(x + clip); - float x2 = fabsf(x - clip); - x1 -= x2; - return 0.5 * x1; + return 0.5 * (std::abs(x + clip) - std::abs(x - clip)); } static inline float clip(float x, float clip) |