From c173d416f749348bee42e1a9436a999700d0f0e8 Mon Sep 17 00:00:00 2001 From: Boris Ulasevich Date: Thu, 6 Nov 2025 12:56:37 +0000 Subject: [PATCH] 8359256: AArch64: Use SHA3 GPR intrinsic where it's faster Reviewed-by: eastigeevich, phh --- src/hotspot/cpu/aarch64/globals_aarch64.hpp | 2 +- .../cpu/aarch64/vm_version_aarch64.cpp | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/hotspot/cpu/aarch64/globals_aarch64.hpp b/src/hotspot/cpu/aarch64/globals_aarch64.hpp index 8e520314c8b..107919b2cbd 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, true, \ + product(bool, UseSIMDForSHA3Intrinsic, false, \ "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 a04e9defa4b..b47bfe6a89f 100644 --- a/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/vm_version_aarch64.cpp @@ -375,18 +375,24 @@ void VM_Version::initialize() { FLAG_SET_DEFAULT(UseSHA256Intrinsics, 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_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_sha512()) {