Symbian
Symbian OS Library

FAQ-0433 ARM GCC Compiler register usage?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Utilities & Build Tools
Created: 11/11/99 Modified: 09/01/2001
Number: FAQ-0433
Platform: Not Applicable

Question:
Whilst optimising my code I noticed that GCC doesn't use register R11 in the code it generates.
Can I use R11 safely in my code and does it need to be preserved across calls?


Answer:
In marm release builds we pass -fomit-frame-pointer to GCC. From the GCC documentation: "This stops the compiler keeping the frame pointer in a register for functions that don't need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. "

We expect that you can safely use fp as a preserved register in release code; however in debug builds we don't say -fomit-frame-pointer and so the register would be reserved.

Note that in roll-your-own assembler code, you should preserve the caller's fp if you use it as a scratch register - this would be done by any routine compiled without the -fomit-frame-pointer flag.

Background

The ARM Register names come from the ARM Procedure calling standard. Here's the full list:

r0 a1 argument 1 / integer result / scratch register
r1 a2 argument 2 / scratch register
r2 a3 argument 3 / scratch register
r3 a4 argument 4 / scratch register
r4 v1 register variable
r5 v2 register variable
r6 v3 register variable
r7 v4 register variable
r8 v5 register variable
r9 sb/v6 static base / register variable
r10 sl/v7 stack limit / stack chunk handle / register variable
r11 fp frame pointer
r12 ip scratch register / new-sb in inter-link-unit calls
r13 sp lower end of current stack frame
r14 lr link address / scratch register
r15 pc program counter

Note that 'fp' and 'r11' are the same register.