Use of intrinsic for clz within MSVS

This commit is contained in:
Patrick Pelissier committed 2020-06-25 23:45:39 +02:00
1 parent b040bc411f
commit 3f8e93ad7a
1 file changed
+22
+22
View File
@@ -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 <intrin.h>
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"