public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: David Brown <david@westcontrol.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: pragma GCC optimize prevents inlining
Date: Fri, 5 Jan 2024 12:19:26 -0600	[thread overview]
Message-ID: <20240105181926.GD19790@gate.crashing.org> (raw)
In-Reply-To: <un98lv$sfg$1@ciao.gmane.io>

On Fri, Jan 05, 2024 at 04:53:35PM +0100, David Brown via Gcc-help wrote:
> >-ffast-math is allowed to introduce any rounding error it wants.  Which
> >can (in a loop for example) easily introduce unlimited rounding error,
> >bigger than the actual result.  And this is not just theoretical either.
> >
> 
> Normal maths mode can also lead to rounding errors that can build up - 
> the fact that rounding is carefully specified with IEEE does not mean 
> there are no errors (compared to the theoretical perfect real-number 
> calculation).

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.

That has nothing to do with the fact that all floating point arithmetic
is an approximation to real arithmetic (arithmetic on real numbers).
The semantics of 754 (or any other standard followed) make it clear what
the exact behaviour should be, and -ffast-math tells the compiler to
ignore that and do whatever instead.  You cannot have reasonable
programs that way.

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

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.


Segher

  reply	other threads:[~2024-01-05 18:20 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 [this message]
2024-01-06 17:02                 ` David Brown
2024-01-07 17:51                   ` Segher Boessenkool
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=20240105181926.GD19790@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=david@westcontrol.com \
    --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).