Skip to content

Commit 673137a

Browse files
committed
riscv: zaamo/zabha target_feature now available on rustc side
1 parent 024ee7a commit 673137a

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
125125
'cfg(target_arch,values("xtensa"))', # 1.81+ https://github.com/rust-lang/rust/pull/125141
126126
'cfg(target_feature,values("lse2","lse128","rcpc3"))', # 1.82+ https://github.com/rust-lang/rust/pull/128192
127127
'cfg(target_feature,values("quadword-atomics"))', # 1.83+ https://github.com/rust-lang/rust/pull/130873
128+
'cfg(target_feature,values("zaamo","zabha"))', # 1.83+ https://github.com/rust-lang/rust/pull/130877
128129
'cfg(target_pointer_width,values("128"))',
129130
# Known custom cfgs, excluding those that may be set by build script.
130131
# Not public API.

build.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747

4848
if version.minor >= 80 {
4949
println!(
50-
r#"cargo:rustc-check-cfg=cfg(target_feature,values("zaamo","zabha","experimental-zacas","fast-serialization","load-store-on-cond","distinct-ops","miscellaneous-extensions-3"))"#
50+
r#"cargo:rustc-check-cfg=cfg(target_feature,values("experimental-zacas","fast-serialization","load-store-on-cond","distinct-ops","miscellaneous-extensions-3"))"#
5151
);
5252

5353
// Custom cfgs set by build script. Not public API.
@@ -323,16 +323,14 @@ fn main() {
323323
}
324324
}
325325
"riscv32" | "riscv64" => {
326-
// As of rustc 1.80, target_feature "zaamo"/"zabha"/"zacas" is not available on rustc side:
327-
// https://github.com/rust-lang/rust/blob/1.80.0/compiler/rustc_target/src/target_features.rs#L273
328-
// zabha and zacas imply zaamo in GCC, but do not in LLVM (but enabling them without zaamo is not allowed).
326+
// zabha and zacas imply zaamo in GCC and Rust, but do not in LLVM (but enabling them
327+
// without zaamo or a is not allowed, so we can assume zaamo is available when zabha is enabled).
329328
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/RISCVISAInfo.cpp#L772-L778
330329
// https://github.com/gcc-mirror/gcc/blob/08693e29ec186fd7941d0b73d4d466388971fe2f/gcc/config/riscv/arch-canonicalize#L45-L46
331-
if version.llvm >= 19 {
332-
// amo*.{b,h}
333-
// available since LLVM 19 https://github.com/llvm/llvm-project/commit/89f87c387627150d342722b79c78cea2311cddf7 / https://github.com/llvm/llvm-project/commit/6b7444964a8d028989beee554a1f5c61d16a1cac
334-
target_feature_fallback("zabha", false);
335-
}
330+
// https://github.com/rust-lang/rust/pull/130877
331+
let mut has_zaamo = false;
332+
// As of rustc 1.80, target_feature "zacas" is not available on rustc side:
333+
// https://github.com/rust-lang/rust/blob/1.80.0/compiler/rustc_target/src/target_features.rs#L273
336334
if version.llvm == 19 {
337335
// amocas.{w,d,q} (and amocas.{b,h} if zabha is also available)
338336
// available as experimental since LLVM 17 https://github.com/llvm/llvm-project/commit/29f630a1ddcbb03caa31b5002f0cbc105ff3a869
@@ -341,10 +339,19 @@ fn main() {
341339
// check == 19 instead of range 17..=19 because it is more experimental in LLVM 17/18.
342340
// check == 19 instead of >= 19 because "experimental-zacas" feature
343341
// may no longer exist when it is marked as non-experimental in LLVM 20.
344-
target_feature_fallback("experimental-zacas", false);
342+
// https://github.com/llvm/llvm-project/commit/614aeda93b2225c6eb42b00ba189ba7ca2585c60
343+
has_zaamo |= target_feature_fallback("experimental-zacas", false);
344+
}
345+
// target_feature "zaamo"/"zabha" is unstable and available on rustc side since nightly-2024-10-02: https://github.com/rust-lang/rust/pull/130877
346+
if !version.probe(83, 2024, 10, 1) || needs_target_feature_fallback(&version, None) {
347+
if version.llvm >= 19 {
348+
// amo*.{b,h}
349+
// available since LLVM 19 https://github.com/llvm/llvm-project/commit/89f87c387627150d342722b79c78cea2311cddf7 / https://github.com/llvm/llvm-project/commit/6b7444964a8d028989beee554a1f5c61d16a1cac
350+
has_zaamo |= target_feature_fallback("zabha", false);
351+
}
352+
// amo*.{w,d}
353+
target_feature_fallback("zaamo", has_zaamo);
345354
}
346-
// amo*.{w,d}
347-
target_feature_fallback("zaamo", false);
348355
}
349356
"powerpc64" => {
350357
// target_feature "quadword-atomics" is unstable and available on rustc side since nightly-2024-09-28: https://github.com/rust-lang/rust/pull/130873

0 commit comments

Comments
 (0)