aboutsummaryrefslogtreecommitdiff
path: root/include/support/win32/support.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/support/win32/support.h')
-rw-r--r--include/support/win32/support.h13
1 files changed, 5 insertions, 8 deletions
diff --git a/include/support/win32/support.h b/include/support/win32/support.h
index 6a5763b5e49b..17ee1980a643 100644
--- a/include/support/win32/support.h
+++ b/include/support/win32/support.h
@@ -110,10 +110,11 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
unsigned long where;
// Search from LSB to MSB for first set bit.
// Returns zero if no set bit is found.
-#if defined(_WIN64)
+#if defined(_LIBCPP_HAS_BITSCAN64)
+ (defined(_M_AMD64) || defined(__x86_64__))
if (_BitScanForward64(&where, mask))
return static_cast<int>(where);
-#elif defined(_WIN32)
+#else
// Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
// Scan the Low Word.
if (_BitScanForward(&where, static_cast<unsigned long>(mask)))
@@ -121,8 +122,6 @@ _LIBCPP_ALWAYS_INLINE int __builtin_ctzll(unsigned long long mask)
// Scan the High Word.
if (_BitScanForward(&where, static_cast<unsigned long>(mask >> 32)))
return static_cast<int>(where + 32); // Create a bit offset from the LSB.
-#else
-#error "Implementation of __builtin_ctzll required"
#endif
return 64;
}
@@ -152,10 +151,10 @@ _LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
unsigned long where;
// BitScanReverse scans from MSB to LSB for first set bit.
// Returns 0 if no set bit is found.
-#if defined(_WIN64)
+#if defined(_LIBCPP_HAS_BITSCAN64)
if (_BitScanReverse64(&where, mask))
return static_cast<int>(63 - where);
-#elif defined(_WIN32)
+#else
// Scan the high 32 bits.
if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
return static_cast<int>(63 -
@@ -163,8 +162,6 @@ _LIBCPP_ALWAYS_INLINE int __builtin_clzll(unsigned long long mask)
// Scan the low 32 bits.
if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
return static_cast<int>(63 - where);
-#else
-#error "Implementation of __builtin_clzll required"
#endif
return 64; // Undefined Behavior.
}