13 #ifndef TLX_MATH_CTZ_HEADER 14 #define TLX_MATH_CTZ_HEADER 29 template <
typename Integral>
31 if (x == 0)
return 8 *
sizeof(x);
33 while ((x & static_cast<Integral>(1)) == 0)
40 template <
typename Integral>
41 inline unsigned ctz(Integral x);
43 #if defined(__GNUC__) || defined(__clang__) 48 if (i == 0)
return 8 *
sizeof(i);
49 return static_cast<unsigned>(__builtin_ctz(i));
55 return ctz(static_cast<unsigned>(i));
61 if (i == 0)
return 8 *
sizeof(i);
62 return static_cast<unsigned>(__builtin_ctzl(i));
68 return ctz(static_cast<unsigned long>(i));
74 if (i == 0)
return 8 *
sizeof(i);
75 return static_cast<unsigned>(__builtin_ctzll(i));
81 return ctz(static_cast<unsigned long long>(i));
84 #elif defined(_MSC_VER) 87 template <
typename Integral>
89 unsigned long trailing_zeros = 0;
92 if (_BitScanForward64(&trailing_zeros, i))
93 return trailing_zeros;
101 if (_BitScanForward(&trailing_zeros, static_cast<unsigned>(i)))
102 return trailing_zeros;
104 return 8 *
sizeof(i);
152 #endif // !TLX_MATH_CTZ_HEADER
unsigned ctz< unsigned >(unsigned i)
ctz (count trailing zeros)
static unsigned ctz_template(Integral x)
ctz (count trailing zeros) - generic implementation
unsigned ctz< long long >(long long i)
ctz (count trailing zeros)
unsigned ctz< unsigned long >(unsigned long i)
ctz (count trailing zeros)
unsigned ctz< long >(long i)
ctz (count trailing zeros)
unsigned ctz< unsigned long long >(unsigned long long i)
ctz (count trailing zeros)
unsigned ctz< int >(int i)
ctz (count trailing zeros)