arguments in registers
John R. Levine
johnl at ima.UUCP
Wed May 7 01:36:51 AEST 1986
In article <1205 at umcp-cs.UUCP> chris at maryland.UUCP (Chris Torek) writes:
>In article <155 at cbmvax.cbm.UUCP> grr at cbmvax.UUCP (George Robbins) writes:
>>[Passing arguments in registers] would be fine if C had nested
>>procedures or inlines or something, but a disaster otherwise.
>
>In fact, a compiler is free to optimise any function into inline code,
Actually, you can always pass arguments in registers if you're smart about it.
The compiler for the IBM RT/PC does. (A clever idea added after I stopped
working on it.) The first few arguments to a procedure are always passed in
registers, but space is left for them in the stack frame. If they aren't
declared register in the routine, the routine's prolog saves them. Note that
this saves code space, since you have one set of store instructions in the
routine's prolog rather than replicating the code at each call. If the
arguments are declared register, well, they're already in registers.
As far as passing args to system calls in registers goes, the big win there
is that the kernel's job of validating the arguments is made easier. If the
args are in memory, the kernel has to make sure the address is valid, go
through some address mapping calculations, possibly take page faults, and so
forth. It's much easier if the user program puts the args in registers, since
then the validation is done for free by hardware.
--
John R. Levine, {ihnp4 | decvax | cbosgd | harvard | yale }!ima!johnl
Levine at YALE.EDU
The opinions expressed above are those of a 12-year-old hacker who has
broken into my account and not those of any person or organization.
More information about the Comp.unix.wizards
mailing list