diff options
author | bunnei <bunneidev@gmail.com> | 2021-01-21 23:45:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-21 23:45:40 +0100 |
commit | 2c4c7aea8adba63af3ebf89bd930b2cacae781a7 (patch) | |
tree | c19776abe75ffea96e49c6fd234945fe675143cb /src | |
parent | Merge pull request #5270 from german77/multiTouch (diff) | |
parent | bit_util: Unify implementations of MostSignificantBit32/MostSignificantBit64 (diff) | |
download | yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.tar yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.tar.gz yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.tar.bz2 yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.tar.lz yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.tar.xz yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.tar.zst yuzu-2c4c7aea8adba63af3ebf89bd930b2cacae781a7.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/common/bit_util.h | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/src/common/bit_util.h b/src/common/bit_util.h index 685e7fc9b..69fb4e5e4 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h @@ -7,10 +7,6 @@ #include <climits> #include <cstddef> -#ifdef _MSC_VER -#include <intrin.h> -#endif - #include "common/common_types.h" namespace Common { @@ -21,48 +17,30 @@ template <typename T> return sizeof(T) * CHAR_BIT; } -#ifdef _MSC_VER - -[[nodiscard]] inline u32 MostSignificantBit32(const u32 value) { - unsigned long result; - _BitScanReverse(&result, value); - return static_cast<u32>(result); -} - -[[nodiscard]] inline u32 MostSignificantBit64(const u64 value) { - unsigned long result; - _BitScanReverse64(&result, value); - return static_cast<u32>(result); -} - -#else - -[[nodiscard]] inline u32 MostSignificantBit32(const u32 value) { - return 31U - static_cast<u32>(__builtin_clz(value)); +[[nodiscard]] constexpr u32 MostSignificantBit32(const u32 value) { + return 31U - static_cast<u32>(std::countl_zero(value)); } -[[nodiscard]] inline u32 MostSignificantBit64(const u64 value) { - return 63U - static_cast<u32>(__builtin_clzll(value)); +[[nodiscard]] constexpr u32 MostSignificantBit64(const u64 value) { + return 63U - static_cast<u32>(std::countl_zero(value)); } -#endif - -[[nodiscard]] inline u32 Log2Floor32(const u32 value) { +[[nodiscard]] constexpr u32 Log2Floor32(const u32 value) { return MostSignificantBit32(value); } -[[nodiscard]] inline u32 Log2Ceil32(const u32 value) { - const u32 log2_f = Log2Floor32(value); - return log2_f + ((value ^ (1U << log2_f)) != 0U); +[[nodiscard]] constexpr u32 Log2Floor64(const u64 value) { + return MostSignificantBit64(value); } -[[nodiscard]] inline u32 Log2Floor64(const u64 value) { - return MostSignificantBit64(value); +[[nodiscard]] constexpr u32 Log2Ceil32(const u32 value) { + const u32 log2_f = Log2Floor32(value); + return log2_f + static_cast<u32>((value ^ (1U << log2_f)) != 0U); } -[[nodiscard]] inline u32 Log2Ceil64(const u64 value) { - const u64 log2_f = static_cast<u64>(Log2Floor64(value)); - return static_cast<u32>(log2_f + ((value ^ (1ULL << log2_f)) != 0ULL)); +[[nodiscard]] constexpr u32 Log2Ceil64(const u64 value) { + const u64 log2_f = Log2Floor64(value); + return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL)); } } // namespace Common |