Skip to content

Commit dfa50c3

Browse files
committed
nicefy mi_popcount
1 parent b10c0f8 commit dfa50c3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

include/mimalloc/bits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static inline size_t mi_popcount(size_t x) {
209209
return mi_builtinz(popcount)(x);
210210
#else
211211
#define MI_HAS_FAST_POPCOUNT 0
212-
return (x<=1 ? x : _mi_popcount_generic(x));
212+
return _mi_popcount_generic(x);
213213
#endif
214214
}
215215

src/libc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ static size_t mi_popcount_generic32(uint32_t x) {
383383
}
384384

385385
mi_decl_noinline size_t _mi_popcount_generic(size_t x) {
386+
if (x<=1) return x;
387+
if (~x==0) return MI_SIZE_BITS;
386388
return mi_popcount_generic32(x);
387389
}
388390

@@ -407,6 +409,8 @@ static size_t mi_popcount_generic64(uint64_t x) {
407409
}
408410

409411
mi_decl_noinline size_t _mi_popcount_generic(size_t x) {
412+
if (x<=1) return x;
413+
if (~x==0) return MI_SIZE_BITS;
410414
return mi_popcount_generic64(x);
411415
}
412416
#endif

0 commit comments

Comments
 (0)