Re: Do not spill variables/registers on the stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mi, 2011-02-02 at 11:08 -0700, Jeff Law wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 02/02/11 10:34, Philip Herron wrote:
> 
> > 
> > I am not quite sure what you are asking/trying to do but the register
> > keyword is used to tell the compiler keep this variable inside any
> > available registers which is useful if your going to use it alot in a
> > piece of code i would imagine it could speed up things alot.
> GCC ignores the "register" keyword.

GCC does _not_ ignore the "register" keyword. The following code was
compiled with GCC version 4.4.5:

int main(void) {
        register int a = 1;
        register int b = -1;

        return a+b;
}

$ gcc -O0 -c test.c
$ objdump -d test.o

...
  20:	3b a0 00 01 	li      r29,1
  24:	3b c0 ff ff 	li      r30,-1
  28:	7c 1d f2 14 	add     r0,r29,r30
  2c:	7c 03 03 78 	mr      r3,r0

and if we remove the register keyword:

  18:	38 00 00 01 	li      r0,1
  1c:	90 1f 00 0c 	stw     r0,12(r31)
  20:	38 00 ff ff 	li      r0,-1
  24:	90 1f 00 08 	stw     r0,8(r31)
  28:	81 3f 00 0c 	lwz     r9,12(r31)
  2c:	80 1f 00 08 	lwz     r0,8(r31)
  30:	7c 09 02 14 	add     r0,r9,r0
  34:	7c 03 03 78 	mr      r3,r0

Kind regards,
Stefan



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux