I have some problems with using inline PowerPC assembly in GCC (4.0.1).
Consider the following code:
void save_fp_register(double* buffer)
{
asm("stfd F0, 0(%0)" : : "r" (buffer) );
}
When compiled with -Os the generated code becomes
save_fp_register:
stfd F0, 0(3)
blr
Which is OK; the input parameter comes in r3 which is used directly in
the stfd operation. However, when compiled with -O0 (no optimization)
the generated code instead becomes
save_fp_register:
stwu 1,-24(1)
stw 31,20(1)
mr 31,1
stw 3,8(31)
lwz 0,8(31)
stfd F0, 0(0) <-- error
lwz 11,0(1)
lwz 31,-4(11)
mr 1,11
blr
The input parameter r3 is transferred to r0, which is used in the stfd
operation. However, for this particular operation r0 means 0 -- not the
value stored in r0 -- which means that the machine will actually try to
store the value at address 0x0.
Is this a bug in GCC or is it my code that is messed up?
-- Stefan