Skip to content

Commit 14a9b30

Browse files
committed
Improve feature detect for combined aarch64 features
LLVM's `ssbs` and `mte` target_features represent two Arm features. Linux's HWCAP also represents the same two features, so this is just a documentation update. LLVM's `ras` target_feature represents two Arm features - FEAT_RAS and FEAT_RASv1p1. There is no runtime detection for this, so this is a no-op in stdarch. LLVM's `aes` feature covers both `FEAT_AES` and `FEAT_PMULL`, but Linux exposes seperate feature bits. This patch makes the `aes` target_feature correctly shortcut runtime `pmull` detection and also makes the `aes` feature check for `pmull` at runtime to bring it in line with the target_feature behaviour. In practice I think this makes the two runtime features identical since the ID_AA64ISAR0_EL1 register does not allow for PMULL without AES.
1 parent 1ee5288 commit 14a9b30

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

crates/std_detect/src/detect/arch/aarch64.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ features! {
3030
/// * `"fhm"` - FEAT_FHM
3131
/// * `"dit"` - FEAT_DIT
3232
/// * `"flagm"` - FEAT_FLAGM
33-
/// * `"ssbs"` - FEAT_SSBS
33+
/// * `"ssbs"` - FEAT_SSBS & FEAT_SSBS2
3434
/// * `"sb"` - FEAT_SB
3535
/// * `"paca"` - FEAT_PAuth (address authentication)
3636
/// * `"pacg"` - FEAT_Pauth (generic authentication)
@@ -48,10 +48,10 @@ features! {
4848
/// * `"bf16"` - FEAT_BF16
4949
/// * `"rand"` - FEAT_RNG
5050
/// * `"bti"` - FEAT_BTI
51-
/// * `"mte"` - FEAT_MTE
51+
/// * `"mte"` - FEAT_MTE & FEAT_MTE2
5252
/// * `"jsconv"` - FEAT_JSCVT
5353
/// * `"fcma"` - FEAT_FCMA
54-
/// * `"aes"` - FEAT_AES
54+
/// * `"aes"` - FEAT_AES & FEAT_PMULL
5555
/// * `"sha2"` - FEAT_SHA1 & FEAT_SHA256
5656
/// * `"sha3"` - FEAT_SHA512 & FEAT_SHA3
5757
/// * `"sm4"` - FEAT_SM3 & FEAT_SM4
@@ -70,7 +70,8 @@ features! {
7070
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] asimd: "neon";
7171
/// FEAT_AdvSIMD (Advanced SIMD/NEON)
7272
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] pmull: "pmull";
73-
/// FEAT_PMULL (Polynomial Multiply)
73+
implied by target_features: ["aes"];
74+
/// FEAT_PMULL (Polynomial Multiply) - Implied by `aes` target_feature
7475
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fp: "fp";
7576
implied by target_features: ["neon"];
7677
/// FEAT_FP (Floating point support) - Implied by `neon` target_feature
@@ -101,7 +102,7 @@ features! {
101102
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] flagm: "flagm";
102103
/// FEAT_FLAGM (flag manipulation instructions)
103104
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] ssbs: "ssbs";
104-
/// FEAT_SSBS (speculative store bypass safe)
105+
/// FEAT_SSBS & FEAT_SSBS2 (speculative store bypass safe)
105106
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] sb: "sb";
106107
/// FEAT_SB (speculation barrier)
107108
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] paca: "paca";
@@ -137,13 +138,13 @@ features! {
137138
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] bti: "bti";
138139
/// FEAT_BTI (Branch Target Identification)
139140
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] mte: "mte";
140-
/// FEAT_MTE (Memory Tagging Extension)
141+
/// FEAT_MTE & FEAT_MTE2 (Memory Tagging Extension)
141142
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] jsconv: "jsconv";
142143
/// FEAT_JSCVT (JavaScript float conversion instructions)
143144
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] fcma: "fcma";
144145
/// FEAT_FCMA (float complex number operations)
145146
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] aes: "aes";
146-
/// FEAT_AES (AES instructions)
147+
/// FEAT_AES (AES SIMD instructions) & FEAT_PMULL (PMULL{2}, 64-bit operand variants)
147148
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] sha2: "sha2";
148149
/// FEAT_SHA1 & FEAT_SHA256 (SHA1 & SHA2-256 instructions)
149150
@FEATURE: #[stable(feature = "simd_aarch64", since = "1.60.0")] sha3: "sha3";

crates/std_detect/src/detect/os/aarch64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub(crate) fn parse_system_registers(
9999
// supported, it also requires half-float support:
100100
enable_feature(Feature::asimd, fp && asimd && (!fphp | asimdhp));
101101
// SIMD extensions require SIMD support:
102-
enable_feature(Feature::aes, asimd && bits_shift(aa64isar0, 7, 4) >= 1);
102+
enable_feature(Feature::aes, asimd && bits_shift(aa64isar0, 7, 4) >= 2);
103103
let sha1 = bits_shift(aa64isar0, 11, 8) >= 1;
104104
let sha2 = bits_shift(aa64isar0, 15, 12) >= 1;
105105
enable_feature(Feature::sha2, asimd && sha1 && sha2);

crates/std_detect/src/detect/os/linux/aarch64.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ impl AtHwcap {
252252
let asimd = self.fp && self.asimd && (!self.fphp | self.asimdhp);
253253
enable_feature(Feature::asimd, asimd);
254254
// Cryptographic extensions require ASIMD
255-
enable_feature(Feature::aes, self.aes && asimd);
255+
// AES also covers FEAT_PMULL
256+
enable_feature(Feature::aes, self.aes && self.pmull && asimd);
256257
enable_feature(Feature::sha2, self.sha1 && self.sha2 && asimd);
257258
return value;
258259
}

crates/std_detect/src/detect/os/macos/aarch64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
8989
enable_feature(Feature::bf16, bf16);
9090
enable_feature(Feature::bti, bti);
9191
enable_feature(Feature::fcma, fcma);
92-
enable_feature(Feature::aes, aes);
92+
enable_feature(Feature::aes, aes && pmull);
9393
enable_feature(Feature::jsconv, jsconv);
9494
enable_feature(Feature::sha2, sha1 && sha2 && asimd);
9595
enable_feature(Feature::sha3, sha512 && sha3 && asimd);

0 commit comments

Comments
 (0)