11 #ifndef TLX_MATH_INTEGER_LOG2_HEADER 12 #define TLX_MATH_INTEGER_LOG2_HEADER 23 template <
typename IntegerType>
26 while (i >= 65536) i >>= 16, p += 16;
27 while (i >= 256) i >>= 8, p += 8;
35 #if defined(__GNUC__) || defined(__clang__) 40 return 8 *
sizeof(int) - 1 - __builtin_clz(i);
46 return 8 *
sizeof(unsigned) - 1 - __builtin_clz(i);
52 return 8 *
sizeof(long) - 1 - __builtin_clzl(i);
58 return 8 *
sizeof(
unsigned long) - 1 - __builtin_clzl(i);
64 return 8 *
sizeof(
long long) - 1 - __builtin_clzll(i);
70 return 8 *
sizeof(
unsigned long long) - 1 - __builtin_clzll(i);
112 if (i <= 1)
return 0;
118 if (i <= 1)
return 0;
124 if (i <= 1)
return 0;
130 if (i <= 1)
return 0;
136 if (i <= 1)
return 0;
142 if (i <= 1)
return 0;
150 #endif // !TLX_MATH_INTEGER_LOG2_HEADER static unsigned integer_log2_floor_template(IntegerType i)
calculate the log2 floor of an integer type
static unsigned integer_log2_floor(int i)
calculate the log2 floor of an integer type
static unsigned integer_log2_ceil(int i)
calculate the log2 floor of an integer type