arguments in registers [a Good Thing]
mash at mips.UUCP
mash at mips.UUCP
Mon May 12 15:07:14 AEST 1986
In article <109 at ima.UUCP> johnl at ima.UUCP (John R. Levine) writes:
>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.
1) Passing arguments in registers is indeed a big win. There is at least
some belief that 2 registers gets you 70-80% of the calls, 4 registers
gets you 90-95%.
2) I'm sure many systems do this these days, especially now that varargs
is more widely used. I may recall incorrectly, but I thought the Zilog
ZEUS system's compiler did this. At least the HP Spectrum and MIPS R2000
compilers do (4 regs). This is especially attractive on 32-register RISC
machines. Certainly the method is not a "disaster", since live
running Unices are supported by them.
3) (^---^ part above): They don't have to be saved unless the code takes
the address of them (the exact conditions vary, but reasonable assumptions
can be made). A good global optimizer may well NEVER save them.
In particular, they almost NEVER need to be saved inside a leaf (i.e.,
calls no functions) routine, at least on machines that have 32 registers.
Even better, the arguments may well be computed into the argument registers
in the first place.
4) For good optimizers, "register x" doesn't mean much any more except
to clue the compiler quickly that no address can be taken of x.
--
-john mashey DISCLAIMER: <generic disclaimer, I speak for me only, etc>
UUCP: {decvax,ucbvax,ihnp4}!decwrl!mips!mash, DDD: 408-720-1700, x253
USPS: MIPS Computer Systems, 930 E. Arques, Sunnyvale, CA 94086
More information about the Comp.unix.wizards
mailing list