From df6d61dd40b602af55f903564358b083bb8b37e4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 5 Dec 2022 14:51:03 -0800 Subject: Use standard likely/unlikely attributes when available --- common/polyphase_resampler.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'common/polyphase_resampler.cpp') diff --git a/common/polyphase_resampler.cpp b/common/polyphase_resampler.cpp index bb8f69a4..76723915 100644 --- a/common/polyphase_resampler.cpp +++ b/common/polyphase_resampler.cpp @@ -21,7 +21,7 @@ using uint = unsigned int; */ double Sinc(const double x) { - if(unlikely(std::abs(x) < Epsilon)) + if(std::abs(x) < Epsilon) [[alunlikely]] return 1.0; return std::sin(al::numbers::pi*x) / (al::numbers::pi*x); } @@ -96,7 +96,7 @@ constexpr uint Gcd(uint x, uint y) constexpr uint CalcKaiserOrder(const double rejection, const double transition) { const double w_t{2.0 * al::numbers::pi * transition}; - if LIKELY(rejection > 21.0) + if(rejection > 21.0) [[allikely]] return static_cast(std::ceil((rejection - 7.95) / (2.285 * w_t))); return static_cast(std::ceil(5.79 / w_t)); } @@ -104,7 +104,7 @@ constexpr uint CalcKaiserOrder(const double rejection, const double transition) // Calculates the beta value of the Kaiser window. Rejection is in dB. constexpr double CalcKaiserBeta(const double rejection) { - if LIKELY(rejection > 50.0) + if(rejection > 50.0) [[allikely]] return 0.1102 * (rejection - 8.7); if(rejection >= 21.0) return (0.5842 * std::pow(rejection - 21.0, 0.4)) + @@ -171,13 +171,13 @@ void PPhaseResampler::init(const uint srcRate, const uint dstRate) // polyphase filter implementation. void PPhaseResampler::process(const uint inN, const double *in, const uint outN, double *out) { - if UNLIKELY(outN == 0) + if(outN == 0) [[alunlikely]] return; // Handle in-place operation. std::vector workspace; double *work{out}; - if UNLIKELY(work == in) + if(work == in) [[alunlikely]] { workspace.resize(outN); work = workspace.data(); @@ -195,17 +195,17 @@ void PPhaseResampler::process(const uint inN, const double *in, const uint outN, // Only take input when 0 <= j_s < inN. double r{0.0}; - if LIKELY(j_f < m) + if(j_f < m) [[allikely]] { size_t filt_len{(m-j_f+p-1) / p}; - if LIKELY(j_s+1 > inN) + if(j_s+1 > inN) [[allikely]] { size_t skip{std::min(j_s+1 - inN, filt_len)}; j_f += p*skip; j_s -= skip; filt_len -= skip; } - if(size_t todo{std::min(j_s+1, filt_len)}) + if(size_t todo{std::min(j_s+1, filt_len)}) [[allikely]] { do { r += f[j_f] * in[j_s]; -- cgit v1.2.3