diff options
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) |