Do not spill variables/registers on the stack
Stefan Schulze Frielinghaus
stefan@seekline.net
Wed Feb 2 18:36:00 GMT 2011
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
More information about the Gcc-help
mailing list