10#ifndef __WSUTIL_BITS_CTZ_H__
11#define __WSUTIL_BITS_CTZ_H__
20#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
25 return __builtin_ctzll(x);
31 return 63 - __builtin_clzll(x);
40 static const uint8_t table[32] = {
41 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
42 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
45 return table[((uint32_t)((x & -(int32_t)x) * 0x077CB531U)) >> 27];
51 uint32_t hi = x >> 32;
52 uint32_t lo = (uint32_t) x;
55 return 32 + __ws_ctz32(hi);
57 return __ws_ctz32(lo);
61__ws_ilog2_32(uint32_t x)
64 static const uint8_t table[32] = {
65 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
66 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
75 return table[((uint32_t)(x * 0x07C4ACDDU)) >> 27];
81 uint32_t hi = x >> 32;
82 uint32_t lo = (uint32_t) x;
85 return __ws_ilog2_32(lo);
87 return 32 + __ws_ilog2_32(hi);