33#if defined(_MSC_VER) && !defined(__clang__)
61static inline bool is_power_of_two(
size_t n) {
62 return n && !(n & (n - 1));
84static inline size_t next_power_of_two(
size_t n) {
93 if (
sizeof(
size_t) > 4) {
126static inline int find_first_set_bit(
uint64_t mask) {
127#if defined(__GNUC__) || defined(__clang__)
131 return __builtin_ctzll(mask);
132#elif defined(_MSC_VER) && defined(_M_X64)
135 if (_BitScanForward64(&index, mask)) {
139#elif defined(_MSC_VER)
142 if (_BitScanForward(&index, (
unsigned long)mask)) {
145 if (_BitScanForward(&index, (
unsigned long)(mask >> 32))) {
146 return 32 + (int)index;
155 static const int debruijn_table[64] = {0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
156 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
157 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
158 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
161 return debruijn_table[((mask & -mask) * 0x022fdd63cc95386dULL) >> 58];
187static inline int count_set_bits(
uint64_t x) {
188#if defined(__GNUC__) || defined(__clang__)
189 return __builtin_popcountll(x);
190#elif defined(_MSC_VER) && defined(_M_X64)
191 return (
int)__popcnt64(x);
unsigned long long uint64_t