19 return (
int)num_bits_on[x];
27 #if defined(__GNUC__) && defined(__POPCNT__)
28 return __builtin_popcount(x);
30 return (
int)num_bits_on[x & 0xffff] + (int)num_bits_on[(x >> 16) & 0xffff];
39 #if defined(__GNUC__) && defined(__POPCNT__)
40 return __builtin_popcountl(x);
53 #if defined(__GNUC__) && defined(__POPCNT__)
54 return __builtin_popcountll(x);
95 #if defined(_LP64) || defined(__LP64__)
104 INLINE
unsigned long long
118 INLINE
unsigned short
150 #if defined(_LP64) || defined(__LP64__)
159 INLINE
unsigned long long
176 #if defined(_MSC_VER)
177 unsigned long result;
178 return (_BitScanForward(&result, (
unsigned long) x) == 0) ? -1 : result;
179 #elif defined(__GNUC__)
180 return __builtin_ffs((
int) x) - 1;
186 unsigned short w = (x & (~x + 1));
187 return (
int)num_bits_on[w - 1];
197 #if defined(_MSC_VER)
198 unsigned long result;
199 return (_BitScanForward(&result, (
unsigned long) x) == 0) ? -1 : result;
200 #elif defined(__GNUC__)
201 return __builtin_ffs((
int) x) - 1;
207 unsigned int w = (x & (~x + 1));
218 #if defined(_MSC_VER) && defined(_M_X64)
219 unsigned long result;
220 return (_BitScanForward(&result, x) == 0) ? -1 : result;
221 #elif defined(__GNUC__)
222 return __builtin_ffsl((
long) x) - 1;
228 unsigned long w = (x & (~x + 1));
239 #if defined(_MSC_VER) && defined(_M_X64)
240 unsigned long result;
241 return (_BitScanForward64(&result, (
unsigned __int64) x) == 0) ? -1 : result;
242 #elif defined(__GNUC__)
243 return __builtin_ffsll((
long long) x) - 1;
249 unsigned long long w = (x & (~x + 1));
260 #if defined(_MSC_VER)
261 unsigned long result;
262 return (_BitScanReverse(&result, (
unsigned long) x) == 0) ? -1 : result;
263 #elif defined(__GNUC__)
264 return (x == 0) ? -1 : 31 - __builtin_clz((
unsigned int) x);
277 #if defined(_MSC_VER)
278 unsigned long result;
279 return (_BitScanReverse(&result, (
unsigned long) x) == 0) ? -1 : result;
280 #elif defined(__GNUC__)
281 return (x == 0) ? -1 : 31 - __builtin_clz(x);
294 #if defined(_MSC_VER) && defined(_M_X64)
295 unsigned long result;
296 return (_BitScanReverse(&result, (
unsigned long) x) == 0) ? -1 : result;
297 #elif defined(__GNUC__)
298 return (x == 0) ? -1 : 63 - __builtin_clzl(x);
311 #if defined(_MSC_VER) && defined(_M_X64)
312 unsigned long result;
313 return (_BitScanReverse64(&result, (
unsigned __int64) x) == 0) ? -1 : result;
314 #elif defined(__GNUC__)
315 return (x == 0) ? -1 : 63 - __builtin_clzll(x);
int get_highest_on_bit(unsigned short x)
Returns the index of the highest 1 bit in the word.
unsigned short flood_bits_down(unsigned short x)
Returns a value such that every bit at or below the highest bit in x is 1.
unsigned short flood_bits_up(unsigned short x)
Returns a value such that every bit at or above the highest bit in x is 1.
int count_bits_in_word(unsigned short x)
Returns the number of 1 bits in the indicated word.
int get_lowest_on_bit(unsigned short x)
Returns the index of the lowest 1 bit in the word.
int get_next_higher_bit(unsigned short x)
Returns the smallest power of 2 greater than x.