GNU Radio Manual and C++ API Reference  3.7.6.1
The Free & Open Software Radio Ecosystem
volk_32u_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_32u_POPCNT_A16_H
24 #define INCLUDED_VOLK_32u_POPCNT_A16_H
25 
26 #include <stdio.h>
27 #include <inttypes.h>
28 
29 
30 #ifdef LV_HAVE_GENERIC
31 
32 static inline void volk_32u_popcnt_generic(uint32_t* ret, const uint32_t value) {
33 
34  // This is faster than a lookup table
35  uint32_t retVal = value;
36 
37  retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
38  retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
39  retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
40  retVal = (retVal + (retVal >> 8));
41  retVal = (retVal + (retVal >> 16)) & 0x0000003F;
42 
43  *ret = retVal;
44 }
45 
46 #endif /*LV_HAVE_GENERIC*/
47 
48 #ifdef LV_HAVE_SSE4_2
49 
50 #include <nmmintrin.h>
51 
52 static inline void volk_32u_popcnt_a_sse4_2(uint32_t* ret, const uint32_t value) {
53  *ret = _mm_popcnt_u32(value);
54 }
55 
56 #endif /*LV_HAVE_SSE4_2*/
57 
58 #endif /*INCLUDED_VOLK_32u_POPCNT_A16_H*/
unsigned int uint32_t
Definition: stdint.h:80