summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-01-21 03:06:11 +0100
committerGitHub <noreply@github.com>2022-01-21 03:06:11 +0100
commitef7c50b276611daf21b66cbd9e82e01e8663024f (patch)
treef8a1d0bde3bb1a5551fcd25a4443b2b48682c095
parentMerge pull request #7710 from german77/just-shake-it (diff)
parentcommon: bit_util: Add IsPow2 helper function (diff)
downloadyuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.tar
yuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.tar.gz
yuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.tar.bz2
yuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.tar.lz
yuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.tar.xz
yuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.tar.zst
yuzu-ef7c50b276611daf21b66cbd9e82e01e8663024f.zip
-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>
}
template <typename T>
+requires std::is_unsigned_v<T>
+[[nodiscard]] constexpr bool IsPow2(T value) {
+ return std::has_single_bit(value);
+}
+
+template <typename T>
requires std::is_integral_v<T>
[[nodiscard]] T NextPow2(T value) {
return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U)));