public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/34678]  New: Optimization generates incorrect code with -frounding-math option
@ 2008-01-04 18:56 merkert at comcast dot net
  2008-01-05 12:08 ` [Bug middle-end/34678] Optimization generates incorrect code with -frounding-math option (#pragma STDC FENV_ACCESS not implemented) rguenth at gcc dot gnu dot org
                   ` (15 more replies)
  0 siblings, 16 replies; 37+ messages in thread
From: merkert at comcast dot net @ 2008-01-04 18:56 UTC (permalink / raw)
  To: gcc-bugs

The following function produces only a single division operation even when
compiling with -frounding-math. I had read in a different PR (29186) that the
pragma FENV_ACCESS is not supported, but that -frounding-math should produce
the same effect (recognizing that the option is experimental as well).

Here's the function:

cat > div.c <<EOF
#include <fenv.h>

void xdiv (double x, double y, double* lo, double* hi)
{
  #pragma STDC FENV_ACCESS ON 

  fesetround(FE_DOWNWARD);
  *lo = x/y;
  fesetround(FE_UPWARD);
  *hi = x/y;
}
EOF
gcc -O -frounding-math div.c -S

I get the following assembly-fragment on 
xdiv:
.LFB2:
        movq    %rbx, -24(%rsp)
.LCFI0:
        movq    %rbp, -16(%rsp)
.LCFI1:
        movq    %r12, -8(%rsp)
.LCFI2:
        subq    $56, %rsp
.LCFI3:
        movsd   %xmm0, 24(%rsp)
        movsd   %xmm1, 16(%rsp)
        movq    %rdi, %rbx
        movq    %rsi, %r12
        movl    $1024, %edi
        call    fesetround
        movsd   24(%rsp), %xmm0
        divsd   16(%rsp), %xmm0
        movsd   %xmm0, 8(%rsp)
        movq    8(%rsp), %rbp
        movq    %rbp, (%rbx)
        movl    $2048, %edi
        call    fesetround
        movq    %rbp, (%r12)
        movq    32(%rsp), %rbx
        movq    40(%rsp), %rbp
        movq    48(%rsp), %r12
        addq    $56, %rsp
        ret
.LFE2:

Here's also a simple driver program:
#include <stdio.h>
#include <assert.h>

extern void xdiv(double x, double y, double* lo, double* hi);

int main(int argc, char** argv)
{
  double z1,z2;

  xdiv(1,10,&z1,&z2);
  printf(" rounding down 1/10 is %30.20g \n", z1);
  printf(" rounding up 1/10 is %30.20g \n", z2);
  assert(z1<z2 && "Rounding mode is not working");
  return 0;
}

I'm sure this is supposed to work in std c, but I'm not sure that it is
supposed to work in gcc yet (according to http://gcc.gnu.org/wiki/GeertBosch it
might). It doesn't work on either x86-64 nor i386.


-- 
           Summary: Optimization generates incorrect code with -frounding-
                    math option
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: merkert at comcast dot net
 GCC build triplet: 4.3.0 20071123


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678


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

end of thread, other threads:[~2023-01-07 12:14 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-34678-4@http.gcc.gnu.org/bugzilla/>
2010-10-26 10:33 ` [Bug middle-end/34678] Optimization generates incorrect code with -frounding-math option (#pragma STDC FENV_ACCESS not implemented) paolo.carlini at oracle dot com
2011-02-08  2:02 ` pinskia at gcc dot gnu.org
2011-04-01 19:22 ` pinskia at gcc dot gnu.org
2013-11-11  9:30 ` nmm1 at cam dot ac.uk
2013-11-11 13:37 ` vincent-gcc at vinc17 dot net
2013-11-11 16:38 ` joseph at codesourcery dot com
2013-11-11 17:32 ` nmm1 at cam dot ac.uk
2014-01-10 11:40 ` vincent-gcc at vinc17 dot net
2014-01-14 14:58 ` vincent-gcc at vinc17 dot net
2014-01-14 15:13 ` nmm1 at cam dot ac.uk
2014-01-14 15:52 ` vincent-gcc at vinc17 dot net
2014-01-14 17:22 ` nmm1 at cam dot ac.uk
2014-01-14 23:16 ` vincent-gcc at vinc17 dot net
2014-02-16 10:03 ` jackie.rosen at hushmail dot com
2020-04-16 15:35 ` vincent-gcc at vinc17 dot net
2023-01-06 17:29 ` pinskia at gcc dot gnu.org
2023-01-06 17:31 ` pinskia at gcc dot gnu.org
2023-01-06 19:29 ` tkoenig at gcc dot gnu.org
2023-01-06 22:14 ` tkoenig at gcc dot gnu.org
2023-01-07 11:14 ` tkoenig at gcc dot gnu.org
2023-01-07 12:14 ` tkoenig at gcc dot gnu.org
2008-01-04 18:56 [Bug c/34678] New: Optimization generates incorrect code with -frounding-math option merkert at comcast dot net
2008-01-05 12:08 ` [Bug middle-end/34678] Optimization generates incorrect code with -frounding-math option (#pragma STDC FENV_ACCESS not implemented) rguenth at gcc dot gnu dot org
2008-01-05 16:48 ` merkert at comcast dot net
2008-01-05 21:00 ` joseph at codesourcery dot com
2008-01-05 21:29 ` rguenth at gcc dot gnu dot org
2008-01-06 16:21 ` joseph at codesourcery dot com
2008-01-06 17:19 ` rguenth at gcc dot gnu dot org
2008-01-06 18:03 ` joseph at codesourcery dot com
2008-10-15 15:44 ` rguenth at gcc dot gnu dot org
2008-10-15 21:31 ` vincent at vinc17 dot org
2008-10-15 22:15 ` rguenth at gcc dot gnu dot org
2008-10-15 22:35 ` vincent at vinc17 dot org
2008-10-16  9:46 ` rguenth at gcc dot gnu dot org
2008-10-16 11:58 ` merkert at comcast dot net
2008-10-16 14:21 ` vincent at vinc17 dot org
2008-10-16 16:40 ` joseph at codesourcery dot com
2008-10-16 17:41 ` vincent at vinc17 dot org

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).