Skip to content

Commit 3cf618f

Browse files
committed
RISC-V: Add two "A" extension subsets
The "A" extension comprises instructions provided by the "Zaamo" and "Zalrsc" extensions. To prepare for the "Zacas" extension (which provides compare-and-swap instructions and discoverable from Linux) which depends on the "Zaamo" extension, it would be better to support those subsets.
1 parent 774d95f commit 3cf618f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ features! {
3030
/// * RV32I: `"rv32i"`
3131
/// * RV64I: `"rv64i"`
3232
/// * A: `"a"`
33+
/// * Zaamo: `"zaamo"`
34+
/// * Zalrsc: `"zalrsc"`
3335
/// * Bit-Manipulation Extensions:
3436
/// * Zba: `"zba"`
3537
/// * Zbb: `"zbb"`
@@ -122,6 +124,10 @@ features! {
122124
123125
@FEATURE: #[stable(feature = "riscv_ratified", since = "1.78.0")] a: "a";
124126
/// "A" Extension for Atomic Instructions
127+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zalrsc: "zalrsc";
128+
/// "Zalrsc" Extension for Load-Reserved/Store-Conditional Instructions
129+
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zaamo: "zaamo";
130+
/// "Zaamo" Extension for Atomic Memory Operations
125131
@FEATURE: #[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")] zam: "zam";
126132
without cfg check: true;
127133
/// "Zam" Extension for Misaligned Atomics

crates/std_detect/src/detect/os/linux/riscv.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ pub(crate) fn detect_features() -> cache::Initializer {
1818
// [hwcap]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/uapi/asm/hwcap.h?h=v6.14
1919
let auxv = auxvec::auxv().expect("read auxvec"); // should not fail on RISC-V platform
2020
#[allow(clippy::eq_op)]
21-
enable_feature(Feature::a, bit::test(auxv.hwcap, (b'a' - b'a').into()));
21+
let has_a = bit::test(auxv.hwcap, (b'a' - b'a').into());
22+
enable_feature(Feature::a, has_a);
23+
enable_feature(Feature::zalrsc, has_a);
24+
enable_feature(Feature::zaamo, has_a);
2225
enable_feature(Feature::c, bit::test(auxv.hwcap, (b'c' - b'a').into()));
2326
let has_d = bit::test(auxv.hwcap, (b'd' - b'a').into());
2427
let has_f = bit::test(auxv.hwcap, (b'f' - b'a').into());

0 commit comments

Comments
 (0)