diff --git a/src/coreclr/gc/env/gcenv.base.h b/src/coreclr/gc/env/gcenv.base.h index 0bb57d800030..56257dcb9096 100644 --- a/src/coreclr/gc/env/gcenv.base.h +++ b/src/coreclr/gc/env/gcenv.base.h @@ -45,6 +45,10 @@ #define SSIZE_T_MAX ((ptrdiff_t)(SIZE_T_MAX / 2)) #endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + #ifndef _INC_WINDOWS // ----------------------------------------------------------------------------------------------------------- // @@ -186,26 +190,15 @@ typedef DWORD (WINAPI *PTHREAD_START_ROUTINE)(void* lpThreadParameter); #endif #else // _MSC_VER -#ifdef __llvm__ -#define HAS_IA32_PAUSE __has_builtin(__builtin_ia32_pause) -#define HAS_IA32_MFENCE __has_builtin(__builtin_ia32_mfence) -#else -#define HAS_IA32_PAUSE 0 -#define HAS_IA32_MFENCE 0 -#endif - -// Only clang defines __has_builtin, so we first test for a GCC define -// before using __has_builtin. - #if defined(__i386__) || defined(__x86_64__) -#if (__GNUC__ > 4 && __GNUC_MINOR > 7) || HAS_IA32_PAUSE +#if __has_builtin(__builtin_ia32_pause) // clang added this intrinsic in 3.8 // gcc added this intrinsic by 4.7.1 #define YieldProcessor __builtin_ia32_pause #endif // __has_builtin(__builtin_ia32_pause) -#if defined(__GNUC__) || HAS_IA32_MFENCE +#if __has_builtin(__builtin_ia32_mfence) // clang has had this intrinsic since at least 3.0 // gcc has had this intrinsic since forever #define MemoryBarrier __builtin_ia32_mfence diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index e3dd1ca37737..85d6a001b038 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -584,12 +584,6 @@ void GCToOSInterface::FlushProcessWriteBuffers() // otherwise raises a SIGTRAP. void GCToOSInterface::DebugBreak() { - // __has_builtin is only defined by clang. GCC doesn't have a debug - // trap intrinsic anyway. -#ifndef __has_builtin - #define __has_builtin(x) 0 -#endif // __has_builtin - #if __has_builtin(__builtin_debugtrap) __builtin_debugtrap(); #else diff --git a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp index 506c645d71d2..526810177a5e 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp @@ -1039,10 +1039,6 @@ REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalCompatibleWaitAny(UInt32_BOOL alert return WaitForSingleObjectEx(pHandles[0], timeout, alertable); } -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif - #if !__has_builtin(_mm_pause) extern "C" void _mm_pause() // Defined for implementing PalYieldProcessor in PalRedhawk.h diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index de4ad2b2e8dc..cfb764368b57 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4285,15 +4285,11 @@ inline WCHAR *PAL_wcsstr(WCHAR* S, const WCHAR* P) } #endif -#if defined(__llvm__) -#define HAS_ROTL __has_builtin(_rotl) -#define HAS_ROTR __has_builtin(_rotr) -#else -#define HAS_ROTL 0 -#define HAS_ROTR 0 +#ifndef __has_builtin +#define __has_builtin(x) 0 #endif -#if !HAS_ROTL +#if !__has_builtin(_rotl) /*++ Function: _rotl @@ -4311,14 +4307,14 @@ unsigned int __cdecl _rotl(unsigned int value, int shift) retval = (value << shift) | (value >> (sizeof(int) * CHAR_BIT - shift)); return retval; } -#endif // !HAS_ROTL +#endif // !__has_builtin(_rotl) // On 64 bit unix, make the long an int. #ifdef HOST_64BIT #define _lrotl _rotl -#endif // HOST_64BIT +#endif -#if !HAS_ROTR +#if !__has_builtin(_rotr) /*++ Function: @@ -4338,7 +4334,7 @@ unsigned int __cdecl _rotr(unsigned int value, int shift) return retval; } -#endif // !HAS_ROTR +#endif // !__has_builtin(_rotr) PALIMPORT int __cdecl abs(int); // clang complains if this is declared with __int64