Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

allow returns via `xmm1` with `WindowsFastCall` for `extern "Rust"` (#14361)

Folkert de Vriese846371a94cf
diff --git a/cranelift/codegen/src/isa/x64/abi.rs b/cranelift/codegen/src/isa/x64/abi.rs
index 3c3dac7f56..2616737bfc 100644
--- a/cranelift/codegen/src/isa/x64/abi.rs
+++ b/cranelift/codegen/src/isa/x64/abi.rs
@@ -1122,6 +1122,7 @@ fn get_fltreg_for_retval(call_conv: CallConv, fltreg_idx: usize, is_last: bool)
},
CallConv::WindowsFastcall => match fltreg_idx {
0 => Some(regs::xmm0()),
+ 1 => Some(regs::xmm1()), // The Rust ABI for float scalar pairs needs this.
_ => None,
},
CallConv::Winch => is_last.then(|| regs::xmm0()),
diff --git a/cranelift/filetests/filetests/isa/x64/float-scalar-pair.clif b/cranelift/filetests/filetests/isa/x64/float-scalar-pair.clif
new file mode 100644
index 0000000000..c901935767
--- /dev/null
+++ b/cranelift/filetests/filetests/isa/x64/float-scalar-pair.clif
@@ -0,0 +1,31 @@
+test compile precise-output
+target x86_64
+
+function %f32_tuple(f32, f32) -> f32, f32 windows_fastcall {
+block0(v0: f32, v1: f32):
+ return v1, v0
+}
+
+; VCode:
+; pushq %rbp
+; movq %rsp, %rbp
+; block0:
+; movdqa %xmm0, %xmm2
+; movdqa %xmm1, %xmm0
+; movdqa %xmm2, %xmm1
+; movq %rbp, %rsp
+; popq %rbp
+; retq
+;
+; Disassembled:
+; block0: ; offset 0x0
+; pushq %rbp
+; movq %rsp, %rbp
+; block1: ; offset 0x4
+; movdqa %xmm0, %xmm2
+; movdqa %xmm1, %xmm0
+; movdqa %xmm2, %xmm1
+; movq %rbp, %rsp
+; popq %rbp
+; retq
+