Skip to content

Commit

Permalink
Add support to detect Neoverse V2 cores at runtime or at build time a…
Browse files Browse the repository at this point in the history
…nd pick the optimal implementatin
  • Loading branch information
andrewhop committed Jul 15, 2024
1 parent 00fcba4 commit 3af0d4e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crypto/fipsmodule/cpucap/cpu_aarch64_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ void OPENSSL_cpuid_setup(void) {
// is supported. As of Valgrind 3.21 trying to read from that register will
// cause Valgrind to crash.
if (hwcap & kCPUID) {
// Check if the CPU model is Neoverse V1,
// Check if the CPU model is Neoverse V1 or V2,
// which has a wide crypto/SIMD pipeline.
OPENSSL_arm_midr = armv8_cpuid_probe();
if (MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_ARM, ARM_CPU_PART_V1)) {
OPENSSL_armcap_P |= ARMV8_NEOVERSE_V1;
}
if (MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_ARM, ARM_CPU_PART_V2)) {
OPENSSL_armcap_P |= ARMV8_NEOVERSE_V2;
}
}

// OPENSSL_armcap is a 32-bit, unsigned value which may start with "0x" to
Expand Down
3 changes: 3 additions & 0 deletions crypto/fipsmodule/cpucap/cpucap.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ HIDDEN uint32_t OPENSSL_armcap_P =
#endif
#if defined(OPENSSL_STATIC_ARMCAP_NEOVERSE_V1) || defined(__ARM_FEATURE_NEOVERSE_V1)
ARMV8_NEOVERSE_V1 |
#endif
#if defined(OPENSSL_STATIC_ARMCAP_NEOVERSE_V2) || defined(__ARM_FEATURE_NEOVERSE_V2)
ARMV8_NEOVERSE_V2 |
#endif
0;

Expand Down
2 changes: 2 additions & 0 deletions crypto/fipsmodule/cpucap/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ OPENSSL_INLINE int CRYPTO_is_ARMv8_PMULL_capable(void) {
OPENSSL_INLINE int CRYPTO_is_ARMv8_GCM_8x_capable(void) {
return ((OPENSSL_armcap_P & ARMV8_SHA3) != 0 &&
((OPENSSL_armcap_P & ARMV8_NEOVERSE_V1) != 0 ||
(OPENSSL_armcap_P & ARMV8_NEOVERSE_V2) != 0 ||
(OPENSSL_armcap_P & ARMV8_APPLE_M1) != 0));
}

OPENSSL_INLINE int CRYPTO_is_ARMv8_wide_multiplier_capable(void) {
return (OPENSSL_armcap_P & ARMV8_NEOVERSE_V1) != 0 ||
(OPENSSL_armcap_P & ARMV8_NEOVERSE_V2) != 0 ||
(OPENSSL_armcap_P & ARMV8_APPLE_M1) != 0;
}

Expand Down
2 changes: 2 additions & 0 deletions include/openssl/arm_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
// wide crypto pipeline and fast multiplier.
#define ARMV8_NEOVERSE_V1 (1 << 12)
#define ARMV8_APPLE_M1 (1 << 13)
#define ARMV8_NEOVERSE_V2 (1 << 14)

//
// MIDR_EL1 system register
Expand All @@ -102,6 +103,7 @@
# define ARM_CPU_PART_CORTEX_A72 0xD08
# define ARM_CPU_PART_N1 0xD0C
# define ARM_CPU_PART_V1 0xD40
# define ARM_CPU_PART_V2 0xD4F

# define MIDR_PARTNUM_SHIFT 4
# define MIDR_PARTNUM_MASK (0xfffUL << MIDR_PARTNUM_SHIFT)
Expand Down

0 comments on commit 3af0d4e

Please sign in to comment.