Skip to content

Commit e87834e

Browse files
committed
add optional soft-float feature for s390x target
to use soft-float one need to also set the `s390x-softfloat` flag in the .rustc_abi target field. This will automatically enable the +soft-float feature. On normal compilation with the default ABI soft-float is still marked incompatible. So the ABI cannot be be broken by accident.
1 parent 4931e09 commit e87834e

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

compiler/rustc_target/src/spec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,8 @@ crate::target_spec_enum! {
10071007
X86Sse2 = "x86-sse2",
10081008
/// On x86-32/64 only: do not use any FPU or SIMD registers for the ABI.
10091009
X86Softfloat = "x86-softfloat",
1010+
// On S390x only: do not use any FPU or Vector registers for the ABI.
1011+
S390xSoftFloat = "s390x-softfloat",
10101012
}
10111013

10121014
parse_error_type = "rustc abi";
@@ -3198,6 +3200,11 @@ impl Target {
31983200
Arch::X86 | Arch::X86_64,
31993201
"`x86-softfloat` ABI is only valid for x86 targets"
32003202
),
3203+
RustcAbi::S390xSoftFloat => check_matches!(
3204+
self.arch,
3205+
Arch::S390x,
3206+
"`s390x-softfloat` ABI is only valid for s390x targets"
3207+
),
32013208
}
32023209
}
32033210

compiler/rustc_target/src/target_features.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ impl Target {
10981098
// LLVM handles the rest.
10991099
FeatureConstraints { required: &["soft-float"], incompatible: &[] }
11001100
}
1101+
Some(r) => panic!("invalid Rust ABI for x86: {r:?}"),
11011102
}
11021103
}
11031104
Arch::X86_64 => {
@@ -1211,11 +1212,26 @@ impl Target {
12111212
}
12121213
}
12131214
Arch::S390x => {
1214-
// We don't currently support a softfloat target on this architecture.
1215-
// As usual, we have to reject swapping the `soft-float` target feature.
1215+
// Same as x86, We use our own ABI indicator here;
1216+
// LLVM does not have anything native and will switch ABI based
1217+
// on the soft-float target feature.
1218+
// Every case should require or forbid `soft-float`!
12161219
// The "vector" target feature does not affect the ABI for floats
12171220
// because the vector and float registers overlap.
1218-
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
1221+
match self.rustc_abi {
1222+
None => {
1223+
// Default hardfloat ABI.
1224+
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
1225+
}
1226+
Some(RustcAbi::S390xSoftFloat) => {
1227+
// Softfloat ABI, requires corresponding target feature.
1228+
// llvm will switch to soft-float ABI just based on this feature.
1229+
FeatureConstraints { required: &["soft-float"], incompatible: &[] }
1230+
}
1231+
Some(r) => {
1232+
panic!("invalid Rust ABI for s390x: {r:?}");
1233+
}
1234+
}
12191235
}
12201236
_ => NOTHING,
12211237
}

0 commit comments

Comments
 (0)