12#define DC_MATH_IS_POWER_OF_2(x) ((x) != 0 && ((x) & ((x) - 1)) == 0)
17 #include <type_traits>
21template <
typename T>
constexpr unsigned msb_index(T x)
noexcept {
22 static_assert(std::is_unsigned_v<T>,
"DC_MATH_MSB_INDEX requires an unsigned integer type");
28 constexpr unsigned bits =
sizeof(T) * 8U;
29 return bits - 1U - std::countl_zero(x);
34 #define DC_MATH_MSB_INDEX(x) ::dc::math::msb_index(x)
38 #define DC_MATH_MSB_INDEX(x) \
41 uint8_t: (7u - __builtin_clz((uint32_t)((x)) << 24)), \
42 uint16_t: (15u - __builtin_clz((uint32_t)((x)) << 16)), \
43 uint32_t: (31u - __builtin_clz((uint32_t)(x))), \
44 uint64_t: (63u - __builtin_clzll((uint64_t)(x)))))
57#if SIZE_MAX > 0xFFFFFFFF
70 uintptr_t
const mask = (1U << exp) - 1;
71 return (((uintptr_t)ptr) & mask) == 0;
#define DC_MATH_IS_POWER_OF_2(x)
static DC_INLINE DC_CONST size_t dc_math_next_power_of_2(size_t x)
static bool DC_INLINE DC_CONST dc_math_is_aligned_pow2_exp(const void *ptr, unsigned exp)
static size_t DC_INLINE DC_CONST dc_math_modulus_power_of_2_capacity(size_t index, size_t capacity)
#define DC_ASSUME(expr,...)