Merge pull request #9422 from MerryMage/__builtin_clz

BitUtils: __builtin_clz is undefined when value == 0
This commit is contained in:
JosJuice 2021-01-03 18:53:25 +01:00 committed by GitHub
commit e957ed0809
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -365,7 +365,7 @@ T ExpandValue(T value, size_t left_shift_amount)
constexpr int CountLeadingZeros(uint64_t value)
{
#if defined(__GNUC__)
return __builtin_clzll(value);
return value ? __builtin_clzll(value) : 64;
#elif defined(_MSC_VER) && defined(_M_ARM_64)
return _CountLeadingZeros64(value);
#elif defined(_MSC_VER) && defined(_M_X86_64)
@ -385,7 +385,7 @@ constexpr int CountLeadingZeros(uint64_t value)
constexpr int CountLeadingZeros(uint32_t value)
{
#if defined(__GNUC__)
return __builtin_clz(value);
return value ? __builtin_clz(value) : 32;
#elif defined(_MSC_VER) && defined(_M_ARM_64)
return _CountLeadingZeros(value);
#elif defined(_MSC_VER) && defined(_M_X86_64)