public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Brown <david@westcontrol.com>
To: Miles Bader <miles@gnu.org>
Cc: David Brown <david.brown@hesbynett.no>,
	 Dario Saccavino <kathoum@gmail.com>,
	Jonathan Wakely <jwakely.gcc@gmail.com>, Ico <gcc@zevv.nl>,
	 gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Floating point performance issue
Date: Wed, 21 Dec 2011 16:49:00 -0000	[thread overview]
Message-ID: <4EF1C970.5040001@westcontrol.com> (raw)
In-Reply-To: <CADCnXoaD8e-EzYd55egeYVVfsV5H5MkARcARPeQOWjoLH9AFyg@mail.gmail.com>

On 21/12/2011 10:22, Miles Bader wrote:
> 2011/12/21 David Brown<david@westcontrol.com>:
>> think I disagree a little on what you describe as false positives, and how
>> much of a problem they are.  Basically, I believe that if you can't be sure
>> that the code is consistent and correct in all circumstances, including
>> different optimisation levels, then it's bad code - and it is fair to give a
>> warning.  So I would want a warning on your "zot" code regardless of how it
>> is implemented - to my mind, that's not a false positive even if zot() were
>> a macro expanding to "0.f". It's bad code style to rely on it, so give a
>> warning.
>
> You seemed to have misunderstood what I'm trying to illustrate by the
> two versions of "zot."
>
> They are examples of two _fundamentally different_ operations.  If zot
> returns a constant 0.f in certain cases, obviously it needs to make
> that fact a documented part of its interface ("zot returns an exact
> value 0.f when XXX happens").   The "return ...sin..." case, on the
> other hand is an arbitrary calculation, for which interface of zot
> would not make such guarantees.
>
> Given the first version of zot, then, any subsequent comparison with
> 0.f, then, is _not_ relying on implementation details, it's relying on
> a documented guarantee.  That's certainly not "bad coding style."
>
> However, the compiler has no way of knowing about this guarantee, so
> any warning code needs to be conservative, and only warn when it's
> quite clear that something dodgy is happening.
>

I think our key difference of opinion here is that you want a warning 
only when it is quite clear that "something dodgy" is happening - I want 
the warning unless it is quite clear that something dodgy is /not/ 
happening.  I think it is bad coding style to write something that is 
not clearly correct - "might be right, might be dodgy" is, to me, simply 
"dodgy" and I want the warning.

So I'm pretty happy with the -Wfloat-equal flag - as I see it, there are 
no false positives.  One improvement might be to override it with double 
parenthesis, so that "if ((x == 0.1f))" would not give a warning (in the 
same way as for "if ((x = nextChar()))" avoids the "-Wparentheses" warning.

mvh.,

David


  reply	other threads:[~2011-12-21 11:58 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-20  9:52 Ico
2011-12-20 10:05 ` Marcin Mirosław
2011-12-20 10:20   ` Ico
2011-12-20 10:34     ` Jonathan Wakely
2011-12-20 10:43       ` Ico
2011-12-20 11:24       ` Vincent Lefevre
2011-12-20 11:51         ` Dario Saccavino
2011-12-20 12:02           ` Ico
2011-12-20 12:12           ` Vincent Lefevre
2011-12-20 12:28             ` Tim Prince
2011-12-20 12:43             ` Segher Boessenkool
2011-12-20 13:02               ` Vincent Lefevre
2011-12-20 19:51                 ` Segher Boessenkool
2011-12-20 21:02                   ` Vincent Lefevre
2011-12-21  4:36                     ` Segher Boessenkool
2011-12-21  6:15                       ` Segher Boessenkool
2011-12-23 20:25                         ` Vincent Lefevre
2011-12-20 13:43             ` David Brown
2011-12-20 13:58               ` Vincent Lefevre
2011-12-20 14:25                 ` David Brown
2011-12-20 15:05                   ` Vincent Lefevre
2011-12-20 15:44                     ` David Brown
2011-12-20 16:18                       ` Vincent Lefevre
2011-12-20 22:32                         ` David Brown
2011-12-23 20:11                           ` Vincent Lefevre
2011-12-24  7:38                             ` Vincent Lefevre
2011-12-24 11:11                             ` David Brown
2011-12-26  1:15                               ` Vincent Lefevre
2011-12-26 11:48                                 ` David Brown
2011-12-26 13:07                                   ` Vincent Lefevre
2011-12-26 13:37                                     ` Tim Prince
2011-12-26 14:01                                       ` Vincent Lefevre
2011-12-26 14:39                                         ` Tim Prince
2011-12-26 16:40                                           ` Vincent Lefevre
2011-12-21  1:19                       ` Miles Bader
2011-12-21  2:19                         ` David Brown
2011-12-21  4:03                           ` Miles Bader
2011-12-21  8:32                             ` David Brown
2011-12-21  9:02                               ` Miles Bader
2011-12-21  9:23                                 ` David Brown
2011-12-21 11:58                                   ` Miles Bader
2011-12-21 16:49                                     ` David Brown [this message]
2011-12-22  3:23                                       ` Miles Bader
2011-12-23 21:15                               ` Vincent Lefevre
2011-12-24 17:18                                 ` David Brown
2011-12-26  8:12                                   ` Vincent Lefevre
2011-12-26 13:00                                     ` David Brown
2011-12-26 13:22                                       ` Vincent Lefevre
2011-12-20 15:45                     ` Jeff Kenton
2011-12-20 11:44     ` David Brown
2011-12-20 11:49       ` David Brown
2011-12-20 10:46 ` Marc Glisse
2011-12-20 11:11   ` Ico
2011-12-20 11:16   ` Vincent Lefevre
2011-12-20 12:00     ` Vincent Lefevre
2011-12-20 12:21 ` Tim Prince

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=4EF1C970.5040001@westcontrol.com \
    --to=david@westcontrol.com \
    --cc=david.brown@hesbynett.no \
    --cc=gcc-help@gcc.gnu.org \
    --cc=gcc@zevv.nl \
    --cc=jwakely.gcc@gmail.com \
    --cc=kathoum@gmail.com \
    --cc=miles@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).