SPRAB89A September 2011 – March 2014
In order to encourage the use of compressible instructions, the register save/restore code is slightly different for some C64x+ functions.
Ordinarily, the compiler allocates the entire frame with one SP decrement and then saves the callee-saved registers with SP-relative writes.
STW B14, *SP--[12]
STDW A15:A14, *SP[5]
STDW A13:A12, *SP[4]
STDW A11:A10, *SP[3]
STDW B13:B12, *SP[2]
STDW B11:B10, *SP[1]
In compact frame mode, the compiler instead generates a series of SP-auto-decrementing stores for each register pair.
STW B14, *SP--[2]
STDW A15:A14, *SP--
STDW A13:A12, *SP--
STDW A11:A10, *SP--
STDW B13:B12, *SP--
STDW B11:B10, *SP--
For this case, the stack layout is the same. However, the stack layout can be different for different saved register subsets. For instance, suppose we need to save A10, A11, B10, B11, and B3, and we choose to use the compact frame layout to save code size. The traditional layout will make the most efficient use of stack space:
STW A11, *SP--[6]
STW A10, *+SP[5]
STW B3, *+SP[4]
STW B11, *+SP[3]
STW B10, *+SP[2]
However, the compact frame layout will leave multiple holes in the register save area in order to use more compressible SP decrement instructions. Since every push must decrement SP by 8 (for interrupt safety), the compiler tries to push members of register pairs together; if it cannot, it must push a single register into a double word, making a hole in the save area.
STW A11, *SP--[2]
STW A10, *SP--[2]
STDW B11:B10, *SP--
STW B3, *SP--[2]