The Terinary Operator does not generate conditional logic as expected. "If" works as expected.
Using GCC 4.5.1-or32-1.0rc4
Testcase: http://www.wuala.com/Deathbob/Files/OR32/Toolchain_T_OP_Error.zip/
Regards, Thomas
volatile uint32_t const SDRAM_GOOD = (uint32_t const)0x01000000; volatile uint32_t const SDRAM_BAD = (uint32_t const)0x02000000;
int main (int argc, char *argv []) { unsigned long i; unsigned long j; unsigned long bob = 0xdeadbeef;
/ This should work / for(i = 0; i < 480; ++i) { for(j = 0; j < 800; ++j) { if(i == 0) { SDRAM_GOODi*800+j = 0x00FFFFFF; } else { SDRAM_GOODi*800+j = (uint8_t)(j+bob+i); } } }
/ This does not work / for(i = 0; i < 480; ++i) { for(j = 0; j < 800; ++j) { SDRAM_BADi*800+j = (i == 0)?0x00FFFFFF:((uint8_t)(j+bob+i)); } }
/ Compare the two / for(i = 0; i < 480; ++i) { for(j = 0; j < 800; ++j) { if (SDRAM_GOODi*800+j != SDRAM_BADi*800+j) { printf ("SDRAM_GOOD%6d = 0x%08x, SDRAM_BAD%6d = 0x%08x\n", i800+j, SDRAM_GOOD[i800+j], i800+j, SDRAM_BAD[i800+j]); } } } }
</pre> <p> I compiled this with </p> <pre> or32-elf-gcc test.c -o test </pre> <p> And ran it with </p> <pre> or32-elf-sim --memory=64M test </pre> <p> No mismatches were reported. I should be surprised if GCC were generating defective code for ternary operators - these are fairly extensively tested in regression. </p> <p> Can you provide more details to help trace this problem. </p> <p> Jeremy </p> <p> -- <br /> Tel: +44 (1590) 610184<br /> Cell: +44 (7970) 676050<br /> SkypeID: jeremybennett<br /> Email: <a href="mailto:jeremy.bennett@embecosm.com">jeremy.bennett@embecosm.com</a><br /> Web: <a href="http://www.embecosm.com">www.embecosm.com</a> </p>