Do not include count_bits() all over the place

This commit is contained in:
Lassi Kortela 2019-08-09 21:41:37 +03:00
parent c84c71adcc
commit 36e2057616
2 changed files with 23 additions and 23 deletions

View File

@ -13,6 +13,29 @@
// greater than this # of words we use malloc instead of alloca
#define MALLOC_CUTOFF 2000
#ifdef __INTEL_COMPILER
#define count_bits(b) _popcnt32(b)
#else
static uint32_t count_bits(uint32_t b)
{
b = b - ((b >> 1) & 0x55555555);
b = ((b >> 2) & 0x33333333) + (b & 0x33333333);
b = ((b >> 4) + b) & 0x0f0f0f0f;
b += (b >> 8);
b += (b >> 16);
return b & 0x3f;
// here is the non-optimized version, for clarity:
/*
b = ((b>> 1)&0x55555555) + (b&0x55555555);
b = ((b>> 2)&0x33333333) + (b&0x33333333);
b = ((b>> 4)&0x0f0f0f0f) + (b&0x0f0f0f0f);
b = ((b>> 8)&0x00ff00ff) + (b&0x00ff00ff);
b = ((b>>16)&0x0000ffff) + (b&0x0000ffff);
return b & 0x3f;
*/
}
#endif
uint32_t bitreverse(uint32_t x)
{
uint32_t m;

View File

@ -3,29 +3,6 @@
#define himask(n) (~lomask(32 - n))
#define ONES32 ((uint32_t)0xffffffff)
#ifdef __INTEL_COMPILER
#define count_bits(b) _popcnt32(b)
#else
static uint32_t count_bits(uint32_t b)
{
b = b - ((b >> 1) & 0x55555555);
b = ((b >> 2) & 0x33333333) + (b & 0x33333333);
b = ((b >> 4) + b) & 0x0f0f0f0f;
b += (b >> 8);
b += (b >> 16);
return b & 0x3f;
// here is the non-optimized version, for clarity:
/*
b = ((b>> 1)&0x55555555) + (b&0x55555555);
b = ((b>> 2)&0x33333333) + (b&0x33333333);
b = ((b>> 4)&0x0f0f0f0f) + (b&0x0f0f0f0f);
b = ((b>> 8)&0x00ff00ff) + (b&0x00ff00ff);
b = ((b>>16)&0x0000ffff) + (b&0x0000ffff);
return b & 0x3f;
*/
}
#endif
uint32_t bitreverse(uint32_t x);
uint32_t *bitvector_new(uint64_t n, int initzero);