summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorNicholas Corgan <n.corgan@gmail.com>2021-05-07 14:10:19 -0500
committerMarcus Müller <marcus@hostalia.de>2021-05-13 14:50:15 +0200
commite1dfa8c62b31661d249f3d0f6a0395b01a2e21f9 (patch)
treebc99310e466df9c5c9c28353ed71f9acc097ff74 /gr-blocks/lib
parent406bd0ab8add97083ec03c724d857001130c88a0 (diff)
blocks: use VOLK popcnt implementations for count_bits
* Changed count_bits64 input parameter type to uint64_t Signed-off-by: Nicholas Corgan <n.corgan@gmail.com>
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/count_bits.cc22
1 files changed, 10 insertions, 12 deletions
diff --git a/gr-blocks/lib/count_bits.cc b/gr-blocks/lib/count_bits.cc
index b0953428d4..f60f71ad05 100644
--- a/gr-blocks/lib/count_bits.cc
+++ b/gr-blocks/lib/count_bits.cc
@@ -10,11 +10,7 @@
#include <gnuradio/blocks/count_bits.h>
-/*
- * these are slow and obvious. If you need something faster, fix these
- *
- * Can probably replace with VOLK's popcount
- */
+#include <volk/volk.h>
namespace gr {
namespace blocks {
@@ -45,16 +41,18 @@ unsigned int count_bits16(unsigned int x)
unsigned int count_bits32(unsigned int x)
{
- unsigned res = (x & 0x55555555) + ((x >> 1) & 0x55555555);
- res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
- res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
- res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
- return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
+ unsigned res = 0;
+ volk_32u_popcnt(&res, x);
+
+ return res;
}
-unsigned int count_bits64(unsigned long long x)
+unsigned int count_bits64(uint64_t x)
{
- return count_bits32((x >> 32) & 0xffffffff) + count_bits32(x & 0xffffffff);
+ uint64_t res_as_u64 = 0;
+ volk_64u_popcnt(&res_as_u64, x);
+
+ return static_cast<unsigned int>(res_as_u64);
}
} /* namespace blocks */