13 #ifndef TLX_MATH_CLZ_HEADER 14 #define TLX_MATH_CLZ_HEADER 29 template <
typename Integral>
31 if (x == 0)
return 8 *
sizeof(
x);
33 while ((x & (static_cast<Integral>(1) << (8 *
sizeof(x) - 1))) == 0)
40 template <
typename Integral>
41 inline unsigned clz(Integral
x);
43 #if defined(__GNUC__) || defined(__clang__) 48 if (i == 0)
return 8 *
sizeof(i);
49 return static_cast<unsigned>(__builtin_clz(i));
55 return clz(static_cast<unsigned>(i));
61 if (i == 0)
return 8 *
sizeof(i);
62 return static_cast<unsigned>(__builtin_clzl(i));
68 return clz(static_cast<unsigned long>(i));
74 if (i == 0)
return 8 *
sizeof(i);
75 return static_cast<unsigned>(__builtin_clzll(i));
81 return clz(static_cast<unsigned long long>(i));
84 #elif defined(_MSC_VER) 87 template <
typename Integral>
89 unsigned long leading_zeros = 0;
92 if (_BitScanReverse64(&leading_zeros, i))
93 return 63 - leading_zeros;
101 if (_BitScanReverse(&leading_zeros, static_cast<unsigned>(i)))
102 return 31 - leading_zeros;
104 return 8 *
sizeof(i);
152 #endif // !TLX_MATH_CLZ_HEADER
unsigned clz< unsigned long >(unsigned long i)
clz (count leading zeros)
unsigned clz< unsigned >(unsigned i)
clz (count leading zeros)
unsigned clz< long long >(long long i)
clz (count leading zeros)
static unsigned clz_template(Integral x)
clz (count leading zeros) - generic implementation
unsigned clz< int >(int i)
clz (count leading zeros)
unsigned clz< unsigned long long >(unsigned long long i)
clz (count leading zeros)
unsigned clz< long >(long i)
clz (count leading zeros)