From 3d6824e802bda6efed40f7613eda7c8c0d84e673 Mon Sep 17 00:00:00 2001 From: Tobias Hartmann Date: Fri, 7 Nov 2025 09:19:18 +0000 Subject: [PATCH] 8371432: [BACKOUT] 8359256: AArch64: Use SHA3 GPR intrinsic where it's faster Reviewed-by: mchevalier, epeter, syan --- src/hotspot/cpu/aarch64/globals_aarch64.hpp | 2 +- .../cpu/aarch64/vm_version_aarch64.cpp | 30 ++++++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/hotspot/cpu/aarch64/globals_aarch64.hpp b/src/hotspot/cpu/aarch64/globals_aarch64.hpp index 107919b2cbd..8e520314c8b 100644 --- a/src/hotspot/cpu/aarch64/globals_aarch64.hpp +++ b/src/hotspot/cpu/aarch64/globals_aarch64.hpp @@ -95,7 +95,7 @@ define_pd_global(intx, InlineSmallCode, 1000); "Use simplest and shortest implementation for array equals") \ product(bool, UseSIMDForBigIntegerShiftIntrinsics, true, \ "Use SIMD instructions for left/right shift of BigInteger") \ - product(bool, UseSIMDForSHA3Intrinsic, false, \ + product(bool, UseSIMDForSHA3Intrinsic, true, \ "Use SIMD SHA3 instructions for SHA3 intrinsic") \ product(bool, AvoidUnalignedAccesses, false, \ "Avoid generating unaligned memory accesses") \ diff --git a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp index b47bfe6a89f..a04e9defa4b 100644 --- a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp @@ -375,24 +375,18 @@ void VM_Version::initialize() { FLAG_SET_DEFAULT(UseSHA256Intrinsics, false); } - if (UseSHA && VM_Version::supports_sha3() && _cpu == CPU_APPLE && FLAG_IS_DEFAULT(UseSIMDForSHA3Intrinsic)) { - // Note: SIMD faster on Apple, worse on Neoverse V1, V2 and N2. - FLAG_SET_DEFAULT(UseSIMDForSHA3Intrinsic, true); - } - - // Enable SHA-3 intrinsics (SIMD or GPR). The GPR path does not require SHA instructions. - if (FLAG_IS_DEFAULT(UseSHA3Intrinsics)) { - FLAG_SET_DEFAULT(UseSHA3Intrinsics, true); - } - - if (!UseSHA3Intrinsics && UseSIMDForSHA3Intrinsic) { - // Keep flags consistent: if SHA3 intrinsics are off, disable the SHA3 SIMD variant. - FLAG_SET_DEFAULT(UseSIMDForSHA3Intrinsic, false); - } - - if (!VM_Version::supports_sha3() && UseSIMDForSHA3Intrinsic) { - warning("SHA3 instructions are not available on this CPU"); - FLAG_SET_DEFAULT(UseSIMDForSHA3Intrinsic, false); + if (UseSHA && VM_Version::supports_sha3()) { + // Auto-enable UseSHA3Intrinsics on hardware with performance benefit. + // Note that the evaluation of UseSHA3Intrinsics shows better performance + // on Apple silicon but worse performance on Neoverse V1 and N2. + if (_cpu == CPU_APPLE) { // Apple silicon + if (FLAG_IS_DEFAULT(UseSHA3Intrinsics)) { + FLAG_SET_DEFAULT(UseSHA3Intrinsics, true); + } + } + } else if (UseSHA3Intrinsics && UseSIMDForSHA3Intrinsic) { + warning("Intrinsics for SHA3-224, SHA3-256, SHA3-384 and SHA3-512 crypto hash functions not available on this CPU."); + FLAG_SET_DEFAULT(UseSHA3Intrinsics, false); } if (UseSHA && VM_Version::supports_sha512()) {