Behaviour of setjmp/longjmp and registers

Ray Butterworth rbutterworth at watmath.waterloo.edu
Fri Jan 27 06:38:36 AEST 1989


In article <9467 at ihlpb.ATT.COM>, gregg at ihlpb.ATT.COM (Wonderly) writes:
> > this is one of the several reasons i consider caller-saves a better
> > approach to function call protocol.
> Except that this kills any efficency that one might try to gain through
> the use of normal scratch registers at the lowest level of function call.
> What is the expense of 
>     for (i=0; i < cnt; ++i)
>         cnt[i] = strlen (str[i]);
> when caller saves verses the case where called saves?  If caller uses a
> lot of registers, it will continually save/restore them if caller saves
> whereas when called saves, it can decide when all of that work should
> really be done.

I think you've got it backwards.  If the caller saves, and the
compiler has any smarts at all, it will go something like:

    /* save all active registers now */
    for (i=0; i < cnt; ++i)
        cnt[i] = strlen (str[i]);
    /* restore all active registers now */

i.e. if the current function uses N registers, and strlen uses n registers,
then with caller saving there are N saves and N restores,
and with callee saving there are cnt*n saves and cnt*n restores.

So which is better depends upon which is smaller, N or cnt*n.

For strlen(), n might be small, but in general I think that
N is usually a lot smaller than cnt*n.




More information about the Comp.lang.c mailing list