public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "merkert at comcast dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/34678] New: Optimization generates incorrect code with -frounding-math option Date: Fri, 04 Jan 2008 18:56:00 -0000 [thread overview] Message-ID: <bug-34678-5307@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2008-01-04 17:49 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-01-04 18:56 merkert at comcast dot net [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-34678-5307@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).