[Bug c++/88630] New: Incorrect float negating together with convertion to int on SH4
zavadovsky.yan at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Dec 28 13:43:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88630
Bug ID: 88630
Summary: Incorrect float negating together with convertion to
int on SH4
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: zavadovsky.yan at gmail dot com
Target Milestone: ---
Created attachment 45299
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45299&action=edit
main.cpp: code to trigger the bug
Hello.
I have some strange behavior with such simple code:
<code>
float float_val = ....;
int int_val = -float_val;
</code>
Problem is in "losing" negation.
Real result of code execution looks like
<code>
int int_val = float_val;
</code>
E.g. if float_val==12.0f I am awaiting that int_val will be equal -12;
And vice versa.
But I got int_val==12 when float_val==12.0f;
I.e. there was no negation.
There is no such bug in GCC-4.x (checked 4.7.3 and 4.9.4).
It begins since 5.x(I checked 5.4.0, 6.3.0, 7.4.0, 8.2.0).
There is no such bug on x86-64, mips and arm with 4.6/4.7 and 6.3.0 compiler
versions.
Assembler from GCC-8.2.0 - works bad:
<code>
sts fpscr,r1
mov.l .L2,r2
fneg fr5
xor r2,r1
lds r1,fpscr
ftrc fr5,fpul
sts fpul,r0
xor r2,r1
lds r1,fpscr
rts
</code>
Assembler from GCC-4.9.4 - works good:
<code>
mov.l .L2,r1
lds.l @r1+,fpscr
add #-4,r1
fneg fr5
add #4,r1
ftrc fr5,fpul
sts fpul,r0
rts
lds.l @r1+,fpscr
</code>
I can see that FPU 'calculation' commands wasn't changed between compiler
versions.
But there was change of work with FPU status/control register.
Can somebody say is it compiler bug or there is a problem with my code?
More information about the Gcc-bugs
mailing list