From 524222f09453872128c71f350e1fea757ba758fa Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 22 Feb 2015 17:43:58 +0800 Subject: [PATCH] Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls. Implementation used: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/support.h?view=markup#l135 --- format.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/format.h b/format.h index 7a71ddc1..47f77da2 100644 --- a/format.h +++ b/format.h @@ -56,15 +56,22 @@ inline uint32_t clz(uint32_t x) { return 31 - r; } # define FMT_BUILTIN_CLZ(n) fmt::internal::clz(n) -# ifdef _WIN64 -# pragma intrinsic(_BitScanReverse64) inline uint32_t clzll(uint64_t n) { unsigned long r = 0; +# ifdef _WIN64 +# pragma intrinsic(_BitScanReverse64) _BitScanReverse64(&r, x); +# else + // Scan the high 32 bits. + if (_BitScanReverse(&r, static_cast(n >> 32))) + return 63 - (r + 32); + + // Scan the low 32 bits. + _BitScanReverse(&r, static_cast(n)); +# endif return 63 - r; } # define FMT_BUILTIN_CLZLL(n) fmt::internal::clzll(n) -# endif } } #endif