2026-09-27 15:50:47

Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
lizzie
2026-09-27 15:50:47 +00:00
parent 815325ccec
commit 3be0db1266
28 changed files with 364 additions and 512 deletions
+4 -18
View File
@@ -22,36 +22,22 @@ template <typename T>
return std::size_t(sizeof(T) * CHAR_BIT);
}
template<typename T>
requires std::is_integral_v<T>
[[nodiscard]] constexpr u32 MostSignificantBit(const T value) {
return u32(sizeof(T) * CHAR_BIT - 1 - std::countl_zero(value));
}
template<typename T>
requires std::is_integral_v<T>
[[nodiscard]] constexpr T Log2Floor(const T value) {
return T(MostSignificantBit<T>(value));
return std::bit_width(value) - 1;
}
template<typename T>
requires std::is_integral_v<T>
[[nodiscard]] constexpr T Log2Ceil(const T value) {
const T log2_f = Log2Floor<T>(value);
return T(log2_f + T((value ^ (T(1ULL) << log2_f)) != T(0ULL)));
}
template <typename T>
requires std::is_integral_v<T>
[[nodiscard]] T NextPow2(T value) {
return T(1ULL << (sizeof(T) * CHAR_BIT - std::countl_zero(value - 1U)));
return std::bit_width(value - 1);
}
template <size_t bit_index, typename T>
requires std::is_integral_v<T>
requires (std::is_integral_v<T> && bit_index < BitSize<T>())
[[nodiscard]] constexpr bool Bit(const T value) {
static_assert(bit_index < BitSize<T>(), "bit_index must be smaller than size of T");
return ((value >> bit_index) & T(1)) == T(1);
return (T(value >> bit_index) & T(1)) == T(1);
}
} // namespace Common