[comp.sys.sun] Questions about SPARC's C compiler

icw@sam.cs.cmu.edu (I-Chen Wu) (06/02/90)

1. When I check some assembly codes, I realize global registers, g0,
   g1,...,etc, are rarely used.  Could I insert, say, asm("move %o5, %g2")
   into the C programs?  Any side effect?  

2. In addition, could I move address of a C variable into a specific
   register?  For example,

	routine() {
		int i;
		asm ("move ADDR(i), %g2"); /* move address of i to g2 */
		....
	}

Thank you in advance.

I-Chen Wu

tac@cs.brown.edu (Theodore A. Camus) (06/05/90)

>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@cs.brown.edu                          Ted Camus  
  ARPAnet:   tac%cs.brown.edu@relay.cs.net             Box 1910 CS Dept
  BITnet:    tac@browncs.BITNET                        Brown University
  "An ounce of example is worth a pound of theory."    Providence, RI 02912