From 4df97efc7a9dbfe48429d246f28d2e8cf81f9c7d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 3 Aug 2023 19:52:07 -0700 Subject: [PATCH 1/2] Light up for newer arm64 hardware capabilities Fixes #89937 --- src/native/minipal/cpufeatures.c | 139 +++++-------------------------- 1 file changed, 23 insertions(+), 116 deletions(-) diff --git a/src/native/minipal/cpufeatures.c b/src/native/minipal/cpufeatures.c index a606bfbe76b4dd..99cf9c9ddc0073 100644 --- a/src/native/minipal/cpufeatures.c +++ b/src/native/minipal/cpufeatures.c @@ -17,8 +17,21 @@ #include "minipalconfig.h" #if HAVE_AUXV_HWCAP_H + #include #include + +// Light-up for hardware capabilities that are not present in older headers used by the portable build. +#ifndef HWCAP_ASIMDRDM +#define HWCAP_ASIMDRDM (1 << 12) +#endif +#ifndef HWCAP_LRCPC +#define HWCAP_LRCPC (1 << 15) +#endif +#ifdef HWCAP_ASIMDDP +#define HWCAP_ASIMDDP (1 << 20) +#endif + #endif #if HAVE_SYSCTLBYNAME @@ -306,142 +319,36 @@ int minipal_getcpufeatures(void) #if defined(TARGET_ARM64) #if defined(TARGET_UNIX) - #if HAVE_AUXV_HWCAP_H - unsigned long hwCap = getauxval(AT_HWCAP); - // HWCAP_* flags are introduced by ARM into the Linux kernel as new extensions are published. - // For a given kernel, some of these flags may not be present yet. - // Use ifdef for each to allow for compilation with any vintage kernel. - // From a single binary distribution perspective, compiling with latest kernel asm/hwcap.h should - // include all published flags. Given flags are merged to kernel and published before silicon is - // available, using the latest kernel for release should be sufficient. +#if HAVE_AUXV_HWCAP_H + unsigned long hwCap = getauxval(AT_HWCAP); -#ifdef HWCAP_AES if (hwCap & HWCAP_AES) result |= ARM64IntrinsicConstants_Aes; -#endif -#ifdef HWCAP_ATOMICS + if (hwCap & HWCAP_ATOMICS) result |= ARM64IntrinsicConstants_Atomics; -#endif -#ifdef HWCAP_CRC32 + if (hwCap & HWCAP_CRC32) result |= ARM64IntrinsicConstants_Crc32; -#endif -#ifdef HWCAP_DCPOP -// if (hwCap & HWCAP_DCPOP) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_ASIMDDP + if (hwCap & HWCAP_ASIMDDP) result |= ARM64IntrinsicConstants_Dp; -#endif -#ifdef HWCAP_FCMA -// if (hwCap & HWCAP_FCMA) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_FP -// if (hwCap & HWCAP_FP) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_FPHP -// if (hwCap & HWCAP_FPHP) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_JSCVT -// if (hwCap & HWCAP_JSCVT) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_LRCPC + if (hwCap & HWCAP_LRCPC) result |= ARM64IntrinsicConstants_Rcpc; -#endif -#ifdef HWCAP_PMULL -// if (hwCap & HWCAP_PMULL) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_SHA1 + if (hwCap & HWCAP_SHA1) result |= ARM64IntrinsicConstants_Sha1; -#endif -#ifdef HWCAP_SHA2 + if (hwCap & HWCAP_SHA2) result |= ARM64IntrinsicConstants_Sha256; -#endif -#ifdef HWCAP_SHA512 -// if (hwCap & HWCAP_SHA512) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_SHA3 -// if (hwCap & HWCAP_SHA3) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_ASIMD + if (hwCap & HWCAP_ASIMD) result |= ARM64IntrinsicConstants_AdvSimd | ARM64IntrinsicConstants_VectorT128; -#endif -#ifdef HWCAP_ASIMDRDM + if (hwCap & HWCAP_ASIMDRDM) result |= ARM64IntrinsicConstants_Rdm; -#endif -#ifdef HWCAP_ASIMDHP -// if (hwCap & HWCAP_ASIMDHP) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_SM3 -// if (hwCap & HWCAP_SM3) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_SM4 -// if (hwCap & HWCAP_SM4) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP_SVE -// if (hwCap & HWCAP_SVE) -// result |= ARM64IntrinsicConstants_???; -#endif - -#ifdef AT_HWCAP2 - unsigned long hwCap2 = getauxval(AT_HWCAP2); - -#ifdef HWCAP2_DCPODP -// if (hwCap2 & HWCAP2_DCPODP) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_SVE2 -// if (hwCap2 & HWCAP2_SVE2) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_SVEAES -// if (hwCap2 & HWCAP2_SVEAES) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_SVEPMULL -// if (hwCap2 & HWCAP2_SVEPMULL) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_SVEBITPERM -// if (hwCap2 & HWCAP2_SVEBITPERM) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_SVESHA3 -// if (hwCap2 & HWCAP2_SVESHA3) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_SVESM4 -// if (hwCap2 & HWCAP2_SVESM4) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_FLAGM2 -// if (hwCap2 & HWCAP2_FLAGM2) -// result |= ARM64IntrinsicConstants_???; -#endif -#ifdef HWCAP2_FRINT -// if (hwCap2 & HWCAP2_FRINT) -// result |= ARM64IntrinsicConstants_???; -#endif - -#endif // AT_HWCAP2 #else // !HAVE_AUXV_HWCAP_H From 55a75056293e0c259cb38bf6c7faa604cd7bae3e Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 3 Aug 2023 21:30:55 -0700 Subject: [PATCH 2/2] Typo --- src/native/minipal/cpufeatures.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/minipal/cpufeatures.c b/src/native/minipal/cpufeatures.c index 99cf9c9ddc0073..f637e58c10f14e 100644 --- a/src/native/minipal/cpufeatures.c +++ b/src/native/minipal/cpufeatures.c @@ -28,7 +28,7 @@ #ifndef HWCAP_LRCPC #define HWCAP_LRCPC (1 << 15) #endif -#ifdef HWCAP_ASIMDDP +#ifndef HWCAP_ASIMDDP #define HWCAP_ASIMDDP (1 << 20) #endif