Path: utzoo!utgpu!watmath!rbutterworth From: rbutterworth@watmath.waterloo.edu (Ray Butterworth) Newsgroups: comp.lang.c Subject: Re: Behaviour of setjmp/longjmp and registers Message-ID: <23303@watmath.waterloo.edu> Date: 26 Jan 89 20:38:36 GMT References: <5771@phoenix.Princeton.EDU> <9467@ihlpb.ATT.COM> Organization: U of Waterloo, Ontario Lines: 30 In article <9467@ihlpb.ATT.COM>, gregg@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.