Skip to content

Commit

Permalink
Fix x64 crossbuild on macOS arm64 (#91413)
Browse files Browse the repository at this point in the history
 cpufeatures.h/.c uses TARGET_ ifdefs, but it should use HOST_ ifdefs
  • Loading branch information
janvorli authored Sep 6, 2023
1 parent ebae468 commit 04bd438
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
40 changes: 20 additions & 20 deletions src/native/minipal/cpufeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#include "cpufeatures.h"
#include "cpuid.h"

#if TARGET_WINDOWS
#if HOST_WINDOWS

#include <Windows.h>

#else // TARGET_WINDOWS
#else // HOST_WINDOWS

#include "minipalconfig.h"

Expand Down Expand Up @@ -41,10 +41,10 @@
#include <sys/sysctl.h>
#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()
{
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions src/native/minipal/cpufeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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"
Expand Down

0 comments on commit 04bd438

Please sign in to comment.