|
ATLAS Offline Software
|
Go to the documentation of this file.
17 #ifndef CXXUTILS_BITSCAN_H
18 #define CXXUTILS_BITSCAN_H
23 #include <type_traits>
39 for (;(
x & 0x1) == 0; ++
n,
x >>= 1);
47 if (
x==0)
return sizeof(T)*8;
49 T msb =
static_cast<T
>(1) << (
sizeof(T)*8-1);
50 for (
n = 0; (
x & msb) == 0; ++
n,
x <<= 1);
73 #if HAVE_BITCOUNT_INTRINSICS
74 return (
x!=0 ? __builtin_ctz(
x) : 0);
81 #if HAVE_BITCOUNT_INTRINSICS
82 return (
x!=0 ? __builtin_ctzl(
x) : 0);
89 #if HAVE_BITCOUNT_INTRINSICS
90 return (
x!=0 ? __builtin_ctzll(
x) : 0);
103 #if HAVE_BITCOUNT_INTRINSICS
104 return (
x!=0 ? __builtin_clz(
x) :
sizeof(
x)*CHAR_BIT);
111 #if HAVE_BITCOUNT_INTRINSICS
112 return (
x!=0 ? __builtin_clzl(
x) :
sizeof(
x)*CHAR_BIT);
119 #if HAVE_BITCOUNT_INTRINSICS
120 return (
x!=0 ? __builtin_clzll(
x) :
sizeof(
x)*CHAR_BIT);
133 #if defined(__x86_64__) && HAVE_TARGET_CLONES
139 [[gnu::target_clones(
"popcnt,default")]]
142 #if HAVE_BITCOUNT_INTRINSICS
143 return __builtin_popcount(
x);
149 #if defined(__x86_64__) && HAVE_TARGET_CLONES
150 [[gnu::target_clones(
"popcnt,default")]]
153 #if HAVE_BITCOUNT_INTRINSICS
154 return __builtin_popcountl(
x);
161 #if defined(__x86_64__) && HAVE_TARGET_CLONES
162 [[gnu::target_clones(
"popcnt,default")]]
165 #if HAVE_BITCOUNT_INTRINSICS
166 return __builtin_popcountll(
x);
178 #endif // CXXUTILS_BITSCAN_H
Some additional feature test macros.
constexpr unsigned count_leading_zeros(unsigned x)
Count number of leading zeros.
constexpr unsigned ctz_portable(T x)
constexpr unsigned clz_portable(T x)
constexpr unsigned count_ones(unsigned x)
Count number of set bits.
constexpr unsigned count_trailing_zeros(unsigned x)
Count number of trailing zeros.
constexpr int maxSetBit(const T x)
Returns the position (counting from least-significant-bit=0) of the most significant set bit.
constexpr unsigned popcount_portable(T x)