From 36e20576167e5038dafa41e52678d78f6afe82f5 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Fri, 9 Aug 2019 21:41:37 +0300 Subject: [PATCH] Do not include count_bits() all over the place --- c/bitvector-ops.c | 23 +++++++++++++++++++++++ c/bitvector.h | 23 ----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/c/bitvector-ops.c b/c/bitvector-ops.c index b59f20a..408308f 100644 --- a/c/bitvector-ops.c +++ b/c/bitvector-ops.c @@ -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; diff --git a/c/bitvector.h b/c/bitvector.h index 7e89b31..12daa30 100644 --- a/c/bitvector.h +++ b/c/bitvector.h @@ -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);