GNU Radio 3.4.2 C++ API
volk_64u_popcnt_a.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_volk_64u_popcnt_a_H
00002 #define INCLUDED_volk_64u_popcnt_a_H
00003 
00004 #include <stdio.h>
00005 #include <inttypes.h>
00006 
00007 
00008 #ifdef LV_HAVE_GENERIC
00009 
00010 
00011 static inline void volk_64u_popcnt_a_generic(uint64_t* ret, const uint64_t value) {
00012 
00013   const uint32_t* valueVector = (const uint32_t*)&value;
00014   
00015   // This is faster than a lookup table
00016   uint32_t retVal = valueVector[0];
00017 
00018   retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
00019   retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
00020   retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
00021   retVal = (retVal + (retVal >> 8));
00022   retVal = (retVal + (retVal >> 16)) & 0x0000003F;
00023   uint64_t retVal64  = retVal;
00024 
00025   retVal = valueVector[1];
00026   retVal = (retVal & 0x55555555) + (retVal >> 1 & 0x55555555);
00027   retVal = (retVal & 0x33333333) + (retVal >> 2 & 0x33333333);
00028   retVal = (retVal + (retVal >> 4)) & 0x0F0F0F0F;
00029   retVal = (retVal + (retVal >> 8));
00030   retVal = (retVal + (retVal >> 16)) & 0x0000003F;
00031   retVal64 += retVal;
00032 
00033   *ret = retVal64;
00034 
00035 }
00036 
00037 #endif /*LV_HAVE_GENERIC*/
00038 
00039 #if LV_HAVE_SSE4_2 && LV_HAVE_64
00040 
00041 #include <nmmintrin.h>
00042 
00043 static inline void volk_64u_popcnt_a_sse4_2(uint64_t* ret, const uint64_t value) {
00044   *ret = _mm_popcnt_u64(value);
00045 
00046 }
00047 
00048 #endif /*LV_HAVE_SSE4_2*/
00049 
00050 #endif /*INCLUDED_volk_64u_popcnt_a_H*/