Text file
src/runtime/cgo/asm_unix_amd64.s
1 // Copyright 2026 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build goexperiment.cgobindings && (darwin || (linux && !android)) && amd64
6
7 #include "go_asm.h"
8 #include "textflag.h"
9 #include "abi_amd64.h"
10
11 // callC calls a C function with up to 6 integer/pointer arguments
12 // in the System V AMD64 ABI and returns its integer/pointer result.
13 // The function may be variadic: AX is cleared to tell it that no
14 // arguments are passed in vector registers.
15 TEXT ·callC<ABIInternal>(SB),NOSPLIT,$0
16 // Convert from Go ABIInternal (AX, BX, CX, DI, SI, R8, R9)
17 // to System V AMD64 ABI (fn in R11; args in DI, SI, DX, CX, R8, R9).
18 MOVQ AX, R11
19 MOVQ DI, DX
20 MOVQ BX, DI
21 MOVQ CX, AX
22 MOVQ SI, CX
23 MOVQ AX, SI
24 // a4 and a5 are already in R8 and R9.
25 MOVQ SP, BX
26 ANDQ $~15, SP
27 XORL AX, AX // vararg: say "no float args"
28 CALL R11
29 MOVQ BX, SP
30 // Restore X15 (the ABIInternal zero register), which is caller-saved
31 // in the System V AMD64 ABI. The return value is already in AX.
32 #ifndef GOAMD64_v3
33 #ifndef GOAMD64_v4
34 XORPS X15, X15
35 CMPB internal∕cpu·X86+const_offsetX86HasAVX(SB), $1
36 JNE noavx
37 #endif
38 #endif
39 VXORPS X15, X15, X15
40 noavx:
41 RET
42
View as plain text