rust/compiler
Michael Goulet 828a3a41b3
Rollup merge of #137417 - taiki-e:riscv-atomic, r=Amanieu
rustc_target: Add more RISC-V atomic-related features

This is a continuation of https://github.com/rust-lang/rust/pull/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](8649328060))
- `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](8649328060))
  - 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: https://github.com/riscv/riscv-profiles/issues/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](614aeda93b))
  - 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., https://github.com/taiki-e/portable-atomic/pull/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](876174ffd7/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](b090569685))
  - 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](b69801dd6b/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](d41a73aa94))
  - This is used to optimize synchronization primitives (e.g., Linux uses this for spinlocks (b8ddb0df30)).

Btw, the question of whether `zaamo` is implied by `zabha` or not, which was discussed in https://github.com/rust-lang/rust/pull/130877, has been resolved in LLVM 20, since LLVM now treats `zaamo` as implied by `zabha`/`zacas` (https://github.com/llvm/llvm-project/pull/115694), just like GCC and rustc.

r? `@Amanieu`

`@rustbot` label +O-riscv +A-target-feature
2025-02-24 19:21:47 -05:00
..
rustc Fix overcapturing, unsafe extern blocks, and new unsafe ops 2025-02-22 00:01:48 +00:00
rustc_abi Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_arena Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ast Auto merge of #137420 - matthiaskrgr:rollup-rr0q37f, r=matthiaskrgr 2025-02-22 13:32:44 +00:00
rustc_ast_ir Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ast_lowering Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_ast_passes Rollup merge of #137435 - estebank:match-arm-2, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_ast_pretty Rollup merge of #137423 - Urgau:imprv-pretty-hir, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_attr_data_structures Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_attr_parsing Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_baked_icu_data Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_borrowck Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_builtin_macros Rollup merge of #135501 - tgross35:stdlib-dependencies-private, r=bjorn3 2025-02-23 00:16:18 +01:00
rustc_codegen_cranelift Rollup merge of #137505 - tgross35:builtins-cannot-call-error, r=compiler-errors 2025-02-24 02:11:38 -05:00
rustc_codegen_gcc Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35 2025-02-23 14:30:25 -05:00
rustc_codegen_llvm Rollup merge of #137417 - taiki-e:riscv-atomic, r=Amanieu 2025-02-24 19:21:47 -05:00
rustc_codegen_ssa Rollup merge of #137505 - tgross35:builtins-cannot-call-error, r=compiler-errors 2025-02-24 02:11:38 -05:00
rustc_const_eval Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_data_structures Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_driver Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_driver_impl Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_error_codes Consolidate and rework CoercePointee and DispatchFromDyn errors 2025-02-24 19:34:54 +00:00
rustc_error_messages Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_errors Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril 2025-02-22 11:36:43 +01:00
rustc_expand Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_feature Remove dyn_compatible_for_dispatch 2025-02-24 18:48:40 +00:00
rustc_fluent_macro Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_fs_util Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_graphviz Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_hashes Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_hir Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_hir_analysis Rollup merge of #137289 - compiler-errors:coerce-unsized-errors, r=oli-obk 2025-02-24 19:21:45 -05:00
rustc_hir_pretty Rollup merge of #137423 - Urgau:imprv-pretty-hir, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_hir_typeck Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_incremental Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk 2025-02-23 00:16:19 +01:00
rustc_index Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_index_macros Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_infer Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_interface Auto merge of #137420 - matthiaskrgr:rollup-rr0q37f, r=matthiaskrgr 2025-02-22 13:32:44 +00:00
rustc_lexer Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_lint Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrum 2025-02-23 11:12:56 +00:00
rustc_lint_defs Fix binding mode problems 2025-02-22 00:13:19 +00:00
rustc_llvm Auto merge of #137271 - nikic:gep-nuw-2, r=scottmcm 2025-02-24 03:06:16 +00:00
rustc_log Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_macros Fix binding mode problems 2025-02-22 00:13:19 +00:00
rustc_metadata Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_middle Fix some use items that import more than necessary. 2025-02-24 09:30:42 +11:00
rustc_mir_build Fix some use items that import more than necessary. 2025-02-24 09:30:42 +11:00
rustc_mir_dataflow Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_mir_transform Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_monomorphize Auto merge of #137225 - RalfJung:vectorcall, r=nnethercote 2025-02-23 14:12:38 +00:00
rustc_next_trait_solver Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril 2025-02-22 11:36:43 +01:00
rustc_parse Rollup merge of #137435 - estebank:match-arm-2, r=compiler-errors 2025-02-23 02:44:19 -05:00
rustc_parse_format Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_passes Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk 2025-02-23 00:16:19 +01:00
rustc_pattern_analysis Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_privacy Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk 2025-02-23 00:16:19 +01:00
rustc_query_impl Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_query_system Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_resolve Fix binding mode problems 2025-02-22 00:13:19 +00:00
rustc_sanitizers Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_serialize rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
rustc_session Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_smir Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_span Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35 2025-02-23 14:30:25 -05:00
rustc_symbol_mangling Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_target Rollup merge of #137417 - taiki-e:riscv-atomic, r=Amanieu 2025-02-24 19:21:47 -05:00
rustc_trait_selection Remove dyn_compatible_for_dispatch 2025-02-24 18:48:40 +00:00
rustc_traits Rollup merge of #137333 - compiler-errors:edition-2024-fresh, r=Nadrieril 2025-02-22 11:36:43 +01:00
rustc_transmute Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ty_utils Rollup merge of #137334 - compiler-errors:edition-2024-fresh-2, r=saethlin,traviscross 2025-02-23 02:44:18 -05:00
rustc_type_ir Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_type_ir_macros Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
stable_mir Rollup merge of #137448 - compiler-errors:control-flow-oops, r=scottmcm 2025-02-23 02:44:20 -05:00