Andrew J Bromage <[EMAIL PROTECTED]> writes:

> G'day all.
>
> On Sun, Apr 28, 2002 at 09:49:35PM -0400, Melvin Smith wrote:
>
>> I don't think I and Andrew were saying we shouldn't do caller-save,
>> we were just discussing that the calling convention (read
>> activation record of a subroutine) should support the common
>> optimization of passing args in scratch registers when it might
>> make sense. Having scratch registers and/or allowing passing in
>> registers says nothing about whether you can implement co-routines
>> or continuations how you see fit nor whether a caller saves its
>> environment correctly or not.
>
> Actually, I _was_ saying we shouldn't do caller-save (except
> possibly for a small number of registers designated for the
> purpose).

Remember that the caller only has to save the stuff that is important
to it, after all, anything that might be of importance to *its*
callers will already have been saved. If the callee saves then it's
going to be doing belt and braces save/restores on registers that may
be completely irrelevant.

> My main reason for objecting is that it slows down trivial leaf
> subs, which are very common in OO programming.  Ideally neither the
> caller nor the callee should need to save registers when calling
> such a sub.

Any half decent compiler, given enough information from the original
source and/or linkage information on precompiled modules will be able
to do the appropriate register saving optimizations at compile
time. It should even be possible to have automagic inlining
happening. 

> I also can't see that it speeds anything up in the case of
> non-trivial/ non-leaf subs.  If the caller isn't trivial, it will
> still have to save lots of registers, so it really doesn't matter
> who does it.

Well factored code tends to have plenty of small, trivial
subroutines... And in the case of non trivial subs then the register
saving overhead will be the same whereever it happens. The precise
breakdown will be different, but I claim that the average case will
stay roughly the same.

> There's got to be a reason for making caller-save the default, but I
> can't think of it. :-)

You've still not shown how you're going to make a first class
continuation when the callee saves. And no, using branch instead of
bsr is *not* a good enough answer, you need to be able to bundle up a
continuation that can be called from anywhere, even after that
continuation is no longer in the current caller chain, which means you
need to be able to restore the register state and continuation chain.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Reply via email to