1package backend
2
3import "github.com/tetratelabs/wazero/internal/engine/wazevo/ssa"
4
5// GoFunctionCallRequiredStackSize returns the size of the stack required for the Go function call.
6// argBegin is the index of the first argument in the signature which is not either execution context or module context.
7func GoFunctionCallRequiredStackSize(sig *ssa.Signature, argBegin int) (ret, retUnaligned int64) {
8 var paramNeededInBytes, resultNeededInBytes int64
9 for _, p := range sig.Params[argBegin:] {
10 s := int64(p.Size())
11 if s < 8 {
12 s = 8 // We use uint64 for all basic types, except SIMD v128.
13 }
14 paramNeededInBytes += s
15 }
16 for _, r := range sig.Results {
17 s := int64(r.Size())
18 if s < 8 {
19 s = 8 // We use uint64 for all basic types, except SIMD v128.
20 }
21 resultNeededInBytes += s
22 }
23
24 if paramNeededInBytes > resultNeededInBytes {
25 ret = paramNeededInBytes
26 } else {
27 ret = resultNeededInBytes
28 }
29 retUnaligned = ret
30 // Align to 16 bytes.
31 ret = (ret + 15) &^ 15
32 return
33}