Skip to content

Commit 316a79f

Browse files
committed
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 + ABI handling. It excludes "E" and all floating point-arithmetic extensions. "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!()`.
1 parent 2ebb126 commit 316a79f

File tree

3 files changed

+51
-53
lines changed

3 files changed

+51
-53
lines changed

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
@@ -589,7 +589,7 @@ const NVPTX_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
589589
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
590590
// tidy-alphabetical-start
591591
("a", Stable, &["zaamo", "zalrsc"]),
592-
("b", Unstable(sym::riscv_target_feature), &["zba", "zbb", "zbs"]),
592+
("b", Stable, &["zba", "zbb", "zbs"]),
593593
("c", Stable, &["zca"]),
594594
("d", Unstable(sym::riscv_target_feature), &["f"]),
595595
("e", Unstable(sym::riscv_target_feature), &[]),
@@ -647,24 +647,24 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
647647
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
648648
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
649649
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
650-
("za64rs", Unstable(sym::riscv_target_feature), &["za128rs"]), // Za64rs ⊃ Za128rs
651-
("za128rs", Unstable(sym::riscv_target_feature), &[]),
652-
("zaamo", Unstable(sym::riscv_target_feature), &[]),
653-
("zabha", Unstable(sym::riscv_target_feature), &["zaamo"]),
654-
("zacas", Unstable(sym::riscv_target_feature), &["zaamo"]),
655-
("zalrsc", Unstable(sym::riscv_target_feature), &[]),
656-
("zama16b", Unstable(sym::riscv_target_feature), &[]),
657-
("zawrs", Unstable(sym::riscv_target_feature), &[]),
650+
("za64rs", Stable, &["za128rs"]), // Za64rs ⊃ Za128rs
651+
("za128rs", Stable, &[]),
652+
("zaamo", Stable, &[]),
653+
("zabha", Stable, &["zaamo"]),
654+
("zacas", Stable, &["zaamo"]),
655+
("zalrsc", Stable, &[]),
656+
("zama16b", Stable, &[]),
657+
("zawrs", Stable, &[]),
658658
("zba", Stable, &[]),
659659
("zbb", Stable, &[]),
660660
("zbc", Stable, &["zbkc"]), // Zbc ⊃ Zbkc
661661
("zbkb", Stable, &[]),
662662
("zbkc", Stable, &[]),
663663
("zbkx", Stable, &[]),
664664
("zbs", Stable, &[]),
665-
("zca", Unstable(sym::riscv_target_feature), &[]),
666-
("zcb", Unstable(sym::riscv_target_feature), &["zca"]),
667-
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
665+
("zca", Stable, &[]),
666+
("zcb", Stable, &["zca"]),
667+
("zcmop", Stable, &["zca"]),
668668
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
669669
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
670670
("zfbfmin", Unstable(sym::riscv_target_feature), &["f"]), // and a subset of Zfhmin
@@ -673,22 +673,22 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
673673
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
674674
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
675675
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
676-
("zic64b", Unstable(sym::riscv_target_feature), &[]),
677-
("zicbom", Unstable(sym::riscv_target_feature), &[]),
678-
("zicbop", Unstable(sym::riscv_target_feature), &[]),
679-
("zicboz", Unstable(sym::riscv_target_feature), &[]),
680-
("ziccamoa", Unstable(sym::riscv_target_feature), &[]),
681-
("ziccif", Unstable(sym::riscv_target_feature), &[]),
682-
("zicclsm", Unstable(sym::riscv_target_feature), &[]),
683-
("ziccrse", Unstable(sym::riscv_target_feature), &[]),
684-
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
685-
("zicond", Unstable(sym::riscv_target_feature), &[]),
686-
("zicsr", Unstable(sym::riscv_target_feature), &[]),
687-
("zifencei", Unstable(sym::riscv_target_feature), &[]),
688-
("zihintntl", Unstable(sym::riscv_target_feature), &[]),
689-
("zihintpause", Unstable(sym::riscv_target_feature), &[]),
690-
("zihpm", Unstable(sym::riscv_target_feature), &["zicsr"]),
691-
("zimop", Unstable(sym::riscv_target_feature), &[]),
676+
("zic64b", Stable, &[]),
677+
("zicbom", Stable, &[]),
678+
("zicbop", Stable, &[]),
679+
("zicboz", Stable, &[]),
680+
("ziccamoa", Stable, &[]),
681+
("ziccif", Stable, &[]),
682+
("zicclsm", Stable, &[]),
683+
("ziccrse", Stable, &[]),
684+
("zicntr", Stable, &["zicsr"]),
685+
("zicond", Stable, &[]),
686+
("zicsr", Stable, &[]),
687+
("zifencei", Stable, &[]),
688+
("zihintntl", Stable, &[]),
689+
("zihintpause", Stable, &[]),
690+
("zihpm", Stable, &["zicsr"]),
691+
("zimop", Stable, &[]),
692692
("zk", Stable, &["zkn", "zkr", "zkt"]),
693693
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
694694
("zknd", Stable, &[]),
@@ -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
@@ -194,47 +194,47 @@ features! {
194194
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] unaligned_vector_mem: "unaligned-vector-mem";
195195
/// Has reasonably performant unaligned vector
196196
197-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicsr: "zicsr";
197+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicsr: "zicsr";
198198
/// "Zicsr" Extension for Control and Status Register (CSR) Instructions
199-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicntr: "zicntr";
199+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicntr: "zicntr";
200200
/// "Zicntr" Extension for Base Counters and Timers
201-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zihpm: "zihpm";
201+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zihpm: "zihpm";
202202
/// "Zihpm" Extension for Hardware Performance Counters
203-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zifencei: "zifencei";
203+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zifencei: "zifencei";
204204
/// "Zifencei" Extension for Instruction-Fetch Fence
205205
206-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zihintntl: "zihintntl";
206+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zihintntl: "zihintntl";
207207
/// "Zihintntl" Extension for Non-Temporal Locality Hints
208-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zihintpause: "zihintpause";
208+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zihintpause: "zihintpause";
209209
/// "Zihintpause" Extension for Pause Hint
210-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zimop: "zimop";
210+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zimop: "zimop";
211211
/// "Zimop" Extension for May-Be-Operations
212-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicbom: "zicbom";
212+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicbom: "zicbom";
213213
/// "Zicbom" Extension for Cache-Block Management Instructions
214-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicboz: "zicboz";
214+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicboz: "zicboz";
215215
/// "Zicboz" Extension for Cache-Block Zero Instruction
216-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zicond: "zicond";
216+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zicond: "zicond";
217217
/// "Zicond" Extension for Integer Conditional Operations
218218
219219
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] m: "m";
220220
/// "M" Extension for Integer Multiplication and Division
221221
222222
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] a: "a";
223223
/// "A" Extension for Atomic Instructions
224-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zalrsc: "zalrsc";
224+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zalrsc: "zalrsc";
225225
/// "Zalrsc" Extension for Load-Reserved/Store-Conditional Instructions
226-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zaamo: "zaamo";
226+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zaamo: "zaamo";
227227
/// "Zaamo" Extension for Atomic Memory Operations
228-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zawrs: "zawrs";
228+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zawrs: "zawrs";
229229
/// "Zawrs" Extension for Wait-on-Reservation-Set Instructions
230-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zabha: "zabha";
230+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zabha: "zabha";
231231
/// "Zabha" Extension for Byte and Halfword Atomic Memory Operations
232-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zacas: "zacas";
232+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zacas: "zacas";
233233
/// "Zacas" Extension for Atomic Compare-and-Swap (CAS) Instructions
234234
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zam: "zam";
235235
without cfg check: true;
236236
/// "Zam" Extension for Misaligned Atomics
237-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] ztso: "ztso";
237+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] ztso: "ztso";
238238
/// "Ztso" Extension for Total Store Ordering
239239
240240
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] f: "f";
@@ -264,20 +264,20 @@ features! {
264264
265265
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] c: "c";
266266
/// "C" Extension for Compressed Instructions
267-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zca: "zca";
267+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zca: "zca";
268268
/// "Zca" Compressed Instructions excluding Floating-Point Loads/Stores
269269
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcf: "zcf";
270270
without cfg check: true;
271271
/// "Zcf" Compressed Instructions for Single-Precision Floating-Point Loads/Stores on RV32
272272
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcd: "zcd";
273273
without cfg check: true;
274274
/// "Zcd" Compressed Instructions for Double-Precision Floating-Point Loads/Stores
275-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcb: "zcb";
275+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zcb: "zcb";
276276
/// "Zcb" Simple Code-size Saving Compressed Instructions
277-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zcmop: "zcmop";
277+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] zcmop: "zcmop";
278278
/// "Zcmop" Extension for Compressed May-Be-Operations
279279
280-
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] b: "b";
280+
@FEATURE: #[stable(feature = "riscv_ratified_v2", since = "CURRENT_RUSTC_VERSION")] b: "b";
281281
/// "B" Extension for Bit Manipulation
282282
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] zba: "zba";
283283
/// "Zba" Extension for Address Generation

0 commit comments

Comments
 (0)