<div class="gmail_quote">On 8 March 2012 22:13, H. S. Teoh <span dir="ltr"><<a href="mailto:hsteoh@quickfur.ath.cx" target="_blank">hsteoh@quickfur.ath.cx</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>On Thu, Mar 08, 2012 at 10:08:41PM +0200, Manu wrote:<br>
> I find myself really wishing for proper multiple return values almost every<br>
> day, particularly when I work with maths heavy code, and especially for<br>
> efficiently returning error codes in functions I'd rather not throw from.<br>
> Many maths-y functions return some sort of pair; intersections return (ray,<br>
> t) or something of that type.<br>
> I'm finding HEAPS of SIMD functions want to return pairs (unpacks in<br>
> particular): int4 (low, hight) = unpack(someShort8);<br>
> Currently I have to duplicate everyting: int4 low =<br>
> unpackLow(someShort8); int4 high = unpackHigh(someShort8);<br>
> I'm getting really sick of that, it feels so... last millennium.<br>
><br>
> The point of 'proper' multiple return values is to return each value in<br>
> registers, in its own register type, using exactly the same register<br>
> assignment pattern as when passing args TO functions.<br>
> I don't think this causes any side effects to the ABI, since the arg<br>
> registers are already volatile across function calls in the first place.<br>
> It just means that the returned-to function can find its return<br>
> values already conveniently in an appropriate register, avoiding memory<br>
> access.<br>
><br>
> People argue I should return a tuple, but this isn't really the same, it<br>
> has hidden implications that complicate the optimisation potential. For<br>
> instance, tuples have an implicit structure/memory layout which can't be<br>
> ignored, whereas return values don't have memory allocated, ie, you can't<br>
> take the address of a return value without first assigning it to some local<br>
> syntactically.<br>
</div></div>[...]<br>
<br>
Couldn't you just use ref parameters? Or does the compiler turn them<br>
into pointers?<br></blockquote><div><br></div><div>ref parameters are pointers by definition. That's not what I'm talking about.</div>
</div>