[Bug c/61423] New: Incorrect conversion from unsigned int to floating point
lvqcl.mail at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Jun 5 15:52:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61423
Bug ID: 61423
Summary: Incorrect conversion from unsigned int to floating
point
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: lvqcl.mail at gmail dot com
The attached program works incorrectly when compiled for i686 with '-O3 -msse2'
or '-O1 -ftree-vectorize -msse2'.
GCC compiles the function
#define N 1024
static unsigned int A[N];
double func (void)
{
unsigned int sum = 0;
unsigned i;
double t;
for (i = 0; i < N; i++) sum += A[i];
t = sum; /* uint32 -> double */
return t;
}
into the following:
01: pxor %xmm0, %xmm0
02: movl $_A, %eax
03: L2:
04: paddd (%eax), %xmm0
05: addl $16, %eax
06: cmpl $_A+4096, %eax
07: jne L2
08: movdqa %xmm0, %xmm1
09: subl $28, %esp
10: psrldq $8, %xmm1
11: paddd %xmm1, %xmm0
12: movdqa %xmm0, %xmm1
13: psrldq $4, %xmm1
14: paddd %xmm1, %xmm0
15: movq %xmm0, 8(%esp)
16: fildq 8(%esp)
17: addl $28, %esp
18: ret
After the line 07: xmm0 contains four partial sums.
After the line 14: lower 4 bytes of xmm0 contain the total sum, the rest 12
bytes contain garbage.
Lines 15 and 16: *eight* bytes from xmm0 are stored in memory and then loaded
into an FPU register.
According to the message from Robert Kausch (
http://lists.xiph.org/pipermail/flac-dev/2014-June/004723.html ) this bug
exists since GCC 4.4.
More information about the Gcc-bugs
mailing list