GNU Radio C++ API
volk_64u_popcnt_a.h
Go to the documentation of this file.
1 #ifndef INCLUDED_volk_64u_popcnt_a_H
2 #define INCLUDED_volk_64u_popcnt_a_H
3 
4 #include <stdio.h>
5 #include <inttypes.h>
6 
7 
8 #ifdef LV_HAVE_GENERIC
9 
10 
11 static inline void volk_64u_popcnt_a_generic(uint64_t* ret, const uint64_t value) {
12 
13  const uint32_t* valueVector = (const uint32_t*)&value;
14 
15  // This is faster than a lookup table
16  uint32_t retVal = valueVector[0];
17 
18  retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
19  retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
20  retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
21  retVal = (retVal + (retVal >> 8));
22  retVal = (retVal + (retVal >> 16)) & 0x0000003F;
23  uint64_t retVal64 = retVal;
24 
25  retVal = valueVector[1];
26  retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
27  retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
28  retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
29  retVal = (retVal + (retVal >> 8));
30  retVal = (retVal + (retVal >> 16)) & 0x0000003F;
31  retVal64 += retVal;
32 
33  *ret = retVal64;
34 
35 }
36 
37 #endif /*LV_HAVE_GENERIC*/
38 
39 #if LV_HAVE_SSE4_2 && LV_HAVE_64
40 
41 #include <nmmintrin.h>
42 
43 static inline void volk_64u_popcnt_a_sse4_2(uint64_t* ret, const uint64_t value) {
44  *ret = _mm_popcnt_u64(value);
45 
46 }
47 
48 #endif /*LV_HAVE_SSE4_2*/
49 
50 #endif /*INCLUDED_volk_64u_popcnt_a_H*/