21#if __cplusplus >= 202002L
29#if defined(__cpp_lib_int_pow2) && __cpp_lib_int_pow2 >= 202002L
32constexpr size_t countl_zero(
size_t x)
noexcept {
33 size_t size_digits = std::numeric_limits<size_t>::digits;
35 if (
sizeof(x) <=
sizeof(
unsigned int))
36 return __builtin_clz(
static_cast<unsigned int>(x)) -
37 (std::numeric_limits<unsigned int>::digits - size_digits);
39 if (
sizeof(x) <=
sizeof(
unsigned long))
40 return __builtin_clzl(
static_cast<unsigned long>(x)) -
41 (std::numeric_limits<unsigned long>::digits - size_digits);
43 static_assert(
sizeof(x) <=
sizeof(
unsigned long long));
44 return __builtin_clzll(
static_cast<unsigned long long>(x)) -
45 (std::numeric_limits<unsigned long long>::digits - size_digits);
48constexpr size_t bit_width(
size_t x)
noexcept {
49 return std::numeric_limits<size_t>::digits - countl_zero(x);
52constexpr size_t bit_ceil(
size_t x)
noexcept {
55 return size_t{1} << bit_width(
size_t{x - 1});
std::atomic< NaturallyAligned< T > > AlignedAtomic
Definition: alignment.h:105
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27
Definition: alignment.h:74