Vector Optimized Library of Kernels  2.0
Architecture-tuned implementations of math kernels
volk_32u_popcnt.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012, 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 
56 #ifndef INCLUDED_VOLK_32u_POPCNT_A16_H
57 #define INCLUDED_VOLK_32u_POPCNT_A16_H
58 
59 #include <stdio.h>
60 #include <inttypes.h>
61 
62 #ifdef LV_HAVE_GENERIC
63 
64 static inline void
65 volk_32u_popcnt_generic(uint32_t* ret, const uint32_t value)
66 {
67  // This is faster than a lookup table
68  uint32_t retVal = value;
69 
70  retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
71  retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
72  retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
73  retVal = (retVal + (retVal >> 8));
74  retVal = (retVal + (retVal >> 16)) & 0x0000003F;
75 
76  *ret = retVal;
77 }
78 
79 #endif /*LV_HAVE_GENERIC*/
80 
81 
82 #ifdef LV_HAVE_SSE4_2
83 
84 #include <nmmintrin.h>
85 
86 static inline void
87 volk_32u_popcnt_a_sse4_2(uint32_t* ret, const uint32_t value)
88 {
89  *ret = _mm_popcnt_u32(value);
90 }
91 
92 #endif /*LV_HAVE_SSE4_2*/
93 
94 #endif /*INCLUDED_VOLK_32u_POPCNT_A16_H*/
static void volk_32u_popcnt_generic(uint32_t *ret, const uint32_t value)
Definition: volk_32u_popcnt.h:65
static void volk_32u_popcnt_a_sse4_2(uint32_t *ret, const uint32_t value)
Definition: volk_32u_popcnt.h:87