setjmp: read the manual

Geoff Kuenning geoff at desint.UUCP
Fri Oct 19 17:17:47 AEST 1984


In article <401 at ism780.UUCP> Darryl Richman (darryl at ism780.UUCP) writes:

>>To fix a program that this breaks, you remove "register" declarations from
>>routines that call setjmp.  Not so bad.
>
>Don't you also have to start removing the register declarations in the
>functions that call functions that call setjmp?  Seems like you could
>lose their (parents to funcs that call setjmp) register values further
>down in the call chain also...
>

Nope.  "setjmp" itself takes care of this by saving 100% of the registers at
the time it is called.  So the *parents'* registers are completely
protected.

>>On the VAX there is a call instruction that dumps all this
>>stuff on the stack for you (slowly; I understand a Modula compiler that
>>avoided the instruction sped itself up by 20%).  On the 68000 there is
>>no such whizzo instruction so we were forced to do it efficiently or
>>tell ourselves why not.
>
>BTW the 68000 has a whizzo instruction for saving registers --
>`movem' (move multiple).

The register saving is not the problem.  The problem is recording *on the
stack* which registers have been saved, so that someone other than the routine
that saved the registers (e.g., longjmp) can restore them.  On the 68k, you
would have to explicitly push a movem mask, and unwinding that mask would
involve either slow bit shifting or (yuck) instruction modification (although
you don't have to unwind it in software very often).  But pushing that mask
(you can manage to pop it for free as part of your 'unlk') is a pretty heavy
penalty to pay in a 5-instruction entry/exit sequence (link/movem/movem/unlk
and rts), just so setjmp works a bit simpler.  And what about the pdp11, the
8086, and many other machines?  Bell supports UNIX on an ever-growing variety
of computers.

-- 
	Geoff Kuenning
	First Systems Corporation
	...!ihnp4!trwrb!desint!geoff



More information about the Comp.lang.c mailing list