From 35fa852d6dda69ce367e449fff78b3fc09834c97 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Mon, 12 Feb 2024 12:38:37 +0100 Subject: runtime: use the right number of parameters in syscall_SyscallX on Windows The syscall_SyscallX functions currently discard the nargs parameter when calling syscall_SyscallN. This precludes some optimizations down the line. For example, on amd64, a syscall that takes 0 arguments don't need to set any of the params passing registers (CX, DX, R8, and R9). This CL updates all syscall_SyscallX functions so they call syscall_SyscallN with an argument slice of the right length. While here, remove the hack in syscall_SyscallN to support less than 4 arguments, and update instead asmstdcall on amd64 to properly handle this case. Change-Id: I0328e14f34c2b000fde06cc6a579b09e8c32f2b9 Reviewed-on: https://go-review.googlesource.com/c/go/+/563315 TryBot-Result: Gopher Robot LUCI-TryBot-Result: Go LUCI Run-TryBot: Quim Muntal Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Than McIntosh --- src/runtime/sys_windows_amd64.s | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/runtime/sys_windows_amd64.s') diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s index c1b78e3976..56a2dc0bcf 100644 --- a/src/runtime/sys_windows_amd64.s +++ b/src/runtime/sys_windows_amd64.s @@ -33,14 +33,12 @@ TEXT runtimeĀ·asmstdcall(SB),NOSPLIT,$16 SUBQ $(const_maxArgs*8), SP // room for args - // Fast version, do not store args on the stack nor - // load them into registers. - CMPL CX, $0 - JE docall - // Fast version, do not store args on the stack. - CMPL CX, $4 - JLE loadregs + CMPL CX, $0; JE _0args + CMPL CX, $1; JE _1args + CMPL CX, $2; JE _2args + CMPL CX, $3; JE _3args + CMPL CX, $4; JE _4args // Check we have enough room for args. CMPL CX, $const_maxArgs @@ -53,22 +51,25 @@ TEXT runtimeĀ·asmstdcall(SB),NOSPLIT,$16 REP; MOVSQ MOVQ SP, SI -loadregs: // Load first 4 args into correspondent registers. - MOVQ 0(SI), CX - MOVQ 8(SI), DX - MOVQ 16(SI), R8 - MOVQ 24(SI), R9 // Floating point arguments are passed in the XMM // registers. Set them here in case any of the arguments // are floating point values. For details see // https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170 - MOVQ CX, X0 - MOVQ DX, X1 - MOVQ R8, X2 +_4args: + MOVQ 24(SI), R9 MOVQ R9, X3 +_3args: + MOVQ 16(SI), R8 + MOVQ R8, X2 +_2args: + MOVQ 8(SI), DX + MOVQ DX, X1 +_1args: + MOVQ 0(SI), CX + MOVQ CX, X0 +_0args: -docall: // Call stdcall function. CALL AX -- cgit v1.3-5-g45d5