The SPARC psABI defines that a caller must allocate the space for a
structure returned from the callee. If the callee sees the size marker
in the allocation matches the size of the return then it fills the slot.
If the size matches we return, if it doesn't match we return anyway but
add a fixed offset to the return (like a non-local goto).

There are some optimiations that can be done...

The caller, knowing that nobody uses the result can set the size marker
to zero. The callee should check for the size marker and write nothing
to the slot, returning to the normal location plus the offset.

The callee can assume the caller allocated the space and always write to
the slot (no size check) and return to the correct position in the
caller.

Is there any example of this type of behaviour in any other ports?
I'm just looking for implementation examples.

The root cause of this research is that code like this:

#include <stdlib.h>

div_t
div(int num, int denom)
{
        div_t r;

        r.quot = num / denom;
        r.rem = num % denom;
        return (r);
}

Produces asm that doesn't check the callers size marker in the allocated
return slot. If the caller and callee are compiled separately then an
optimization in the caller could cause a problem. Rightly though the
caller can't optimize without breaking ABI. Rightly the callee can't
opimize away the size check without breaking ABI. Without coordination
we can't safely remove the checks.

Cheers,
Carlos.
-- 
Carlos O'Donell                                                                 
             
CodeSourcery, LLC                                                               
                    
[EMAIL PROTECTED] 

Reply via email to