Multiple return values

Manu turkeyman at gmail.com
Tue Jan 3 15:21:27 PST 2012


When a function is inlined, virtually everything regarding parameters
passing is irrelevant, the compiler can usually do what's best in this case.

In the former case, it's extremely rare that the calling function making
the register available for the return value could negatively affect
performance.. if it wants the returned value (that was alternatively
written to the stack), it needs to allocate a register for it anyway, why
not the one that allows it to return directly. Additionally, if the
function receives any args, then the registers for return values are
probably already allocated to the function call to pass the args when
calling.

On 4 January 2012 01:17, Mail Mantis <mail.mantis.88 at gmail.com> wrote:

> 2012/1/4 Manu <turkeyman at gmail.com>
>
>> Does returning a tuple give any ABI guarantees? How can I be sure
>> multiple return values will return in consecutive registers?
>> What if the return types are of different types, a float and an int...
>> can I expect each to return in their own register types respectively?
>> This needs to be defined and loosely guaranteed (within reason) so people
>> can expect multiple return values to behave as expected on any architecture.
>>
>>
>> On 4 January 2012 01:02, Sean Kelly <sean at invisibleduck.org> wrote:
>>
>>> It's easy enough with Tuple, though better language support would be
>>> nice.
>>>
>>> Sent from my iPhone
>>>
>>> On Jan 3, 2012, at 2:40 PM, Manu <turkeyman at gmail.com> wrote:
>>>
>>> > Why doesn't D support multiple return values like many other modern
>>> languages?
>>> >
>>> > Clearly the same syntax as Go wouldn't work, but I'm sure a neat and
>>> tidy syntax could be invented?
>>> > I constantly want to be able to return x,y from a function, or
>>> retVal,errorCode and I want the language to make some rough ABI guarantees,
>>> like multiple return values will be returned in consecutive registers,
>>> rather than a single return value register like C/C++, avoiding the need to
>>> pass output addresses through ref function parameters (slow!).
>>>
>>
>> Returning multiple values in registers might not always be the best idea
> from the performance point of view. The caller must make sure the
> appropriate registers don't hold any intermediate values before calling the
> function, so overall complier optimization may be poorer.
> Of course, this only applies when function is actually called. When it is
> inlined, having multiple return values could result in better optimization.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120104/d1c1e766/attachment.html>


More information about the Digitalmars-d mailing list