From 3f8e93ad7a25f6129222a0a9cf79974e0bc95208 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 25 Jun 2020 23:45:39 +0200 Subject: [PATCH] Use of intrinsic for clz within MSVS --- m-core.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/m-core.h b/m-core.h index 3243dc64..dd7a7570 100644 --- a/m-core.h +++ b/m-core.h @@ -1855,6 +1855,28 @@ static inline unsigned int m_core_clz64(uint64_t limb) { return M_UNLIKELY (limb == 0ULL) ? sizeof (uint64_t)*CHAR_BIT : (unsigned int) __builtin_clzll(limb) - (sizeof (unsigned long long) - sizeof (uint64_t)) * CHAR_BIT; } + +#elif defined(_MSC_VER) +#include +static inline unsigned int m_core_clz32(uint32_t limb) +{ + unsigned long bit = 0; + if (_BitScanReverse( &bit_zero, limb ) != 0) { + return 31 - bit; + } else { + return 32; + } +} +static inline unsigned int m_core_clz64(uint64_t limb) +{ + unsigned long bit = 0; + if (_BitScanReverse64( &bit_zero, limb ) != 0) { + return 63 - bit; + } else { + return 64; + } +} + #else #define M_CORE_CLZ_TAB "\010\07\06\06\05\05\05\05\04\04\04\04\04\04\04\04\03\03\03\03\03\03\03\03\03\03\03\03\03\03\03\03\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\02\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\01\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"