http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50794
Bug #: 50794 Summary: [picochip] incorrect implementation of ashrsi3 for negative numbers Classification: Unclassified Product: gcc Version: 4.6.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: paulo.ma...@csr.com I was looking at the ashrsi3 implementation in picochip and I find something odd. I think it would generate incorrect results for negative numbers. Note, however that I have not tested the code, so this is through inspection only. Picochip ashrsi3.c contains the following piece of code: /* Given a word of sign bits, shift back left to create the destination sign bits. */ wordOfSignBits = __builtin_asri(value.s.high, 15); signWord = wordOfSignBits << reverseCount; result.s.high |= signWord; Note however that wordOfSignBits should be 0xffff for negative value.s.high and 0x0000 for positive value.s.high. However, this will either be 0x0000 for positive value.s.high or 0x0001 for negative value.s.high. This is because value.s.high is unsigned, so arithmetic shift will be performed as if on an unsigned value and the word will never contain the expected value. Replacing the above by: /* Given a word of sign bits, shift back left to create the destination sign bits. */ + HItype topword = value.s.high; + wordOfSignBits = __builtin_asri(topword, 15); - wordOfSignBits = __builtin_asri(value.s.high, 15); signWord = wordOfSignBits << reverseCount; result.s.high |= signWord;