blob: f60f71ad05b44587c8901880b74dbf00bf35a0ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/* -*- c++ -*- */
/*
* Copyright 2003,2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/
#include <gnuradio/blocks/count_bits.h>
#include <volk/volk.h>
namespace gr {
namespace blocks {
unsigned int count_bits8(unsigned int x)
{
int count = 0;
for (int i = 0; i < 8; i++) {
if (x & (1 << i))
count++;
}
return count;
}
unsigned int count_bits16(unsigned int x)
{
int count = 0;
for (int i = 0; i < 16; i++) {
if (x & (1 << i))
count++;
}
return count;
}
unsigned int count_bits32(unsigned int x)
{
unsigned res = 0;
volk_32u_popcnt(&res, x);
return res;
}
unsigned int count_bits64(uint64_t x)
{
uint64_t res_as_u64 = 0;
volk_64u_popcnt(&res_as_u64, x);
return static_cast<unsigned int>(res_as_u64);
}
} /* namespace blocks */
} /* namespace gr */
|