From 86eebc5b658b5c2ccf2f4fbc16e8aee9880919a5 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 4 Jan 2017 01:53:24 +0000 Subject: [PATCH] Refactor bitscan64 check Introduce a `_LIBCPP_HAS_BITSCAN64` macro to specify if the 64-bit variant of the bitscan family of APIs is available. This avoids duplicating the check in the support header. llvm-svn: 290924 --- libcxx/include/__config | 3 +++ libcxx/include/support/win32/support.h | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 4f0fe1d14805..bb6d998961f3 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -173,6 +173,9 @@ # ifndef __MINGW32__ # define _LIBCPP_MSVCRT // Using Microsoft's C Runtime library # endif +# if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_ARM) || defined(__arm__)) +# define _LIBCPP_HAS_BITSCAN64 +# endif #endif // defined(_WIN32) #ifdef __sun__ diff --git a/libcxx/include/support/win32/support.h b/libcxx/include/support/win32/support.h index 105721913413..17ee1980a643 100644 --- a/libcxx/include/support/win32/support.h +++ b/libcxx/include/support/win32/support.h @@ -110,7 +110,7 @@ _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(_M_ARM) || defined(__arm__)) || \ +#if defined(_LIBCPP_HAS_BITSCAN64) (defined(_M_AMD64) || defined(__x86_64__)) if (_BitScanForward64(&where, mask)) return static_cast(where); @@ -151,8 +151,7 @@ _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(_M_ARM) || defined(__arm__)) || \ - (defined(_M_AMD64) || defined(__x86_64__)) +#if defined(_LIBCPP_HAS_BITSCAN64) if (_BitScanReverse64(&where, mask)) return static_cast(63 - where); #else