gcc 2.95.3 for ppc uses GPR 0 in addi

Franz Sirl Franz.Sirl-kernel@lauterbach.com
Thu Jul 27 10:50:00 GMT 2000


At 19:15 27.07.00, Karl Cooper wrote:
>The following C code with user-provided asm code
>causes gcc to produce incorrect assembler output:
>void waitfor (int delta)
>{
>   asm
>   (
>     "addi    %%r4,%0,1\n\t"
>     "mftb    %%r6\n\t"
>     "add     %%r4,%%r4,%%r6\n\t"
>     "1: mftb %%r5\n\t"
>     "cmpl    0,%%r4,%%r5\n\t"
>     "bgt     1b\n\t"
>     :
>     : "r" (delta)
^^^^^^^^^^^^^^^^^^

>     : "r4", "r5", "r6"
>   );
>}
>
>
>The resulting .s file chooses r0 to load the input parameter,
>resulting in an addi  r4,r0,1 instruction which effectively
>zeroes the input parameter.

But you explicitly allowed r0-r31 by using "r", if you want to restrict the 
range to r1-r31, use "b". This is a common programming error when using 
inline assembly on PPC.

Franz.



More information about the Gcc-bugs mailing list