From: Segher Boessenkool <segher@kernel.crashing.org>
To: David Brown <david.brown@hesbynett.no>
Cc: gcc-help@gcc.gnu.org
Subject: Re: pragma GCC optimize prevents inlining
Date: Sun, 7 Jan 2024 11:51:44 -0600 [thread overview]
Message-ID: <20240107175144.GF19790@gate.crashing.org> (raw)
In-Reply-To: <unc13l$kv$1@ciao.gmane.io>
On Sat, Jan 06, 2024 at 06:02:45PM +0100, David Brown wrote:
> On 05/01/2024 19:19, Segher Boessenkool wrote:
> >That's not the point. A program can be perfectly fine, with bounded
> >errors and all, and then -ffast-math will typically completely destroy
> >all that, and replace all arithmetic by the equivalent of a dice roll.
>
> The only difference between IEEE calculations and -ffast-math
> calculations is that with IEEE, the ordering and rounding is controlled
> and consistent.
No, that is not the only difference.
'-ffast-math'
Sets the options '-fno-math-errno', '-funsafe-math-optimizations',
'-ffinite-math-only', '-fno-rounding-math', '-fno-signaling-nans',
'-fcx-limited-range' and '-fexcess-precision=fast'.
Many of those do much more than what you say, can result in the compiler
generating completely different code.
> For any given /single/ arithmetic operation that is
> performed, each can have the same amount of rounding error or error due
> to the limited length of the mantissa. Agreed?
I don't understand what you mean to say even.
> >>The rounding errors in -ffast-math will be very similar to those in IEEE
> >>mode, for normal numbers.
> >
> >No, not at all. Look at what -fassociative-math does, for example.
> >This can **and does** cause the loss of **all** bits of precision in
> >certain programs. This is not theoretical. This is real.
>
> a = 1e120;
> b = 2;
>
> x = (a + b) - a;
>
> IEEE rules will give "x" equal to 1e120 - mathematically /completely/
> wrong. -ffast-math will give "x" equal to 2, which is mathematically
> precisely correct.
The IEEE result is 0. Which is the **exactly correct** result. This is
a computer program, not some formulas that you can manipulate at will.
> >The -ffast-math flag can only reasonably be used with programs that did
> >not want any specific results anyway. It would be even faster (and just
> >as correct!) to always return 0.
>
> That is simply wrong.
It is an exaggeration for dramatic effect, but it is fundamentally
correct.
Segher
next prev parent reply other threads:[~2024-01-07 17:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 9:01 Hashan Gayasri
2024-01-04 9:27 ` LIU Hao
2024-01-05 0:56 ` Hashan Gayasri
2024-01-04 14:51 ` David Brown
2024-01-04 15:03 ` Segher Boessenkool
2024-01-04 15:24 ` David Brown
2024-01-04 16:37 ` Richard Earnshaw
2024-01-09 13:38 ` Florian Weimer
2024-01-04 16:55 ` Segher Boessenkool
2024-01-05 14:24 ` David Brown
2024-01-05 15:00 ` Segher Boessenkool
2024-01-05 15:53 ` David Brown
2024-01-05 18:19 ` Segher Boessenkool
2024-01-06 17:02 ` David Brown
2024-01-07 17:51 ` Segher Boessenkool [this message]
2024-01-07 18:36 ` Gabriel Ravier
2024-01-08 15:53 ` David Brown
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=20240107175144.GF19790@gate.crashing.org \
--to=segher@kernel.crashing.org \
--cc=david.brown@hesbynett.no \
--cc=gcc-help@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).