This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Richard,
Following i describe what i believe to be a bug in the arm/thumb
code generation of the latest gcc, and also of gcc since at least 3.0.0.
We've been bedeviled for sometime by e.g. pow(10.0,0.2) returning 0.0
and by other occasional floating point bugs.
I just upgraded to newlib-1.10.0 and gcc-3.0.4, both of which are for
the moment reasonably current, and the problem is still there.
(Target is arm, running in thumb mode; optimization flag is -O).
After long tracing i finally narrowed this down to the following
compiler bug which can be summarized as:
(int j=0x3fe542a5)
newlib-1.10.0/newlib/libm/math/e_pow.c line 273:
if ((j&0x7fffffff) >= 0x4090cc00)
{
... under flow code...
}
The underflow code incorrectly executes because the generated assembly
code looks like:
(r5 is j == 0x3fe542a5)
lsl r3,r5,#1 (sets r5 to 0x7fca854a)
ldr r4,(pc-relative location containing 0x812197ff which is 2*0x4090cc00-1)
cmp r3,r4 (sets N=1,Z=0,C=0,V=1)
blt (past overflow code)
The blt instruction branches only if N!=V which is not the case here,
thus the underflow code executes (which should not be the case).
The correct instruction to use would have been BLS (with appropriate
fiddling of the constant).
The blt would make sense if r3 and r4 were really signed integers.
Although blt would have been appropriate for signed integers,
the optimization clearly(?) recognizes that positive quantities are being
compared (otherwise the optimization could not be done) and
the comparison must be treated as unsigned.
(I assume the point of the optimization was to avoid loading the
constant 0x7fffffff... a good thing to avoid).
Attached is the .c and .s files of a simple test case.
Thanks for your (otherwise) excellent work.
If you have time to produce a patch in the next week or so i will
probably have time to test it.
In any event, i'd appreciate an ack that you got this message.
Thanks
-Ted Merrill
ArrayComm, Inc.
ted@arraycomm.com
Attachment:
bug1.c
Description: bug1.c
Attachment:
bug1.c.o.s
Description: bug1.s
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |