MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_clz32

Function mi_clz32

3rd/mimalloc-2.0.9/include/mimalloc-internal.h:999–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

997 return debruijn[((x & -(int32_t)x) * 0x077CB531UL) >> 27];
998}
999static inline size_t mi_clz32(uint32_t x) {
1000 // de Bruijn multiplication, see <http://supertech.csail.mit.edu/papers/debruijn.pdf>
1001 static const uint8_t debruijn[32] = {
1002 31, 22, 30, 21, 18, 10, 29, 2, 20, 17, 15, 13, 9, 6, 28, 1,
1003 23, 19, 11, 3, 16, 14, 7, 24, 12, 4, 8, 25, 5, 26, 27, 0
1004 };
1005 if (x==0) return 32;
1006 x |= x >> 1;
1007 x |= x >> 2;
1008 x |= x >> 4;
1009 x |= x >> 8;
1010 x |= x >> 16;
1011 return debruijn[(uint32_t)(x * 0x07C4ACDDUL) >> 27];
1012}
1013
1014static inline size_t mi_clz(uintptr_t x) {
1015 if (x==0) return MI_INTPTR_BITS;

Callers 1

mi_clzFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected