From 04bd438844482c907062583153a43a9e3b37dbb8 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 6 Sep 2023 07:20:06 +0200 Subject: [PATCH] Fix x64 crossbuild on macOS arm64 (#91413) cpufeatures.h/.c uses TARGET_ ifdefs, but it should use HOST_ ifdefs --- src/native/minipal/cpufeatures.c | 40 ++++++++++++++++---------------- src/native/minipal/cpufeatures.h | 8 +++---- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/native/minipal/cpufeatures.c b/src/native/minipal/cpufeatures.c index af122d4fbb1c0..db7e7acf3b80e 100644 --- a/src/native/minipal/cpufeatures.c +++ b/src/native/minipal/cpufeatures.c @@ -8,11 +8,11 @@ #include "cpufeatures.h" #include "cpuid.h" -#if TARGET_WINDOWS +#if HOST_WINDOWS #include -#else // TARGET_WINDOWS +#else // HOST_WINDOWS #include "minipalconfig.h" @@ -41,10 +41,10 @@ #include #endif -#endif // !TARGET_WINDOWS +#endif // !HOST_WINDOWS -#if defined(TARGET_UNIX) -#if defined(TARGET_X86) || defined(TARGET_AMD64) +#if defined(HOST_UNIX) +#if defined(HOST_X86) || defined(HOST_AMD64) static uint32_t xmmYmmStateSupport() { @@ -64,7 +64,7 @@ static uint32_t xmmYmmStateSupport() static uint32_t avx512StateSupport() { -#if defined(TARGET_APPLE) +#if defined(HOST_APPLE) // MacOS has specialized behavior where it reports AVX512 support but doesnt // actually enable AVX512 until the first instruction is executed and does so // on a per thread basis. It does this by catching the faulting instruction and @@ -98,11 +98,11 @@ static bool IsAvx512Enabled() { return true; } -#endif // defined(TARGET_X86) || defined(TARGET_AMD64) -#endif // TARGET_UNIX +#endif // defined(HOST_X86) || defined(HOST_AMD64) +#endif // HOST_UNIX -#if defined(TARGET_WINDOWS) -#if defined(TARGET_X86) || defined(TARGET_AMD64) +#if defined(HOST_WINDOWS) +#if defined(HOST_X86) || defined(HOST_AMD64) static uint32_t xmmYmmStateSupport() { // check OS has enabled both XMM and YMM state support @@ -127,14 +127,14 @@ static bool IsAvx512Enabled() return ((FeatureMask & XSTATE_MASK_AVX512) != 0); } -#endif // defined(TARGET_X86) || defined(TARGET_AMD64) -#endif // TARGET_WINDOWS +#endif // defined(HOST_X86) || defined(HOST_AMD64) +#endif // HOST_WINDOWS int minipal_getcpufeatures(void) { int result = 0; -#if defined(TARGET_X86) || defined(TARGET_AMD64) +#if defined(HOST_X86) || defined(HOST_AMD64) int cpuidInfo[4]; @@ -318,10 +318,10 @@ int minipal_getcpufeatures(void) } } -#endif // TARGET_X86 || TARGET_AMD64 +#endif // HOST_X86 || HOST_AMD64 -#if defined(TARGET_ARM64) -#if defined(TARGET_UNIX) +#if defined(HOST_ARM64) +#if defined(HOST_UNIX) #if HAVE_AUXV_HWCAP_H unsigned long hwCap = getauxval(AT_HWCAP); @@ -395,9 +395,9 @@ int minipal_getcpufeatures(void) result |= ARM64IntrinsicConstants_AdvSimd | ARM64IntrinsicConstants_VectorT128; #endif // HAVE_AUXV_HWCAP_H -#endif // TARGET_UNIX +#endif // HOST_UNIX -#if defined(TARGET_WINDOWS) +#if defined(HOST_WINDOWS) // FP and SIMD support are enabled by default result |= ARM64IntrinsicConstants_AdvSimd | ARM64IntrinsicConstants_VectorT128; @@ -430,9 +430,9 @@ int minipal_getcpufeatures(void) // TODO: IsProcessorFeaturePresent doesn't support LRCPC2 yet. -#endif // TARGET_WINDOWS +#endif // HOST_WINDOWS -#endif // TARGET_ARM64 +#endif // HOST_ARM64 return result; } diff --git a/src/native/minipal/cpufeatures.h b/src/native/minipal/cpufeatures.h index ead191f2921d9..d0f615d293d59 100644 --- a/src/native/minipal/cpufeatures.h +++ b/src/native/minipal/cpufeatures.h @@ -8,7 +8,7 @@ // Should match the constants defined in the compiler in HardwareIntrinsicHelpers.cs // -#if defined(TARGET_X86) || defined(TARGET_AMD64) +#if defined(HOST_X86) || defined(HOST_AMD64) enum XArchIntrinsicConstants { XArchIntrinsicConstants_Aes = 0x0001, @@ -41,9 +41,9 @@ enum XArchIntrinsicConstants XArchIntrinsicConstants_VectorT256 = 0x8000000, XArchIntrinsicConstants_VectorT512 = 0x10000000, }; -#endif // TARGET_X86 || TARGET_AMD64 +#endif // HOST_X86 || HOST_AMD64 -#if defined(TARGET_ARM64) +#if defined(HOST_ARM64) enum ARM64IntrinsicConstants { ARM64IntrinsicConstants_AdvSimd = 0x0001, @@ -65,7 +65,7 @@ enum ARM64IntrinsicConstants #define ARM64_ATOMICS_FEATURE_FLAG_BIT 7 static_assert((1 << ARM64_ATOMICS_FEATURE_FLAG_BIT) == ARM64IntrinsicConstants_Atomics, "ARM64_ATOMICS_FEATURE_FLAG_BIT must match with ARM64IntrinsicConstants_Atomics"); -#endif // TARGET_ARM64 +#endif // HOST_ARM64 #ifdef __cplusplus extern "C"