From c163072197b56e76b656cc472bbe6df650cf11ba Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 28 Sep 2011 13:18:09 -0700 Subject: mesa: Create _mesa_bitcount_64() to replace i965's brw_count_bits() The i965 driver already had a function to count bits in a 64-bit uint (brw_count_bits()), but it was buggy (it only counted the bottom 32 bits) and it was clumsy (it had a strange and broken fallback for non-GCC-like compilers, which fortunately was never used). Since Mesa already has a _mesa_bitcount() function, it seems better to just create a _mesa_bitcount_64() function rather than special-case this in the i965 driver. This patch creates the new _mesa_bitcount_64() function and rewrites all of the old brw_count_bits() calls to refer to it. Reviewed-by: Ian Romanick Reviewed-by: Eric Anholt --- src/mesa/main/imports.c | 13 +++++++++++++ src/mesa/main/imports.h | 3 +++ 2 files changed, 16 insertions(+) (limited to 'src/mesa/main') diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 8f097195922..345a1c53e2f 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -527,6 +527,19 @@ _mesa_bitcount(unsigned int n) } return bits; } + +/** + * Return number of bits set in given 64-bit uint. + */ +unsigned int +_mesa_bitcount_64(uint64_t n) +{ + unsigned int bits; + for (bits = 0; n > 0; n = n >> 1) { + bits += (n & 1); + } + return bits; +} #endif diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h index 5fb5581efce..20fa148fe59 100644 --- a/src/mesa/main/imports.h +++ b/src/mesa/main/imports.h @@ -578,9 +578,12 @@ _mesa_init_sqrt_table(void); #if ((_GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4) #define _mesa_bitcount(i) __builtin_popcount(i) +#define _mesa_bitcount_64(i) __builtin_popcountll(i) #else extern unsigned int _mesa_bitcount(unsigned int n); +extern unsigned int +_mesa_bitcount_64(uint64_t n); #endif #else -- cgit v1.2.3