diff options
author | bunnei <bunneidev@gmail.com> | 2022-01-21 03:06:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 03:06:11 +0100 |
commit | ef7c50b276611daf21b66cbd9e82e01e8663024f (patch) | |
tree | f8a1d0bde3bb1a5551fcd25a4443b2b48682c095 | |
parent | Merge pull request #7710 from german77/just-shake-it (diff) | |
parent | common: bit_util: Add IsPow2 helper function (diff) | |
download | yuzu-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.h | 6 |
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))); |