public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/61423] New: Incorrect conversion from unsigned int to floating point
@ 2014-06-05 15:52 lvqcl.mail at gmail dot com
  2014-06-05 15:54 ` [Bug c/61423] " lvqcl.mail at gmail dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: lvqcl.mail at gmail dot com @ 2014-06-05 15:52 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-06-18 20:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-05 15:52 [Bug c/61423] New: Incorrect conversion from unsigned int to floating point lvqcl.mail at gmail dot com
2014-06-05 15:54 ` [Bug c/61423] " lvqcl.mail at gmail dot com
2014-06-06  8:07 ` [Bug target/61423] " rguenth at gcc dot gnu.org
2014-06-06 10:28 ` ubizjak at gmail dot com
2014-06-06 15:30 ` ubizjak at gmail dot com
2014-06-06 15:37 ` ubizjak at gmail dot com
2014-06-06 15:42 ` ubizjak at gmail dot com
2014-06-06 17:45 ` uros at gcc dot gnu.org
2014-06-11 16:17 ` jakub at gcc dot gnu.org
2014-06-11 21:27 ` law at redhat dot com
2014-06-12 21:20 ` law at redhat dot com
2014-06-13 16:42 ` law at redhat dot com
2014-06-17  5:01 ` uros at gcc dot gnu.org
2014-06-18 20:02 ` uros at gcc dot gnu.org
2014-06-18 20:03 ` ubizjak at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).