From 65ecf1e43e8d2718a5bb9bb46ae93c581f586341 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sat, 9 Jan 2021 23:44:00 -0800 Subject: [PATCH] BitUtils: loosen clz to inline on msvc/arm64 --- Source/Core/Common/BitUtils.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/BitUtils.h b/Source/Core/Common/BitUtils.h index bff643855d..1ba34be10f 100644 --- a/Source/Core/Common/BitUtils.h +++ b/Source/Core/Common/BitUtils.h @@ -362,7 +362,16 @@ T ExpandValue(T value, size_t left_shift_amount) (T(-ExtractBit<0>(value)) >> (BitSize() - left_shift_amount)); } -constexpr int CountLeadingZeros(uint64_t value) +// On some compiler / arch combinations, the compiler does not see instrinsics as constexpr, so mark +// the function as inline instead. +#if defined(_MSC_VER) && defined(_M_ARM_64) +#define CONSTEXPR_FROM_INTRINSIC inline +#else +#define CONSTEXPR_FROM_INTRINSIC constexpr +#endif + +CONSTEXPR_FROM_INTRINSIC +int CountLeadingZeros(uint64_t value) { #if defined(__GNUC__) return value ? __builtin_clzll(value) : 64; @@ -382,7 +391,8 @@ constexpr int CountLeadingZeros(uint64_t value) #endif } -constexpr int CountLeadingZeros(uint32_t value) +CONSTEXPR_FROM_INTRINSIC +int CountLeadingZeros(uint32_t value) { #if defined(__GNUC__) return value ? __builtin_clz(value) : 32; @@ -402,4 +412,6 @@ constexpr int CountLeadingZeros(uint32_t value) #endif } +#undef CONSTEXPR_FROM_INTRINSIC + } // namespace Common