Basile Starynkevitch <bas...@starynkevitch.net> writes: >In my MELT experience, most multiple-results function calls have only >two results. Giving 3 results is very rare, and giving more than 3 >results is really exceptionnal (probably as exceptionnal as functions >with more than 6 arguments). > >From what I learned from the Go tutorial at the GCC summit, The Go >language also have several idioms with two results.
I agree that Go code rarely returns more than two results, though for example runtime.Caller returns four results: func Caller(skip int) (pc uintptr, file string, line int, ok bool) >From what I know of the AMD64 ABI, (but I might be false), functions >are only supposed to return one result in a register (rax...). It's a little more complicated than that, as always. In some cases values may be returned on the floating point stack, or in the MMX registers, or in the SSE registers. When returning a value of type complex long or similar, the values will be returned in the two registers %rax/%rdx. The same is true when returning a struct with integer type fields whose size is 32 bytes or less. For the complex full set of rules, see the x86_64 ABI. > Does the Go language define a specific ABI convention for returning > two values from a function thru registers? If yes, how does GCC > implement it? Or is it some future work? The Go language does not define an ABI for returning multiple values. The gccgo frontend implements it by saying that a function which returns multiple values returns a struct with fields whose types are the types of the result parameter. It's desirable to make it possible to write C functions which return multiple values to Go code. For example, some of the runtime support functions work that way. Having the Go return a struct ensures that it is easy to write compatible C code. Ian