Skip to content

Commit 00f49d2

Browse files
committed
Auto merge of #145948 - a4lg:riscv-stabilize-target-features-v2, r=Amanieu
Stabilize 29 RISC-V target features (`riscv_ratified_v2`) This commit stabilizes RISC-V target features with following constraints: * Describes a ratified extension. * Implemented on Rust 1.88.0 or before. Waiting for four+ version cycles seems sufficient. * Does not disrupt current rustc's target feature (cf. #140570) + ABI (cf. #132618) handling. It excludes `E` and all floating point-arithmetic extensions. The `Zfinx` family does not involve floating point registers but not stabilizing for now to avoid possible confusion between the `F` extension family. * Not vector-related (floating point and integer). While integer vector subsets should not cause any ABI issues (as they don't use ABI-dependent floating point registers), we need to discuss before stabilizing them. * Supported by the lowest LLVM version supported by rustc (LLVM 20). List of target features to be stabilized: 1. `b` 2. `za64rs` (no-RT) 3. `za128rs` (no-RT) 4. `zaamo` 5. `zabha` 6. `zacas` 7. `zalrsc` 8. `zama16b` (no-RT) 9. `zawrs` 10. `zca` 11. `zcb` 12. `zcmop` 13. `zic64b` (no-RT) 14. `zicbom` 15. `zicbop` (no-RT) 16. `zicboz` 17. `ziccamoa` (no-RT) 18. `ziccif` (no-RT) 19. `zicclsm` (no-RT) 20. `ziccrse` (no-RT) 21. `zicntr` 22. `zicond` 23. `zicsr` 24. `zifencei` 25. `zihintntl` 26. `zihintpause` 27. `zihpm` 28. `zimop` 29. `ztso` Of which, 20 of them (29 minus 9 "no-RT" target features) support runtime detection through `std::arch::is_riscv_feature_detected!()`. Corresponding PR for the Reference: rust-lang/reference#1987
2 parents 50d5940 + 316a79f commit 00f49d2

3 files changed

Lines changed: 51 additions & 53 deletions

File tree

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,12 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
330330
let mut e_flags: u32 = 0x0;
331331

332332
// Check if compression is enabled
333-
// `unstable_target_features` is used here because "zca" is gated behind riscv_target_feature.
334-
if sess.unstable_target_features.contains(&sym::zca) {
333+
if sess.target_features.contains(&sym::zca) {
335334
e_flags |= elf::EF_RISCV_RVC;
336335
}
337336

338337
// Check if RVTSO is enabled
339-
// `unstable_target_features` is used here because "ztso" is gated behind riscv_target_feature.
340-
if sess.unstable_target_features.contains(&sym::ztso) {
338+
if sess.target_features.contains(&sym::ztso) {
341339
e_flags |= elf::EF_RISCV_TSO;
342340
}
343341

compiler/rustc_target/src/target_features.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ const NVPTX_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
588588
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
589589
// tidy-alphabetical-start
590590
("a", Stable, &["zaamo", "zalrsc"]),
591-
("b", Unstable(sym::riscv_target_feature), &["zba", "zbb", "zbs"]),
591+
("b", Stable, &["zba", "zbb", "zbs"]),
592592
("c", Stable, &["zca"]),
593593
("d", Unstable(sym::riscv_target_feature), &["f"]),
594594
("e", Unstable(sym::riscv_target_feature), &[]),
@@ -646,24 +646,24 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
646646
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
647647
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
648648
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
649-
("za64rs", Unstable(sym::riscv_target_feature), &["za128rs"]), // Za64rs ⊃ Za128rs
650-
("za128rs", Unstable(sym::riscv_target_feature), &[]),
651-
("zaamo", Unstable(sym::riscv_target_feature), &[]),
652-
("zabha", Unstable(sym::riscv_target_feature), &["zaamo"]),
653-
("zacas", Unstable(sym::riscv_target_feature), &["zaamo"]),
654-
("zalrsc", Unstable(sym::riscv_target_feature), &[]),
655-
("zama16b", Unstable(sym::riscv_target_feature), &[]),
656-
("zawrs", Unstable(sym::riscv_target_feature), &[]),
649+
("za64rs", Stable, &["za128rs"]), // Za64rs ⊃ Za128rs
650+
("za128rs", Stable, &[]),
651+
("zaamo", Stable, &[]),
652+
("zabha", Stable, &["zaamo"]),
653+
("zacas", Stable, &["zaamo"]),
654+
("zalrsc", Stable, &[]),
655+
("zama16b", Stable, &[]),
656+
("zawrs", Stable, &[]),
657657
("zba", Stable, &[]),
658658
("zbb", Stable, &[]),
659659
("zbc", Stable, &["zbkc"]), // Zbc ⊃ Zbkc
660660
("zbkb", Stable, &[]),
661661
("zbkc", Stable, &[]),
662662
("zbkx", Stable, &[]),
663663
("zbs", Stable, &[]),
664-
("zca", Unstable(sym::riscv_target_feature), &[]),
665-
("zcb", Unstable(sym::riscv_target_feature), &["zca"]),
666-
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
664+
("zca", Stable, &[]),
665+
("zcb", Stable, &["zca"]),
666+
("zcmop", Stable, &["zca"]),
667667
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
668668
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
669669
("zfbfmin", Unstable(sym::riscv_target_feature), &["f"]), // and a subset of Zfhmin
@@ -672,22 +672,22 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
672672
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
673673
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
674674
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
675-
("zic64b", Unstable(sym::riscv_target_feature), &[]),
676-
("zicbom", Unstable(sym::riscv_target_feature), &[]),
677-
("zicbop", Unstable(sym::riscv_target_feature), &[]),
678-
("zicboz", Unstable(sym::riscv_target_feature), &[]),
679-
("ziccamoa", Unstable(sym::riscv_target_feature), &[]),
680-
("ziccif", Unstable(sym::riscv_target_feature), &[]),
681-
("zicclsm", Unstable(sym::riscv_target_feature), &[]),
682-
("ziccrse", Unstable(sym::riscv_target_feature), &[]),
683-
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
684-
("zicond", Unstable(sym::riscv_target_feature), &[]),
685-
("zicsr", Unstable(sym::riscv_target_feature), &[]),
686-
("zifencei", Unstable(sym::riscv_target_feature), &[]),
687-
("zihintntl", Unstable(sym::riscv_target_feature), &[]),
688-
("zihintpause", Unstable(sym::riscv_target_feature), &[]),
689-
("zihpm", Unstable(sym::riscv_target_feature), &["zicsr"]),
690-
("zimop", Unstable(sym::riscv_target_feature), &[]),
675+
("zic64b", Stable, &[]),
676+
("zicbom", Stable, &[]),
677+
("zicbop", Stable, &[]),
678+
("zicboz", Stable, &[]),
679+
("ziccamoa", Stable, &[]),
680+
("ziccif", Stable, &[]),
681+
("zicclsm", Stable, &[]),
682+
("ziccrse", Stable, &[]),
683+
("zicntr", Stable, &["zicsr"]),
684+
("zicond", Stable, &[]),
685+
("zicsr", Stable, &[]),
686+
("zifencei", Stable, &[]),
687+
("zihintntl", Stable, &[]),
688+
("zihintpause", Stable, &[]),
689+
("zihpm", Stable, &["zicsr"]),
690+
("zimop", Stable, &[]),
691691
("zk", Stable, &["zkn", "zkr", "zkt"]),
692692
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
693693
("zknd", Stable, &["zkne_or_zknd"]),
@@ -699,7 +699,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
699699
("zksed", Stable, &[]),
700700
("zksh", Stable, &[]),
701701
("zkt", Stable, &[]),
702-
("ztso", Unstable(sym::riscv_target_feature), &[]),
702+
("ztso", Stable, &[]),
703703
("zvbb", Unstable(sym::riscv_target_feature), &["zvkb"]), // Zvbb ⊃ Zvkb
704704
("zvbc", Unstable(sym::riscv_target_feature), &["zve64x"]),
705705
("zve32f", Unstable(sym::riscv_target_feature), &["zve32x", "f"]),

library/std_detect/src/detect/arch/riscv.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,47 +196,47 @@ features! {
196196
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] unaligned_vector_mem: "unaligned-vector-mem";
197197
/// Has reasonably performant unaligned vector
198198
199-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicsr: "zicsr";
199+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicsr: "zicsr";
200200
/// "Zicsr" Extension for Control and Status Register (CSR) Instructions
201-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicntr: "zicntr";
201+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicntr: "zicntr";
202202
/// "Zicntr" Extension for Base Counters and Timers
203-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zihpm: "zihpm";
203+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zihpm: "zihpm";
204204
/// "Zihpm" Extension for Hardware Performance Counters
205-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zifencei: "zifencei";
205+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zifencei: "zifencei";
206206
/// "Zifencei" Extension for Instruction-Fetch Fence
207207
208-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zihintntl: "zihintntl";
208+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zihintntl: "zihintntl";
209209
/// "Zihintntl" Extension for Non-Temporal Locality Hints
210-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zihintpause: "zihintpause";
210+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zihintpause: "zihintpause";
211211
/// "Zihintpause" Extension for Pause Hint
212-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zimop: "zimop";
212+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zimop: "zimop";
213213
/// "Zimop" Extension for May-Be-Operations
214-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicbom: "zicbom";
214+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicbom: "zicbom";
215215
/// "Zicbom" Extension for Cache-Block Management Instructions
216-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicboz: "zicboz";
216+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicboz: "zicboz";
217217
/// "Zicboz" Extension for Cache-Block Zero Instruction
218-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicond: "zicond";
218+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicond: "zicond";
219219
/// "Zicond" Extension for Integer Conditional Operations
220220
221221
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] m: "m";
222222
/// "M" Extension for Integer Multiplication and Division
223223
224224
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] a: "a";
225225
/// "A" Extension for Atomic Instructions
226-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zalrsc: "zalrsc";
226+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zalrsc: "zalrsc";
227227
/// "Zalrsc" Extension for Load-Reserved/Store-Conditional Instructions
228-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zaamo: "zaamo";
228+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zaamo: "zaamo";
229229
/// "Zaamo" Extension for Atomic Memory Operations
230-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zawrs: "zawrs";
230+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zawrs: "zawrs";
231231
/// "Zawrs" Extension for Wait-on-Reservation-Set Instructions
232-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zabha: "zabha";
232+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zabha: "zabha";
233233
/// "Zabha" Extension for Byte and Halfword Atomic Memory Operations
234-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zacas: "zacas";
234+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zacas: "zacas";
235235
/// "Zacas" Extension for Atomic Compare-and-Swap (CAS) Instructions
236236
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zam: "zam";
237237
without cfg check: true;
238238
/// "Zam" Extension for Misaligned Atomics
239-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] ztso: "ztso";
239+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] ztso: "ztso";
240240
/// "Ztso" Extension for Total Store Ordering
241241
242242
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] f: "f";
@@ -266,20 +266,20 @@ features! {
266266
267267
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] c: "c";
268268
/// "C" Extension for Compressed Instructions
269-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zca: "zca";
269+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zca: "zca";
270270
/// "Zca" Compressed Instructions excluding Floating-Point Loads/Stores
271271
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcf: "zcf";
272272
without cfg check: true;
273273
/// "Zcf" Compressed Instructions for Single-Precision Floating-Point Loads/Stores on RV32
274274
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcd: "zcd";
275275
without cfg check: true;
276276
/// "Zcd" Compressed Instructions for Double-Precision Floating-Point Loads/Stores
277-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcb: "zcb";
277+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zcb: "zcb";
278278
/// "Zcb" Simple Code-size Saving Compressed Instructions
279-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcmop: "zcmop";
279+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zcmop: "zcmop";
280280
/// "Zcmop" Extension for Compressed May-Be-Operations
281281
282-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] b: "b";
282+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] b: "b";
283283
/// "B" Extension for Bit Manipulation
284284
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zba: "zba";
285285
/// "Zba" Extension for Address Generation

0 commit comments

Comments
 (0)