From 052fd1c407e506fd3e4a4593b06193cc7d31c2c3 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 6 Jan 2017 16:59:57 -0800 Subject: [PATCH] Extract loop into static method. Performance boost as compiler is no longer updating member variable every pass through the loop. --- firmware/baseband/channel_stats_collector.hpp | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/firmware/baseband/channel_stats_collector.hpp b/firmware/baseband/channel_stats_collector.hpp index 44d70753..8e69448e 100644 --- a/firmware/baseband/channel_stats_collector.hpp +++ b/firmware/baseband/channel_stats_collector.hpp @@ -36,15 +36,7 @@ class ChannelStatsCollector { public: template void feed(const buffer_c16_t& src, Callback callback) { - auto src_p = simd32_ptr(src.p); - const auto end_p = simd32_ptr(&src.p[src.count]); - while(src_p < end_p) { - const uint32_t sample = *(src_p++); - const uint32_t mag_sq = __SMUAD(sample, sample); - if( mag_sq > max_squared ) { - max_squared = mag_sq; - } - } + max_squared = compute_max_squared(src, max_squared); count += src.count; const size_t samples_per_update = src.sampling_rate * update_interval; @@ -63,6 +55,24 @@ private: static constexpr float update_interval { 0.1f }; uint32_t max_squared { 0 }; size_t count { 0 }; + + static uint32_t compute_max_squared( + const buffer_c16_t& src, + uint32_t max_squared + ) { + auto p = simd32_ptr(src.p); + const auto end_p = simd32_ptr(&src.p[src.count]); + + while(p < end_p) { + const uint32_t sample = *(p++); + const uint32_t mag_sq = __SMUAD(sample, sample); + if( mag_sq > max_squared ) { + max_squared = mag_sq; + } + } + + return max_squared; + } }; #endif/*__CHANNEL_STATS_COLLECTOR_H__*/