mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-09 23:50:22 +00:00
8371459: [REDO] AArch64: Use SHA3 GPR intrinsic where it's faster
Reviewed-by: phh, bperez
This commit is contained in:
parent
4d9d2c352b
commit
2cb177d0ba
@ -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") \
|
||||
|
||||
@ -11876,16 +11876,13 @@ class StubGenerator: public StubCodeGenerator {
|
||||
StubRoutines::_sha512_implCompress = generate_sha512_implCompress(StubId::stubgen_sha512_implCompress_id);
|
||||
StubRoutines::_sha512_implCompressMB = generate_sha512_implCompress(StubId::stubgen_sha512_implCompressMB_id);
|
||||
}
|
||||
if (UseSHA3Intrinsics) {
|
||||
|
||||
if (UseSHA3Intrinsics && UseSIMDForSHA3Intrinsic) {
|
||||
StubRoutines::_double_keccak = generate_double_keccak();
|
||||
if (UseSIMDForSHA3Intrinsic) {
|
||||
StubRoutines::_sha3_implCompress = generate_sha3_implCompress(StubId::stubgen_sha3_implCompress_id);
|
||||
StubRoutines::_sha3_implCompressMB = generate_sha3_implCompress(StubId::stubgen_sha3_implCompressMB_id);
|
||||
} else {
|
||||
StubRoutines::_sha3_implCompress = generate_sha3_implCompress_gpr(StubId::stubgen_sha3_implCompress_id);
|
||||
StubRoutines::_sha3_implCompressMB = generate_sha3_implCompress_gpr(StubId::stubgen_sha3_implCompressMB_id);
|
||||
}
|
||||
StubRoutines::_sha3_implCompress = generate_sha3_implCompress(StubId::stubgen_sha3_implCompress_id);
|
||||
StubRoutines::_sha3_implCompressMB = generate_sha3_implCompress(StubId::stubgen_sha3_implCompressMB_id);
|
||||
} else if (UseSHA3Intrinsics) {
|
||||
StubRoutines::_sha3_implCompress = generate_sha3_implCompress_gpr(StubId::stubgen_sha3_implCompress_id);
|
||||
StubRoutines::_sha3_implCompressMB = generate_sha3_implCompress_gpr(StubId::stubgen_sha3_implCompressMB_id);
|
||||
}
|
||||
|
||||
if (UsePoly1305Intrinsics) {
|
||||
|
||||
@ -365,16 +365,28 @@ 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
|
||||
if (UseSHA) {
|
||||
// No need to check VM_Version::supports_sha3(), since a fallback GPR intrinsic implementation is provided.
|
||||
if (FLAG_IS_DEFAULT(UseSHA3Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA3Intrinsics, true);
|
||||
}
|
||||
} else if (UseSHA3Intrinsics) {
|
||||
// Matches the documented and tested behavior: the -UseSHA option disables all SHA intrinsics.
|
||||
warning("UseSHA3Intrinsics requires that UseSHA is enabled.");
|
||||
FLAG_SET_DEFAULT(UseSHA3Intrinsics, false);
|
||||
}
|
||||
|
||||
if (UseSHA3Intrinsics && VM_Version::supports_sha3()) {
|
||||
// Auto-enable UseSIMDForSHA3Intrinsic on hardware with performance benefit.
|
||||
// Note that the evaluation of SHA3 extension Intrinsics shows better performance
|
||||
// on Apple and Qualcomm silicon but worse performance on Neoverse V1 and N2.
|
||||
if (_cpu == CPU_APPLE || _cpu == CPU_QUALCOMM) { // Apple or Qualcomm silicon
|
||||
if (FLAG_IS_DEFAULT(UseSHA3Intrinsics)) {
|
||||
FLAG_SET_DEFAULT(UseSHA3Intrinsics, true);
|
||||
if (FLAG_IS_DEFAULT(UseSIMDForSHA3Intrinsic)) {
|
||||
FLAG_SET_DEFAULT(UseSIMDForSHA3Intrinsic, true);
|
||||
}
|
||||
}
|
||||
} else if (UseSHA3Intrinsics && UseSIMDForSHA3Intrinsic) {
|
||||
}
|
||||
if (UseSHA3Intrinsics && UseSIMDForSHA3Intrinsic && !VM_Version::supports_sha3()) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ public class TestUseSHA3IntrinsicsWithUseSHADisabledOnSupportedCPU {
|
||||
private static final String UNLOCK_DIAGNOSTIC = "-XX:+UnlockDiagnosticVMOptions";
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
if (!IntrinsicPredicates.SHA3_INSTRUCTION_AVAILABLE.getAsBoolean()) {
|
||||
if (!IntrinsicPredicates.SHA3_INTRINSIC_AVAILABLE.getAsBoolean()) {
|
||||
throw new SkippedException("Skipping... SHA3 intrinsics are not available on this platform.");
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ public class TestUseSHA3IntrinsicsWithUseSHADisabledOnSupportedCPU {
|
||||
private static void testWarningWhenEnablingWithUseSHADisabled() throws Throwable {
|
||||
// A warning should be printed when trying to enable UseSHA3Intrinsics with -UseSHA
|
||||
CommandLineOptionTest.verifySameJVMStartup(
|
||||
new String[] { WARNING_MESSAGE }, // Warning should appear
|
||||
new String[] { "warning" }, // Warning should appear
|
||||
null, // No unexpected output
|
||||
"JVM should start successfully",
|
||||
String.format("A warning should be printed when trying to enable %s while %s is disabled",
|
||||
|
||||
@ -51,7 +51,7 @@ public class TestUseSHA3IntrinsicsWithUseSHADisabledOnUnsupportedCPU {
|
||||
private static final String UNLOCK_DIAGNOSTIC = "-XX:+UnlockDiagnosticVMOptions";
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
if (IntrinsicPredicates.SHA3_INSTRUCTION_AVAILABLE.getAsBoolean()) {
|
||||
if (IntrinsicPredicates.SHA3_INTRINSIC_AVAILABLE.getAsBoolean()) {
|
||||
throw new SkippedException("Skipping... SHA3 intrinsics are available on this platform.");
|
||||
}
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ public class DigestOptionsBase extends CommandLineOptionTest {
|
||||
case DigestOptionsBase.USE_SHA512_INTRINSICS_OPTION:
|
||||
return IntrinsicPredicates.isSHA512IntrinsicAvailable();
|
||||
case DigestOptionsBase.USE_SHA3_INTRINSICS_OPTION:
|
||||
return IntrinsicPredicates.SHA3_INSTRUCTION_AVAILABLE;
|
||||
return IntrinsicPredicates.SHA3_INTRINSIC_AVAILABLE;
|
||||
default:
|
||||
throw new Error("Unexpected option " + optionName);
|
||||
}
|
||||
|
||||
@ -28,10 +28,7 @@
|
||||
* @summary Verify UseSHA3Intrinsics option processing on supported CPU.
|
||||
* @library /test/lib /
|
||||
* @requires vm.flagless
|
||||
* @requires os.arch == "aarch64" & os.family == "mac"
|
||||
* @comment sha3 is only implemented on AArch64 for now.
|
||||
* UseSHA3Intrinsics is only auto-enabled on Apple silicon, because it
|
||||
* may introduce performance regression on others. See JDK-8297092.
|
||||
* @requires (os.arch == "aarch64" | os.arch == "amd64" | os.arch == "x86_64")
|
||||
*
|
||||
* @build jdk.test.whitebox.WhiteBox
|
||||
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
|
||||
|
||||
@ -80,7 +80,8 @@ public class GenericTestCaseForSupportedCPU extends
|
||||
// Verify that if -XX:-UseSHA is passed to the JVM, it is not possible
|
||||
// to enable the tested option and a warning is printed.
|
||||
CommandLineOptionTest.verifySameJVMStartup(
|
||||
new String[] { DigestOptionsBase.getWarningForUnsupportedCPU(optionName) },
|
||||
new String[] { "warning: " }, // Accept any warning message, e.g. "requires that UseSHA is enabled"
|
||||
// or the common "not available on this CPU" message.
|
||||
null,
|
||||
shouldPassMessage,
|
||||
String.format("Enabling option '%s' should not be possible and should result in a warning if %s was passed to JVM",
|
||||
|
||||
@ -71,7 +71,8 @@ public class GenericTestCaseForUnsupportedCPU extends
|
||||
// a warning will occur in VM output if UseSHA is disabled.
|
||||
if (!optionName.equals(DigestOptionsBase.USE_SHA_OPTION)) {
|
||||
CommandLineOptionTest.verifySameJVMStartup(
|
||||
new String[] { DigestOptionsBase.getWarningForUnsupportedCPU(optionName) },
|
||||
new String[] { "warning: " }, // Accept any warning message, e.g. "requires that UseSHA is enabled"
|
||||
// or the common "not available on this CPU" message.
|
||||
null,
|
||||
shouldPassMessage,
|
||||
shouldPassMessage,
|
||||
|
||||
@ -109,6 +109,12 @@ public class IntrinsicPredicates {
|
||||
new OrPredicate(new CPUSpecificPredicate("amd64.*", new String[] {"avx512f", "avx512bw"}, null),
|
||||
new CPUSpecificPredicate("x86_64", new String[] {"avx512f", "avx512bw"}, null)));
|
||||
|
||||
public static final BooleanSupplier SHA3_INTRINSIC_AVAILABLE
|
||||
// AArch64 has both SHA3-based and GPR-based implementations of the SHA3 intrinsic. No need for the SHA3 capability.
|
||||
= new OrPredicate(new CPUSpecificPredicate("aarch64.*", null, null),
|
||||
new OrPredicate(new CPUSpecificPredicate("amd64.*", new String[] {"avx512f", "avx512bw"}, null),
|
||||
new CPUSpecificPredicate("x86_64", new String[] {"avx512f", "avx512bw"}, null)));
|
||||
|
||||
public static final BooleanSupplier ANY_SHA_INSTRUCTION_AVAILABLE
|
||||
= new OrPredicate(IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE,
|
||||
new OrPredicate(IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user