Skip to content
Permalink
Browse files
Merge pull request #9433 from shuffle2/constexpr-error
BitUtils: loosen clz to inline on msvc/arm64
  • Loading branch information
lioncash committed Jan 10, 2021
2 parents a613c2a + 65ecf1e commit 87debc6
Showing 1 changed file with 14 additions and 2 deletions.
@@ -362,7 +362,16 @@ T ExpandValue(T value, size_t left_shift_amount)
(T(-ExtractBit<0>(value)) >> (BitSize<T>() - 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

0 comments on commit 87debc6

Please sign in to comment.