X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2Flibbp.git;a=blobdiff_plain;f=bp-utils.h;h=2397d6f662f0def0ef58a9422b18dda49684419f;hp=b54868876a27dd14637a586b1ea2e7dcd5fff7e2;hb=HEAD;hpb=45ff7a2260f890f6ef6a7b56f654ffa1a057a7e7 diff --git a/bp-utils.h b/bp-utils.h index b548688..2397d6f 100644 --- a/bp-utils.h +++ b/bp-utils.h @@ -18,26 +18,44 @@ extern "C" { #define RRR (1< - +#ifdef __GNUC__ +#define UNUSED __attribute__((unused)) +#else +#define UNUSED +#endif #ifdef HAS_NATIVE_POPCOUNT -static inline unsigned int popcount(unsigned int n){ - asm ("popcnt %1, %0" : "=r" (n) : "0" (n)); - return n; +static inline UNUSED unsigned int popcount(unsigned int n){ + return __builtin_popcount(n); } -static inline unsigned int popcount8(unsigned int n) { +static inline UNUSED unsigned int popcount8(unsigned int n) { return popcount(n & 0xff); } #else +#ifdef HAS_POPCOUNT_TABLE + +extern unsigned char popCount[256]; + +static UNUSED unsigned int popcount8(unsigned int x) +{ + return (unsigned int) popCount[x & 0xff]; +} + +static UNUSED unsigned int popcount(unsigned int x) +{ + return popcount8(x) + + popcount8((x >> 8)) + + popcount8((x >> 16)) + + popcount8((x >> 24)); +} + -static unsigned int popcount8(unsigned int x) +#else +static UNUSED unsigned int popcount8(unsigned int x) { unsigned int r; r = x; @@ -47,7 +65,7 @@ static unsigned int popcount8(unsigned int x) return r; } -static inline unsigned int popcount(unsigned int x) +static inline UNUSED unsigned int popcount(unsigned int x) { unsigned int m1 = 0x55555555; unsigned int m2 = 0xc30c30c3; @@ -58,6 +76,7 @@ static inline unsigned int popcount(unsigned int x) } #endif +#endif void * bp_malloc(size_t); @@ -68,7 +87,7 @@ void * bp_malloc(size_t); void bp_free(void *); -size_t bp_alloc_stats(void); +size_t bp_get_alloc_stats(void); void bp_reset_alloc_states(void);