summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/bit_util.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/common/bit_util.h b/src/common/bit_util.h
index eef8c1c5a..f50d3308a 100644
--- a/src/common/bit_util.h
+++ b/src/common/bit_util.h
@@ -46,6 +46,12 @@ template <typename T>
46} 46}
47 47
48template <typename T> 48template <typename T>
49requires std::is_unsigned_v<T>
50[[nodiscard]] constexpr bool IsPow2(T value) {
51 return std::has_single_bit(value);
52}
53
54template <typename T>
49requires std::is_integral_v<T> 55requires std::is_integral_v<T>
50[[nodiscard]] T NextPow2(T value) { 56[[nodiscard]] T NextPow2(T value) {
51 return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U))); 57 return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U)));