public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@wasabisystems.com>
To: gcc@gcc.gnu.org
Subject: Re: -ffast-math and floating point reordering
Date: Thu, 25 Mar 2004 06:05:00 -0000	[thread overview]
Message-ID: <m3u10dhg82.fsf@gossamer.airs.com> (raw)
In-Reply-To: <20040324170719.A12420@synopsys.com>

Joe Buck <Joe.Buck@synopsys.COM> writes:

> If -ffast-math is specified, what should we do?  One option is to use the
> K&R rule and free-associate at will.  I feel uncomfortable with that
> because of the major loss in accuracy that can result.  If, however, we
> implement support for the Fortran rules, one option would be to relax
> order of evaluation when there are no parentheses (like Fortran), another
> would be to just leave the order the same.

-ffast-math is documented in terms of turning on a set of other
options.  So another issue is: if we add support for permitting the
addition of a+b+c in any order, should we put that under
-funsafe-math-optimizations (currently implied for -ffast-math), or
should we put it under another option (-fassociative-math?).  If we
choose the latter alternative, should that new option be set by
-ffast-math, or only by explicit use?

My vote, at least right now, would be to add -fassociative-math to
mean that gcc is permitted to reassociate math expressions at will,
regardless of the presence of parentheses.  And -ffast-math should
imply -fassociative-math.  That is, with -ffast-math, (a+b)+c may be
evaluated as a+(b+c).

My rationale is that people who are paying close attention to their
floating point arithmetic should generally not use -ffast-math.  But
adding another option for this will permit people to pay close
attention to floating point arithmetic to use -ffast-math
-fno-associative-math.  In general I'm not in favor of giving people
too many knobs.  But I think this one is OK because it can be clearly
expressed in terms of its effect on the code that people write (as
opposed to many of the knobs which are expressed in terms of gcc's
internal optimizations).

People who do not pay close attention to floating point arithmetic,
and who use -ffast-math, are saying that they want the fastest
possible execution, and that their floating point code is written
accordingly.  I believe that implies that reassociating floating point
operations is acceptable when it will produce faster code.

I don't think this type of reassociation fits under
-funsafe-math-options, because it doesn't really fit the description
of that option in the documentation.  That option is described in
terms of assuming that values are in domain and results are in range.
That is different from associativity.

Ian

  reply	other threads:[~2004-03-25  1:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-25  6:03 Joe Buck
2004-03-25  6:05 ` Ian Lance Taylor [this message]
2004-03-25 11:27   ` Robert Dewar
2004-03-25 11:31     ` Ian Lance Taylor
2004-03-25 11:55       ` Ben Elliston
2004-03-25 12:37       ` Robert Dewar
2004-03-25 10:22 ` Robert Dewar
2004-03-25 18:28   ` Joe Buck
2004-03-25 18:38     ` Dave Korn
2004-03-26 20:06     ` Robert Dewar
2004-03-26 20:18       ` Joe Buck
2004-03-25 16:12 ` Paul Koning
2004-03-25 18:46   ` Dale Johannesen
2004-03-25 20:11     ` Geert Bosch
2004-03-27  1:51     ` Robert Dewar
2004-03-27  2:39       ` Dale Johannesen
2004-03-26 18:18 ` law
2004-03-26 18:37   ` Joe Buck
2004-03-26 18:46     ` Diego Novillo
2004-03-26 19:03       ` Richard Guenther
2004-03-26 19:54         ` Fariborz Jahanian
2004-03-26 20:19         ` law
2004-03-26 22:08           ` Joe Buck
2004-03-27  0:42             ` Richard Henderson
2004-03-26 22:12     ` Joseph S. Myers
2004-03-26 21:48   ` Laurent GUERBY
2004-03-26 11:20 Bradley Lucier
2004-03-26 18:33 Robert Dewar
2004-03-26 22:22 Chris Lattner
2004-03-26 22:27 ` Chris Lattner

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=m3u10dhg82.fsf@gossamer.airs.com \
    --to=ian@wasabisystems.com \
    --cc=gcc@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: link
Be 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).