[comp.sys.nsc.32k] Calling conventions

chaim@nsc.nsc.com (Chaim Bendelac) (05/31/90)

In article <9005231633.29312@munnari.oz.au> ian@sibyl.eleceng.ua.oz.au writes:
>Amos Shapira writes:

> > Hello,
> >  ian@sibyl.eleceng.ua.oz.au askes:
> > 
> >  > I built gcc with a convention where R0 - R3 inclusive are free for use
> >  > in functions without saving and restoring (for compatability with my
> >  > ICM library functions).
> > 
> >  In the  "GNX - Version 3 Assembler Reference Manual" from NSC (NSC
> >  Publication Number 424010497-003C) there is a small Appendix
> >  (E) about calling conventions. This appendix clearly states that only
> >  registers R0-R2 should be considered as "unsafe", the same with floating
> >  registers F0-F3. The rest of the registers (i.e. R3-R7 and F4-F7) must
> >  be saved before used in a procedure.

>Clearly NS haven't been consistent. 

The ICM compiler was inconsistent with most other compilers for the 32K; NSC's
current compilers (GNX) follow the r0-r2,f0-f3 unsafe, rest safe rule.

>I was wondering if anyone had any information about the pro's and
>con's involved. 

We did some experimentation and testing of this (after we had already set
the convention). We implemented a little secret kludge in our compiler to
indicate the "infinite" number of safe and unsafe registers the optimizer
COULD use, were they available (under the same general assumptions as our
current register model, ie, it COSTS something to use a safe register (you
have to save/restore it), it COSTS something to have a global variable or
param in a register (you have to load and sometimes spill it). 
The GNX optimizer performs some additional clever footwork with registers; it
maneuvers "return" results into r0 (to avoid extra mov's), it passes params
to (static) functions thru r0/r1 when advantagous, etc.

Anyway, the results were not clear-cut. In leaf-routines, obviously, more
unsafe registers were needed than in non-leaf routines, which had variable
life-ranges over function-calls. Some functions needed many more safes,
other functions were better off with many more unsafes. Bottom-line, both 
the 3-5 and the 4-4 split make sense, and are certainly better than a 0-8 
or 8-0 convention.
---
chaim@nsc.nsc.com