Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
Extract loop into static method.
Browse files Browse the repository at this point in the history
Performance boost as compiler is no longer updating member variable every pass through the loop.
  • Loading branch information
jboone committed Jan 7, 2017
1 parent 05eb694 commit 052fd1c
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions firmware/baseband/channel_stats_collector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ class ChannelStatsCollector {
public:
template<typename Callback>
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;
Expand All @@ -63,6 +55,24 @@ class ChannelStatsCollector {
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__*/

0 comments on commit 052fd1c

Please sign in to comment.