Hi. I'm using the GCC compiler for PPC405 as delivered with Xilinx EDK 8.1. The exact version is: powerpc-eabi-gcc (GCC) 3.4.1 ( Xilinx EDK 8.1.1 Build EDK_I.19.3 190106 )
I found a bug in the code generation. My code is a serial receiver and uses an uninitialized uchar nData: uchar nBits; uchar nData; for (nBits=0; nBits<8; nBits++) { nData >>= 1; // the bug is related to this statement if (function()) nData |= 0x80; } Although nData is not initialized, the correct state after the first "nData >>= 1" statement would be any value between 0x00 and 0x7f. However, on my target board I found it to be >= 0x80. Looking at the disassembler output shows that the compiler used the following assembler instruction to implement the "nData >>= 1" statement: rlwinm r26,r26,31,24,31 // incorrect implementation, as generated by gcc It is a rotate-left by 31 bits (equals a rotate-right by 1 bit), and subsequent AND-mask with 0xFF (powerpc-eabi is a big endian machine). This command is not a correct implementation of the statement. It is only correct if bit 0 of R26 (which will become bit 31 after the rotate) happens to be 0. The correct implementation would be to use a different mask value, which ensures that the "new" bit 31 is 0 (mask 0x7F instead of 0xFF): rlwinm r26,r26,31,24,30 // corrected implementation I can work around this bug by initializing nData before the first use, because GCC will initialize all of r26 (including bit 0) . However I still consider it a bug that should be addressed. Keep on good work! Regards from Spain, Marc