mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
common: bit_util: Add IsPow2 helper function
Makes use of std::has_single_bit() to check whether the value is a power of 2.
This commit is contained in:
parent
b3308830b2
commit
d92b5fc435
1 changed files with 6 additions and 0 deletions
|
@ -45,6 +45,12 @@ template <typename T>
|
||||||
return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL));
|
return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
requires std::is_unsigned_v<T>
|
||||||
|
[[nodiscard]] constexpr bool IsPow2(T value) {
|
||||||
|
return std::has_single_bit(value);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires std::is_integral_v<T>
|
requires std::is_integral_v<T>
|
||||||
[[nodiscard]] T NextPow2(T value) {
|
[[nodiscard]] T NextPow2(T value) {
|
||||||
|
|
Loading…
Reference in a new issue