This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/50794] New: [picochip] incorrect implementation of ashrsi3 for negative numbers
- From: "Paulo.Matos at csr dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 19 Oct 2011 14:26:09 +0000
- Subject: [Bug target/50794] New: [picochip] incorrect implementation of ashrsi3 for negative numbers
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: Paulo.Matos@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;