Skip to content

Commit 3055fa9

Browse files
committed
rustc_target: RISC-V: feature addition batch 2
This commit adds unprivileged ratified extensions that are either dicoverable from the `riscv_hwprobe` syscall of the Linux kernel (as of version 6.14) plus 1 minus 2 extensions. Plus 1: * "B" This is a combination of "Zba", "Zbb" and "Zbs". Note: Although not required by the RISC-V specification, it is convenient to imply "B" from its three members (will be implemented in LLVM 21/22) but this is not yet implemented in Rust due to current implication handling. It still implies three members *from* "B". Minus 2: * "Zcf" (target_arch = "riscv32" only) This is the compression instruction subset corresponding "F". This is implied from RV32 + "C" + "F" but this complex handling is not yet supported by Rust's feature handling. * "Zcd" This is the compression instruction subset corresponding "D". This is implied from "C" + "D" but this complex handling is not yet supported by Rust's feature handling. Notes: * Because this commit adds the "Zca" extension (an integer subset of the "C" extension), the "C" extension is modified to imply "Zca". * The "Supm" extension requires LLVM 20 yet it should not affect codegen on LLVM 19 because this extension does not specify any mechanism to control pointer masking (just tells the availability from the user mode and *some* way to control pointer masking like a system call).
1 parent c211076 commit 3055fa9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
272272
("aarch64", "fpmr") => None, // only existed in 18
273273
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
274274
// Filter out features that are not supported by the current LLVM version
275+
("riscv32" | "riscv64", "supm") if get_version().0 < 20 => None,
275276
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
276277
// Enable the evex512 target feature if an avx512 target feature is enabled.
277278
("x86", s) if s.starts_with("avx512") => {

compiler/rustc_target/src/target_features.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
491491
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
492492
// tidy-alphabetical-start
493493
("a", Stable, &["zaamo", "zalrsc"]),
494-
("c", Stable, &[]),
494+
("b", Unstable(sym::riscv_target_feature), &["zba", "zbb", "zbs"]),
495+
("c", Stable, &["zca"]),
495496
("d", Unstable(sym::riscv_target_feature), &["f"]),
496497
("e", Unstable(sym::riscv_target_feature), &[]),
497498
("f", Unstable(sym::riscv_target_feature), &["zicsr"]),
@@ -502,6 +503,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
502503
),
503504
("m", Stable, &[]),
504505
("relax", Unstable(sym::riscv_target_feature), &[]),
506+
("supm", Unstable(sym::riscv_target_feature), &[]),
505507
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
506508
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
507509
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
@@ -520,17 +522,25 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
520522
("zbkc", Stable, &[]),
521523
("zbkx", Stable, &[]),
522524
("zbs", Stable, &[]),
525+
("zca", Unstable(sym::riscv_target_feature), &[]),
526+
("zcb", Unstable(sym::riscv_target_feature), &["zca"]),
527+
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
523528
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
529+
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
524530
("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
525531
("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
526532
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
527533
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
528534
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
535+
("zicboz", Unstable(sym::riscv_target_feature), &[]),
529536
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
537+
("zicond", Unstable(sym::riscv_target_feature), &[]),
530538
("zicsr", Unstable(sym::riscv_target_feature), &[]),
531539
("zifencei", Unstable(sym::riscv_target_feature), &[]),
540+
("zihintntl", Unstable(sym::riscv_target_feature), &[]),
532541
("zihintpause", Unstable(sym::riscv_target_feature), &[]),
533542
("zihpm", Unstable(sym::riscv_target_feature), &["zicsr"]),
543+
("zimop", Unstable(sym::riscv_target_feature), &[]),
534544
("zk", Stable, &["zkn", "zkr", "zkt"]),
535545
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
536546
("zknd", Stable, &[]),
@@ -541,6 +551,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
541551
("zksed", Stable, &[]),
542552
("zksh", Stable, &[]),
543553
("zkt", Stable, &[]),
554+
("ztso", Unstable(sym::riscv_target_feature), &[]),
544555
("zvbb", Unstable(sym::riscv_target_feature), &["zvkb"]),
545556
("zvbc", Unstable(sym::riscv_target_feature), &["zve64x"]),
546557
("zve32f", Unstable(sym::riscv_target_feature), &["zve32x", "f"]),

tests/ui/check-cfg/target_feature.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
4949
`avxvnni`
5050
`avxvnniint16`
5151
`avxvnniint8`
52+
`b`
5253
`backchain`
5354
`bf16`
5455
`bmi1`
@@ -233,6 +234,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
233234
`ssve-fp8dot2`
234235
`ssve-fp8dot4`
235236
`ssve-fp8fma`
237+
`supm`
236238
`sve`
237239
`sve-b16b16`
238240
`sve2`
@@ -318,17 +320,25 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
318320
`zbkc`
319321
`zbkx`
320322
`zbs`
323+
`zca`
324+
`zcb`
325+
`zcmop`
321326
`zdinx`
327+
`zfa`
322328
`zfh`
323329
`zfhmin`
324330
`zfinx`
325331
`zhinx`
326332
`zhinxmin`
333+
`zicboz`
327334
`zicntr`
335+
`zicond`
328336
`zicsr`
329337
`zifencei`
338+
`zihintntl`
330339
`zihintpause`
331340
`zihpm`
341+
`zimop`
332342
`zk`
333343
`zkn`
334344
`zknd`
@@ -339,6 +349,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
339349
`zksed`
340350
`zksh`
341351
`zkt`
352+
`ztso`
342353
`zvbb`
343354
`zvbc`
344355
`zve32f`

0 commit comments

Comments
 (0)