diff options
Diffstat (limited to 'gr-blocks/lib/count_bits.cc')
-rw-r--r-- | gr-blocks/lib/count_bits.cc | 22 |
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 */ |