Skip to content

Commit e337275

Browse files
committed
RISC-V: Add virtual target feature: zkne_or_zknd
Because some AES key scheduling instructions require *either* Zkne or Zknd extension, we must have a target feature to represent `(Zkne || Zknd)`. This commit adds (perma-unstable) target feature to the RISC-V architecture: `zkne_or_zknd` for this purpose. Helped-by: sayantn <sayantn05@gmail.com>
1 parent ed0006a commit e337275

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
262262
"power8-crypto" => Some(LLVMFeature::new("crypto")),
263263
s => Some(LLVMFeature::new(s)),
264264
},
265+
Arch::RiscV32 | Arch::RiscV64 => match s {
266+
// Filter out Rust-specific *virtual* target feature
267+
"zkne_or_zknd" => None,
268+
s => Some(LLVMFeature::new(s)),
269+
},
265270
Arch::Sparc | Arch::Sparc64 => match s {
266271
"leoncasa" => Some(LLVMFeature::new("hasleoncasa")),
267272
s => Some(LLVMFeature::new(s)),

compiler/rustc_target/src/target_features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
690690
("zimop", Unstable(sym::riscv_target_feature), &[]),
691691
("zk", Stable, &["zkn", "zkr", "zkt"]),
692692
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
693-
("zknd", Stable, &[]),
694-
("zkne", Stable, &[]),
693+
("zknd", Stable, &["zkne_or_zknd"]),
694+
("zkne", Stable, &["zkne_or_zknd"]),
695+
("zkne_or_zknd", Unstable(sym::riscv_target_feature), &[]), // Not an extension
695696
("zknh", Stable, &[]),
696697
("zkr", Stable, &[]),
697698
("zks", Stable, &["zbkb", "zbkc", "zbkx", "zksed", "zksh"]),

tests/ui/check-cfg/target_feature.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
423423
`zkn`
424424
`zknd`
425425
`zkne`
426+
`zkne_or_zknd`
426427
`zknh`
427428
`zkr`
428429
`zks`

0 commit comments

Comments
 (0)