Skip to content

Commit

Permalink
Match LLVM ABI in extern "C" functions for f128 on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
beetrees committed Jul 30, 2024
1 parent e69c19e commit bf8798c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_target/src/abi/call/x86_win64.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::abi::call::{ArgAbi, FnAbi, Reg};
use crate::abi::Abi;
use crate::abi::{Abi, Float, Primitive};

// Win64 ABI: https://docs.microsoft.com/en-us/cpp/build/parameter-passing

Expand All @@ -18,8 +18,12 @@ pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
// FIXME(eddyb) there should be a size cap here
// (probably what clang calls "illegal vectors").
}
Abi::Scalar(_) => {
if a.layout.size.bytes() > 8 {
Abi::Scalar(scalar) => {
// Match what LLVM does for `f128` so that `compiler-builtins` builtins match up
// with what LLVM expects.
if a.layout.size.bytes() > 8
&& !matches!(scalar.primitive(), Primitive::Float(Float::F128))
{
a.make_indirect();
} else {
a.extend_integer_width_to(32);
Expand Down
4 changes: 3 additions & 1 deletion library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn main() {
// Unsupported <https://github.com/llvm/llvm-project/issues/94434>
("arm64ec", _) => false,
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
("x86", "windows") => false,
("x86_64", "windows") => false,
// x86 has ABI bugs that show up with optimizations. This should be partially fixed with
// the compiler-builtins update. <https://github.com/rust-lang/rust/issues/123885>
("x86" | "x86_64", _) => false,
Expand Down Expand Up @@ -122,6 +122,8 @@ fn main() {
("nvptx64", _) => false,
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838>
("sparc", _) => false,
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
("x86_64", "windows") => false,
// 64-bit Linux is about the only platform to have f128 symbols by default
(_, "linux") if target_pointer_width == 64 => true,
// Same as for f16, except MacOS is also missing f128 symbols.
Expand Down
23 changes: 23 additions & 0 deletions tests/assembly/f16-f128-windows-x86_64-abi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ assembly-output: emit-asm
//@ compile-flags: -O
//@ only-windows
//@ only-x86_64

#![feature(f16, f128)]
#![crate_type = "lib"]

// CHECK-LABEL: second_f16
// CHECK: movaps %xmm1, %xmm0
// CHECK-NEXT: retq
#[no_mangle]
pub extern "C" fn second_f16(_: f16, x: f16) -> f16 {
x
}

// CHECK-LABEL: second_f128
// CHECK: movaps %xmm1, %xmm0
// CHECK-NEXT: retq
#[no_mangle]
pub extern "C" fn second_f128(_: f128, x: f128) -> f128 {
x
}

0 comments on commit bf8798c

Please sign in to comment.