Skip to content

[release/6.0] Define __cpuid{ex} only when there's no builtin one (backport of #73065) #77507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/common/native/find-native-compiler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ if [ -z "$CLR_CC" ]; then
# Set default versions
if [ -z "$majorVersion" ]; then
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
if [ "$compiler" = "clang" ]; then versions=( 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 )
if [[ "$compiler" == "clang" ]]; then versions=( 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 )
elif [ "$compiler" = "gcc" ]; then versions=( 9 8 7 6 5 4.9 ); fi

for version in "${versions[@]}"; do
Expand Down
19 changes: 6 additions & 13 deletions src/coreclr/gc/env/gcenv.base.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#define SSIZE_T_MAX ((ptrdiff_t)(SIZE_T_MAX / 2))
#endif

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

#ifndef _INC_WINDOWS
// -----------------------------------------------------------------------------------------------------------
//
Expand Down Expand Up @@ -191,26 +195,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
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,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
Expand Down
18 changes: 7 additions & 11 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4092,15 +4092,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
Expand All @@ -4118,14 +4114,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:
Expand All @@ -4145,7 +4141,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
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/amd64/unixstubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C"
PORTABILITY_ASSERT("Implement for PAL");
}

#if !__has_builtin(__cpuid)
void __cpuid(int cpuInfo[4], int function_id)
{
// Based on the Clang implementation provided in cpuid.h:
Expand All @@ -20,7 +21,9 @@ extern "C"
: "0"(function_id)
);
}
#endif

#if !__has_builtin(__cpuidex)
void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id)
{
// Based on the Clang implementation provided in cpuid.h:
Expand All @@ -31,6 +34,7 @@ extern "C"
: "0"(function_id), "2"(subFunction_id)
);
}
#endif

DWORD xmmYmmStateSupport()
{
Expand Down