diff --git a/include/mimalloc/bits.h b/include/mimalloc/bits.h index e3038d11..1d4063bb 100644 --- a/include/mimalloc/bits.h +++ b/include/mimalloc/bits.h @@ -209,7 +209,7 @@ static inline size_t mi_popcount(size_t x) { return mi_builtinz(popcount)(x); #else #define MI_HAS_FAST_POPCOUNT 0 - return (x<=1 ? x : _mi_popcount_generic(x)); + return _mi_popcount_generic(x); #endif } diff --git a/src/libc.c b/src/libc.c index a54eec5b..b40d1204 100644 --- a/src/libc.c +++ b/src/libc.c @@ -383,6 +383,8 @@ static size_t mi_popcount_generic32(uint32_t x) { } mi_decl_noinline size_t _mi_popcount_generic(size_t x) { + if (x<=1) return x; + if (~x==0) return MI_SIZE_BITS; return mi_popcount_generic32(x); } @@ -407,6 +409,8 @@ static size_t mi_popcount_generic64(uint64_t x) { } mi_decl_noinline size_t _mi_popcount_generic(size_t x) { + if (x<=1) return x; + if (~x==0) return MI_SIZE_BITS; return mi_popcount_generic64(x); } #endif