Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 238a324

Browse files
authoredFeb 25, 2025
Unrolled build for rust-lang#137417
Rollup merge of rust-lang#137417 - taiki-e:riscv-atomic, r=Amanieu rustc_target: Add more RISC-V atomic-related features This is a continuation of rust-lang#130877 and adds a few target features, including `zacas`, which was experimental in LLVM 19 and marked non-experimental in LLVM 20. This adds the following target features to unstable riscv_target_feature: - `za64rs` (Za64rs Extension 1.0): Reservation Set Size of at Most 64 Bytes ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0-rc2/llvm/lib/Target/RISCV/RISCVFeatures.td#L227-L228), [available since LLVM 18](llvm/llvm-project@8649328)) - `za128rs` (Za128rs Extension 1.0): Reservation Set Size of at Most 128 Bytes ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0-rc2/llvm/lib/Target/RISCV/RISCVFeatures.td#L230-L231), [available since LLVM 18](llvm/llvm-project@8649328)) - IIUC, `za*rs` can be referenced when implementing helpers to reduce contention in synchronization primitives, like [`crossbeam_utils::CachePadded`](https://docs.rs/crossbeam-utils/latest/crossbeam_utils/struct.CachePadded.html). (relevant discussion: riscv/riscv-profiles#79) - `zacas` (Zacas Extension 1.0): Atomic Compare-And-Swap Instructions (`amocas.{w,d,q}{,.aq,.rl,.aqrl}` and `amocas.{b,h}{,.aq,.rl,.aqrl}` when `zabha` is also enabled) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0-rc2/llvm/lib/Target/RISCV/RISCVFeatures.td#L240-L243), [available as non-experimental since LLVM 20](llvm/llvm-project@614aeda)) - This implies `zaamo`. - This is used to optimize CAS in existing atomics and/or implement 64-bit/128-bit atomics on riscv32/riscv64 (e.g., taiki-e/portable-atomic#173). - Note that [LLVM does not automatically use this instruction for 64-bit/128-bit atomics on riscv32/riscv64 even if this feature is enabled, because doing it changes the ABI](https://github.com/llvm/llvm-project/blob/876174ffd7533dc220f94721173bb767b659fa7f/llvm/docs/RISCVUsage.rst#riscv-zacas-note). (If the ability to do that is provided by LLVM in the future, it should probably be controlled by another ABI feature similar to `forced-atomics`.) - `zama16b` (Zama16b Extension 1.0): Atomic 16-byte misaligned loads, stores and AMOs ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0-rc2/llvm/lib/Target/RISCV/RISCVFeatures.td#L255-L256), [available since LLVM 19](llvm/llvm-project@b090569)) - IIUC, unlike AArch64 FEAT_LSE2 which also makes 16-byte aligned ldp ({i,u}128 load) atomic, this extension only affects instructions that already considered atomic if they were naturally aligned. i.e., fld (f64 load) on riscv32 would not be atomic with or without this extension ([relevant QEMU code](https://github.com/qemu/qemu/blob/b69801dd6b1eb4d107f7c2f643adf0a4e3ec9124/target/riscv/insn_trans/trans_rvd.c.inc#L50-L62)). - `zawrs` (Zawrs Extension 1.0): Wait on Reservation Set (`wrs.nto` and `wrs.sto`) ([definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-20.1.0-rc2/llvm/lib/Target/RISCV/RISCVFeatures.td#L258), [available as non-experimental since LLVM 17](llvm/llvm-project@d41a73a)) - This is used to optimize synchronization primitives (e.g., Linux uses this for spinlocks (torvalds/linux@b8ddb0d)). Btw, the question of whether `zaamo` is implied by `zabha` or not, which was discussed in rust-lang#130877, has been resolved in LLVM 20, since LLVM now treats `zaamo` as implied by `zabha`/`zacas` (llvm/llvm-project#115694), just like GCC and rustc. r? `@Amanieu` `@rustbot` label +O-riscv +A-target-feature
2 parents 7d8c6e7 + a343dcb commit 238a324

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
 

‎compiler/rustc_codegen_llvm/src/llvm_util.rs

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
281281
("riscv32" | "riscv64", "zaamo") if get_version().0 < 19 => None,
282282
("riscv32" | "riscv64", "zabha") if get_version().0 < 19 => None,
283283
("riscv32" | "riscv64", "zalrsc") if get_version().0 < 19 => None,
284+
("riscv32" | "riscv64", "zama16b") if get_version().0 < 19 => None,
285+
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
284286
// Enable the evex512 target feature if an avx512 target feature is enabled.
285287
("x86", s) if s.starts_with("avx512") => {
286288
Some(LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512")))

‎compiler/rustc_target/src/target_features.rs

+5
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,14 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
497497
("relax", Unstable(sym::riscv_target_feature), &[]),
498498
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
499499
("v", Unstable(sym::riscv_target_feature), &[]),
500+
("za128rs", Unstable(sym::riscv_target_feature), &[]),
501+
("za64rs", Unstable(sym::riscv_target_feature), &[]),
500502
("zaamo", Unstable(sym::riscv_target_feature), &[]),
501503
("zabha", Unstable(sym::riscv_target_feature), &["zaamo"]),
504+
("zacas", Unstable(sym::riscv_target_feature), &["zaamo"]),
502505
("zalrsc", Unstable(sym::riscv_target_feature), &[]),
506+
("zama16b", Unstable(sym::riscv_target_feature), &[]),
507+
("zawrs", Unstable(sym::riscv_target_feature), &[]),
503508
("zba", Stable, &[]),
504509
("zbb", Stable, &[]),
505510
("zbc", Stable, &[]),

‎tests/ui/check-cfg/target_feature.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,14 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
290290
`xsavec`
291291
`xsaveopt`
292292
`xsaves`
293+
`za128rs`
294+
`za64rs`
293295
`zaamo`
294296
`zabha`
297+
`zacas`
295298
`zalrsc`
299+
`zama16b`
300+
`zawrs`
296301
`zba`
297302
`zbb`
298303
`zbc`

0 commit comments

Comments
 (0)
Failed to load comments.