Questions about SPARC's C compiler

Theodore A. Camus tac at cs.brown.edu
Tue Jun 5 12:26:05 AEST 1990


>1. When I check some assembly codes, I realize global registers, g0,
>   g1,...,etc, are rarely used.  

The global registers are used in "leaf routines", functions that do not
need to allocate their own register window.  By convention, they use the
global registers instead, along with the outgoing parameter registers of
the calling function.  In general it is assumed that the outgoing/globals
may be trashed at will by any function, thus caller-save is the assumed
protocol, but sparc has so many registers this is rarely needed.  Don't
worry, the compiler knows they're there.

>  Could I insert, say, asm("move %o5, %g2")
>  into the C programs?  Any side effect?  

Well, our compiler says "asm statement disables optimization", and I'd say
that was a side-effect.  It is much better to modify the assembler source
directly. 

>2. In addition, could I move address of a C variable into a specific
>   register?  For example,
>
>	  asm ("move ADDR(i), %g2"); /* move address of i to g2 */

Technically asm("set _i,%g2") would do it, but again it's a very bad idea.
This practice would not be much better than self-modifying code, i.e.
don't try it unless you really know what you're doing.

  CSnet:     tac at cs.brown.edu                          Ted Camus  
  ARPAnet:   tac%cs.brown.edu at relay.cs.net             Box 1910 CS Dept
  BITnet:    tac at browncs.BITNET                        Brown University
  "An ounce of example is worth a pound of theory."    Providence, RI 02912



More information about the Comp.sys.sun mailing list