[compiler-rt] r242002 - sanitizer_common: Fix implementation of bit count operations on 64-bit Windows.
Peter Collingbourne
peter at pcc.me.uk
Sun Jul 12 17:26:03 PDT 2015
Author: pcc
Date: Sun Jul 12 19:26:03 2015
New Revision: 242002
URL: http://llvm.org/viewvc/llvm-project?rev=242002&view=rev
Log:
sanitizer_common: Fix implementation of bit count operations on 64-bit Windows.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=242002&r1=242001&r2=242002&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Sun Jul 12 19:26:03 2015
@@ -355,7 +355,11 @@ INLINE uptr MostSignificantSetBitIndex(u
CHECK_NE(x, 0U);
unsigned long up; // NOLINT
#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
+# ifdef _WIN64
+ up = SANITIZER_WORDSIZE - 1 - __builtin_clzll(x);
+# else
up = SANITIZER_WORDSIZE - 1 - __builtin_clzl(x);
+# endif
#elif defined(_WIN64)
_BitScanReverse64(&up, x);
#else
@@ -368,7 +372,11 @@ INLINE uptr LeastSignificantSetBitIndex(
CHECK_NE(x, 0U);
unsigned long up; // NOLINT
#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
+# ifdef _WIN64
+ up = __builtin_ctzll(x);
+# else
up = __builtin_ctzl(x);
+# endif
#elif defined(_WIN64)
_BitScanForward64(&up, x);
#else
@@ -406,17 +414,7 @@ INLINE bool IsAligned(uptr a, uptr align
INLINE uptr Log2(uptr x) {
CHECK(IsPowerOfTwo(x));
-#if !SANITIZER_WINDOWS || defined(__clang__) || defined(__GNUC__)
- return __builtin_ctzl(x);
-#elif defined(_WIN64)
- unsigned long ret; // NOLINT
- _BitScanForward64(&ret, x);
- return ret;
-#else
- unsigned long ret; // NOLINT
- _BitScanForward(&ret, x);
- return ret;
-#endif
+ return LeastSignificantSetBitIndex(x);
}
// Don't use std::min, std::max or std::swap, to minimize dependency
More information about the llvm-commits
mailing list