15#ifdef VECMEM_HAVE_LZCNT_U64
28 return ((x & (x - 1)) ==
static_cast<std::size_t
>(0));
36inline std::size_t
clzl(std::size_t i) {
38#if defined(VECMEM_HAVE_LZCNT_U64)
39 return static_cast<std::size_t
>(_lzcnt_u64(i));
40#elif defined(VECMEM_HAVE_BUILTIN_CLZL)
41 return static_cast<std::size_t
>(__builtin_clzl(i));
45 !((i << b) & (static_cast<std::size_t>(1UL)
46 << (std::numeric_limits<std::size_t>::digits - 1UL)));
58inline std::size_t
log2(std::size_t x) {
60 static constexpr std::size_t num_bits = CHAR_BIT *
sizeof(std::size_t);
61 static constexpr std::size_t num_bits_minus_one = num_bits - 1;
62 return num_bits_minus_one -
clzl(x);
70inline std::size_t
log2_ri(std::size_t x) {
73 std::size_t result =
log2(x);
89 static constexpr std::size_t SIZE_T_BITS = CHAR_BIT *
sizeof(std::size_t);
90 assert((
static_cast<std::size_t
>(1UL) << (SIZE_T_BITS - 1)) >= size);
91 for (std::size_t i = 0; i < SIZE_T_BITS; ++i) {
92 if ((
static_cast<std::size_t
>(1UL) << i) >= size) {
Namespace for types that should not be used directly by clients.
Definition array.hpp:23
std::size_t log2_ri(std::size_t x)
Compute the base-2 logarithm of a number, rounding up to the nearest log.
Definition integer_math.hpp:70
std::size_t round_up(std::size_t size)
Rounds a size up to the nearest power of two, and returns the power (not the size itself).
Definition integer_math.hpp:88
std::size_t clzl(std::size_t i)
Count the leading zeroes in a number.
Definition integer_math.hpp:36
bool is_power_of_2(std::size_t x)
Check if a number is a power of 2.
Definition integer_math.hpp:26
std::size_t log2(std::size_t x)
Compute the base-2 logarithm of a number.
Definition integer_math.hpp:58