GNU Radio Manual and C++ API Reference  3.7.6.1
The Free & Open Software Radio Ecosystem
volk_64u_popcnt.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2014 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_volk_64u_popcnt_a_H
24 #define INCLUDED_volk_64u_popcnt_a_H
25 
26 #include <stdio.h>
27 #include <inttypes.h>
28 
29 
30 #ifdef LV_HAVE_GENERIC
31 
32 
33 static inline void volk_64u_popcnt_generic(uint64_t* ret, const uint64_t value) {
34 
35  //const uint32_t* valueVector = (const uint32_t*)&value;
36 
37  // This is faster than a lookup table
38  //uint32_t retVal = valueVector[0];
39  uint32_t retVal = (uint32_t)(value & 0x00000000FFFFFFFF);
40 
41  retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
42  retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
43  retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
44  retVal = (retVal + (retVal >> 8));
45  retVal = (retVal + (retVal >> 16)) & 0x0000003F;
46  uint64_t retVal64 = retVal;
47 
48  //retVal = valueVector[1];
49  retVal = (uint32_t)((value & 0xFFFFFFFF00000000) >> 31);
50  retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
51  retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
52  retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
53  retVal = (retVal + (retVal >> 8));
54  retVal = (retVal + (retVal >> 16)) & 0x0000003F;
55  retVal64 += retVal;
56 
57  *ret = retVal64;
58 
59 }
60 
61 #endif /*LV_HAVE_GENERIC*/
62 
63 #if LV_HAVE_SSE4_2 && LV_HAVE_64
64 
65 #include <nmmintrin.h>
66 
67 static inline void volk_64u_popcnt_a_sse4_2(uint64_t* ret, const uint64_t value) {
68  *ret = _mm_popcnt_u64(value);
69 
70 }
71 
72 #endif /*LV_HAVE_SSE4_2*/
73 
74 #if LV_HAVE_NEON
75 #include <arm_neon.h>
76 static inline void volk_64u_popcnt_neon(uint64_t* ret, const uint64_t value) {
77  uint8x8_t input_val, count8x8_val;
78  uint16x4_t count16x4_val;
79  uint32x2_t count32x2_val;
80  uint64x1_t count64x1_val;
81 
82  input_val = vld1_u8((unsigned char *) &value);
83  count8x8_val = vcnt_u8(input_val);
84  count16x4_val = vpaddl_u8(count8x8_val);
85  count32x2_val = vpaddl_u16(count16x4_val);
86  count64x1_val = vpaddl_u32(count32x2_val);
87  vst1_u64(ret, count64x1_val);
88 
89  //*ret = _mm_popcnt_u64(value);
90 
91 }
92 #endif /*LV_HAVE_NEON*/
93 
94 #endif /*INCLUDED_volk_64u_popcnt_a_H*/
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90