From 6106d6481f0ce60cbd1a51042238c0f3de3af939 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 3 Jan 2021 17:35:15 +0000 Subject: [PATCH] BitUtils: __builtin_clz is undefined when value == 0 --- Source/Core/Common/BitUtils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/BitUtils.h b/Source/Core/Common/BitUtils.h index 0bf8ab2d26..bc4778611c 100644 --- a/Source/Core/Common/BitUtils.h +++ b/Source/Core/Common/BitUtils.h @@ -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)