11 #ifndef TLX_MATH_INTEGER_LOG2_HEADER 12 #define TLX_MATH_INTEGER_LOG2_HEADER 25 template <
typename IntegerType>
28 while (i >= 65536) i >>= 16, p += 16;
29 while (i >= 256) i >>= 8, p += 8;
37 #if defined(__GNUC__) || defined(__clang__) 42 return 8 *
sizeof(int) - 1 - __builtin_clz(i);
48 return 8 *
sizeof(unsigned) - 1 - __builtin_clz(i);
54 return 8 *
sizeof(long) - 1 - __builtin_clzl(i);
60 return 8 *
sizeof(
unsigned long) - 1 - __builtin_clzl(i);
66 return 8 *
sizeof(
long long) - 1 - __builtin_clzll(i);
72 return 8 *
sizeof(
unsigned long long) - 1 - __builtin_clzll(i);
114 if (i <= 1)
return 0;
120 if (i <= 1)
return 0;
126 if (i <= 1)
return 0;
132 if (i <= 1)
return 0;
138 if (i <= 1)
return 0;
144 if (i <= 1)
return 0;
152 #endif // !TLX_MATH_INTEGER_LOG2_HEADER static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil(int i)
calculate the log2 floor of an integer type
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor(int i)
calculate the log2 floor of an integer type
#define TLX_ADVANCED_CONSTEXPR
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor_template(IntegerType i)
calculate the log2 floor of an integer type