Browse Source

fix C implementation of a_clz_32

this broke mallocng size_to_class on archs without a native
implementation of a_clz_32. the incorrect logic seems to have been
something i derived from a related but distinct log2-type operation.
with the change made here, it passes an exhaustive test.

as this function is new and presently only used by mallocng, no other
functionality was affected.
master
Rich Felker 6 years ago
parent
commit
0a005f499c
  1. 2
      src/internal/atomic.h

2
src/internal/atomic.h

@ -319,7 +319,7 @@ static inline int a_clz_64(uint64_t x)
#define a_clz_32 a_clz_32 #define a_clz_32 a_clz_32
static inline int a_clz_32(uint32_t x) static inline int a_clz_32(uint32_t x)
{ {
x--; x >>= 1;
x |= x >> 1; x |= x >> 1;
x |= x >> 2; x |= x >> 2;
x |= x >> 4; x |= x >> 4;

Loading…
Cancel
Save