Skip to content

Commit

Permalink
More cleanups for AVR/M68k/MSP430/PowerPC/RISC-V/s390x/SPARC
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Nov 18, 2024
1 parent 755cfe9 commit 79c8600
Show file tree
Hide file tree
Showing 13 changed files with 770 additions and 384 deletions.
11 changes: 10 additions & 1 deletion .github/.cspell/project-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ andc
andn
aqrl
armasm
balign
beqz
Bicc
bnez
casp
cbnz
ccmp
cdsg
CDSY
cinc
clrex
cmpd
cmpw
cmpxchg
cset
Expand All @@ -26,21 +27,26 @@ fistp
gaisler
getex
GRLIB
hwsync
IMAFD
inequal
instrs
ishld
isync
kuser
LAAL
lclang
ldapr
ldar
ldarx
ldaxp
ldclrp
ldiapp
ldrd
ldrex
ldrexd
ldsetp
ldstub
ldxp
leoncasa
lgcc
Expand Down Expand Up @@ -75,6 +81,7 @@ opensbi
orrs
partword
pshufd
pstq
putchar
qbsp
quadword
Expand All @@ -94,6 +101,7 @@ sltui
sreg
srlv
stbar
stdcx
stilp
stlxp
stpq
Expand All @@ -116,6 +124,7 @@ uxth
virt
wokwi
xchg
xmegau
xmmword
xorps
zaamo
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ jobs:
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-cpu=pwr8
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-cpu=pwr8
if: startsWith(matrix.target, 'powerpc64-')
# powerpc64 pwr10
- run: tools/test.sh -vv --tests ${TARGET:-} ${BUILD_STD:-} ${RELEASE:-}
env:
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-cpu=pwr10
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-cpu=pwr10
if: startsWith(matrix.target, 'powerpc64')
# riscv +zabha
- run: tools/test.sh -vv --tests ${TARGET:-} ${BUILD_STD:-} ${RELEASE:-}
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Currently, x86, x86_64, Arm, AArch64, RISC-V, LoongArch64, Arm64EC, s390x, MIPS,
| mips64 / mips64r6 \[8] | isize,usize,i8,u8,i16,u16,i32,u32,i64,u64 |||
| powerpc \[8] | isize,usize,i8,u8,i16,u16,i32,u32 |||
| powerpc64 \[8] | isize,usize,i8,u8,i16,u16,i32,u32,i64,u64 |||
| powerpc64 (pwr8+) \[4] \[8] | i128,u128 |||
| powerpc64 (+quadword-atomics) \[4] \[8]| i128,u128 |||
| msp430 \[8] (experimental) | isize,usize,i8,u8,i16,u16 |||
| avr \[8] (experimental) | isize,usize,i8,u8,i16,u16 |||
| sparc \[5] \[8] (experimental) | isize,usize,i8,u8,i16,u16,i32,u32 |||
Expand Down
61 changes: 35 additions & 26 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {

if version.minor >= 80 {
println!(
r#"cargo:rustc-check-cfg=cfg(target_feature,values("x87","v8m","fast-serialization","isa-68020"))"#
r#"cargo:rustc-check-cfg=cfg(target_feature,values("x87","v8m","prefix-instrs","fast-serialization","isa-68020"))"#
);

// Custom cfgs set by build script. Not public API.
Expand All @@ -41,7 +41,7 @@ fn main() {
// TODO: handle multi-line target_feature_fallback
// grep -F 'target_feature_fallback("' build.rs | grep -Ev '^ *//' | sed -E 's/^.*target_feature_fallback\(//; s/",.*$/"/' | LC_ALL=C sort -u | tr '\n' ',' | sed -E 's/,$/\n/'
println!(
r#"cargo:rustc-check-cfg=cfg(atomic_maybe_uninit_target_feature,values("a","cmpxchg16b","fast-serialization","isa-68020","leoncasa","lse","lse128","lse2","mclass","partword-atomics","quadword-atomics","rcpc","rcpc3","v5te","v6","v7","v8","v8m","v9","x87","zaamo","zabha"))"#
r#"cargo:rustc-check-cfg=cfg(atomic_maybe_uninit_target_feature,values("a","cmpxchg16b","fast-serialization","isa-68020","leoncasa","lse","lse128","lse2","mclass","partword-atomics","prefix-instrs","quadword-atomics","rcpc","rcpc3","v5te","v6","v7","v8","v8m","v9","x87","zaamo","zabha"))"#
);
}

Expand Down Expand Up @@ -317,35 +317,43 @@ fn main() {
target_feature_fallback("a", a);
}
}
"powerpc64" => {
// 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().as_deref() {
if let Some(mut cpu_version) = cpu.strip_prefix("pwr") {
cpu_version = cpu_version.strip_suffix('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";
"powerpc" | "powerpc64" => {
// 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 pwr8_features = target_arch == "powerpc64"
&& env::var("CARGO_CFG_TARGET_ENDIAN").expect("CARGO_CFG_TARGET_ENDIAN not set")
== "little";
let mut pwr10_features = false;
if let Some(cpu) = &target_cpu() {
if let Some(mut cpu_version) = cpu.strip_prefix("pwr") {
cpu_version = cpu_version.strip_suffix('x').unwrap_or(cpu_version); // for pwr5x and pwr6x
if let Ok(cpu_version) = cpu_version.parse::<u32>() {
pwr8_features = cpu_version >= 8;
pwr10_features = cpu_version >= 10;
}
} 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
let future = cpu == "future";
pwr8_features = future || cpu == "ppc64le";
pwr10_features = future;
}
}
// 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) {
// power8 features: /~https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L409
// l[bh]arx and st[bh]cx.
target_feature_fallback("partword-atomics", has_pwr8_features);
target_feature_fallback("partword-atomics", pwr8_features);
// lqarx and stqcx.
target_feature_fallback("quadword-atomics", has_pwr8_features);
target_feature_fallback("quadword-atomics", pwr8_features);
}
// As of rustc 1.80, target_feature "prefix-instrs" is not available on rustc side:
// /~https://github.com/rust-lang/rust/blob/1.80.0/compiler/rustc_target/src/target_features.rs
// power10 features: /~https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/PowerPC/PPC.td#L460
target_feature_fallback("prefix-instrs", pwr10_features);
}
"s390x" => {
// /~https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZFeatures.td
Expand All @@ -362,6 +370,7 @@ fn main() {
}
// As of rustc 1.80, target_feature "fast-serialization" is not available on rustc side:
// /~https://github.com/rust-lang/rust/blob/1.80.0/compiler/rustc_target/src/target_features.rs
// arch9 features: /~https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZFeatures.td#L103
// bcr 14,0
target_feature_fallback("fast-serialization", arch9_features);
}
Expand Down
Loading

0 comments on commit 79c8600

Please sign in to comment.