From 25672cdc47ca003c4c43e67fa77378853703ddb3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Tue, 13 Jan 2015 00:32:53 +0300 Subject: [PATCH] cntlz fix --- Utilities/GNU.h | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Utilities/GNU.h b/Utilities/GNU.h index 91fc34ae50..b1988b4dfa 100644 --- a/Utilities/GNU.h +++ b/Utilities/GNU.h @@ -289,9 +289,7 @@ static __forceinline uint64_t InterlockedXor(volatile uint64_t* dest, uint64_t v static __forceinline uint32_t cntlz32(uint32_t arg) { -#if defined(__GNUG__) - return __builtin_clzl(arg); -#else +#if defined(_MSC_VER) unsigned long res; if (!_BitScanReverse(&res, arg)) { @@ -301,14 +299,21 @@ static __forceinline uint32_t cntlz32(uint32_t arg) { return res ^ 31; } +#else + if (arg) + { + return __builtin_clzll((uint64_t)arg) - 32; + } + else + { + return 32; + } #endif } static __forceinline uint64_t cntlz64(uint64_t arg) { -#if defined(__GNUG__) - return __builtin_clzll(arg); -#else +#if defined(_MSC_VER) unsigned long res; if (!_BitScanReverse64(&res, arg)) { @@ -318,6 +323,15 @@ static __forceinline uint64_t cntlz64(uint64_t arg) { return res ^ 63; } +#else + if (arg) + { + return __builtin_clzll(arg); + } + else + { + return 64; + } #endif }