35 template<
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
37 return (v & (v - 1)) == 0;
48 template<
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
50 return v && !(v & (v - 1));
63 template<
class T, std::enable_if_t<std::is_
integral_v<T> || std::is_
signed_v<T>,
int> = 0>
76 template<
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
91 template<
class T, std::enable_if_t<std::is_
integral_v<T> || (!std::is_
signed_v<T>),
int> = 0>
126 return (
len + group_size - 1) / group_size;
137 template<
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
139 return (value >>
bitnum) & 1;
148 template<
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
150 return T(std::make_unsigned_t<T>(1) << (
sizeof(T) * 8 - 1));
160 template<
class T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
173 template<i32 power,
class T>
176 if constexpr (
power == 0) {
178 }
else if constexpr (
power % 2 == 0) {
181 }
else if constexpr (
power % 2 == 1) {
183 return tmp * tmp *
a;
188 inline constexpr bool is_flag_on(
u32 val) {
std::uint32_t u32
32 bit unsigned integer
namespace for basic c++ utilities
constexpr u32 group_count(u32 len, u32 group_size)
Calculates the number of groups based on the length and group size.
T select_bit(T value, T bitnum)
Selects and returns the bit at a specific position in the given value.
constexpr bool is_pow_of_two(T v) noexcept
determine if v is a power of two and check if v==0 Source : https://graphics.stanford....
constexpr T pow_constexpr(T a) noexcept
Calculates the power of a number at compile time.
constexpr bool sign_differ(T a, T b) noexcept
check if the sign of the two integers differs Source : https://graphics.stanford.edu/~seander/bithack...
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
constexpr T most_sig_bit_mask() noexcept
Generates a mask with only the most significant bit set.
constexpr T roundup_pow2(T v) noexcept
round up to the next power of two Source : https://graphics.stanford.edu/~seander/bithacks....
void xor_swap(T &a, T &b)
swap two values using xor Source : https://graphics.stanford.edu/~seander/bithacks....
constexpr bool is_pow_of_two_fast(T v) noexcept
determine if v is a power of two Warning : this function return true if v == 0 Source : https://graph...
constexpr bool is_most_sig_bit_set(const T x) noexcept
Checks if the most significant bit is set in the given value.