Skip to content

Commit

Permalink
powerpc64: quadword-atomics target_feature now available on rustc side
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 28, 2024
1 parent 66b25f8 commit 3eb8507
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ single_use_lifetimes = "warn"
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(target_arch,values("xtensa"))', # 1.81+ https://github.com/rust-lang/rust/pull/125141
'cfg(target_feature,values("lse2","lse128","rcpc3"))', # 1.82+ https://github.com/rust-lang/rust/pull/128192
'cfg(target_feature,values("quadword-atomics"))', # 1.83+ https://github.com/rust-lang/rust/pull/130873
'cfg(target_pointer_width,values("128"))',
# Known custom cfgs, excluding those that may be set by build script.
# Not public API.
Expand Down
47 changes: 24 additions & 23 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn main() {

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

// Custom cfgs set by build script. Not public API.
Expand Down Expand Up @@ -343,31 +343,32 @@ fn main() {
target_feature_fallback("zaamo", false);
}
"powerpc64" => {
let target_endian =
env::var("CARGO_CFG_TARGET_ENDIAN").expect("CARGO_CFG_TARGET_ENDIAN not set");
// powerpc64le is pwr8+ by default https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L702
// See also https://github.com/rust-lang/rust/issues/59932
let mut has_pwr8_features = target_endian == "little";
// https://github.com/llvm/llvm-project/commit/549e118e93c666914a1045fde38a2cac33e1e445
if let Some(cpu) = &target_cpu() {
if let Some(mut cpu_version) = strip_prefix(cpu, "pwr") {
cpu_version = strip_suffix(cpu_version, "x").unwrap_or(cpu_version); // for pwr5x and pwr6x
if let Ok(cpu_version) = cpu_version.parse::<u32>() {
has_pwr8_features = cpu_version >= 8;
// target_feature "quadword-atomics" is unstable and available on rustc side since nightly-2024-09-28: https://github.com/rust-lang/rust/pull/130873
if !version.probe(83, 2024, 9, 27) || needs_target_feature_fallback(&version, None) {
let target_endian =
env::var("CARGO_CFG_TARGET_ENDIAN").expect("CARGO_CFG_TARGET_ENDIAN not set");
// powerpc64le is pwr8+ by default https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L702
// See also https://github.com/rust-lang/rust/issues/59932
let mut has_pwr8_features = target_endian == "little";
// https://github.com/llvm/llvm-project/commit/549e118e93c666914a1045fde38a2cac33e1e445
if let Some(cpu) = &target_cpu() {
if let Some(mut cpu_version) = strip_prefix(cpu, "pwr") {
cpu_version = strip_suffix(cpu_version, "x").unwrap_or(cpu_version); // for pwr5x and pwr6x
if let Ok(cpu_version) = cpu_version.parse::<u32>() {
has_pwr8_features = cpu_version >= 8;
}
} else {
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L702
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L483
// On the minimum external LLVM version of the oldest rustc version which we can use asm_experimental_arch
// on this target (see CI config for more), "future" is based on pwr10 features.
// https://github.com/llvm/llvm-project/blob/llvmorg-12.0.0/llvm/lib/Target/PowerPC/PPC.td#L370
has_pwr8_features = cpu == "ppc64le" || cpu == "future";
}
} else {
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L702
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L483
// On the minimum external LLVM version of the oldest rustc version which we can use asm_experimental_arch
// on this target (see CI config for more), "future" is based on pwr10 features.
// https://github.com/llvm/llvm-project/blob/llvmorg-12.0.0/llvm/lib/Target/PowerPC/PPC.td#L370
has_pwr8_features = cpu == "ppc64le" || cpu == "future";
}
// lqarx and stqcx.
target_feature_fallback("quadword-atomics", has_pwr8_features);
}
// As of rustc 1.80, target_feature "quadword-atomics" is not available on rustc side:
// https://github.com/rust-lang/rust/blob/1.80.0/compiler/rustc_target/src/target_features.rs#L253
// lqarx and stqcx.
target_feature_fallback("quadword-atomics", has_pwr8_features);
}
"s390x" => {
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZFeatures.td
Expand Down

0 comments on commit 3eb8507

Please sign in to comment.