Skip to content

Commit 38c1ac9

Browse files
committed
Change the f128 ABI to match i128 on Windows
1 parent 4429a48 commit 38c1ac9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

compiler/rustc_target/src/callconv/x86_win64.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,24 @@ pub(crate) fn compute_abi_info<Ty>(cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<'
2323
// (probably what clang calls "illegal vectors").
2424
}
2525
BackendRepr::Scalar(scalar) => {
26-
if is_ret && matches!(scalar.primitive(), Primitive::Int(Integer::I128, _)) {
26+
if is_ret
27+
&& matches!(
28+
scalar.primitive(),
29+
Primitive::Int(Integer::I128, _) | Primitive::Float(Float::F128)
30+
)
31+
{
32+
// i128 and f128 have the same ABI on Windows.
2733
if cx.target_spec().rustc_abi == Some(RustcAbi::X86Softfloat) {
28-
// Use the native `i128` LLVM type for the softfloat ABI -- in other words, adjust nothing.
34+
// Use the native `i128`/`f128` LLVM type for the softfloat ABI -- in other
35+
// words, adjust nothing.
2936
} else {
30-
// `i128` is returned in xmm0 by Clang and GCC
37+
// `i128` and `f128` are returned in xmm0 by Clang. `i128` is returned in
38+
// xmm0 by GCC but `f128` is indirect (Clang and GCC have a mismatch).
3139
// FIXME(#134288): This may change for the `-msvc` targets in the future.
3240
let reg = Reg { kind: RegKind::Vector, size: Size::from_bits(128) };
3341
a.cast_to(reg);
3442
}
35-
} else if a.layout.size.bytes() > 8
36-
&& !matches!(scalar.primitive(), Primitive::Float(Float::F128))
37-
{
38-
// Match what LLVM does for `f128` so that `compiler-builtins` builtins match up
39-
// with what LLVM expects.
43+
} else if a.layout.size.bytes() > 8 {
4044
a.make_indirect();
4145
} else {
4246
a.extend_integer_width_to(32);

tests/assembly/x86_64-windows-float-abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub extern "C" fn second_f64(_: f64, x: f64) -> f64 {
3737
}
3838

3939
// CHECK-LABEL: second_f128
40-
// CHECK: movaps %xmm1, %xmm0
40+
// CHECK: movaps (%rdx), %xmm0
4141
// CHECK-NEXT: retq
4242
#[no_mangle]
4343
pub extern "C" fn second_f128(_: f128, x: f128) -> f128 {

0 commit comments

Comments
 (0)