public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: leon zadorin <leonleon77@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Re: Compile-time floating-point expressions and subsequent detection of possible overflows etc -- during the compile-time stage.
Date: Thu, 03 Nov 2011 14:28:00 -0000	[thread overview]
Message-ID: <CAPpySAbqg=d8AdjoTgqdUcqf7PDpHtC+K9AZ-DH+YqDcH6dBTQ@mail.gmail.com> (raw)
In-Reply-To: <20111103122956.GC3523@xvii.vinc17.org>

On 11/3/11, Vincent Lefevre <vincent+gcc@vinc17.org> wrote:
> On 2011-11-03 00:36:20 +1100, leon zadorin wrote:
>> I dont think that this is the point i am making... Gcc allows certain
>> optimization options eg -Ofast (4.6) where -ffast-math (even prior to
>> 4.6), and some other, unsafe wrt pedantic standard definitions,
>> optimization options become available (including, i think
>> floating-point constant folding opportunities).
>>
>> I am very happy with such options by the way so the question was not
>> about standard compliance (hence my original statement about the said
>> compile-time calculations being done under certain conditions, not all
>> the time and having nothing to do with c++03/11 standard
>> specifications).
>>
>> I am saying that having such, great, otimization options available it
>> would be super-helpful if there was a way to have a diagnostic/warning
>> about compile-time calculations producing non-finite floating point
>> values (whether via lib mpfr or otherwise).
>
> I'd say that this wouldn't be much useful, because similar problems
> can also occur at run time, and if you use options like -ffast-math,
> you won't be able to tell whether your program works correctly...
> unless you can prove that no overflows (etc.) can occur. But if you
> can do that, you no longer need GCC to do this for you for the
> particular case of compile-time calculations.

But as I had mentioned in my original post -- there is a way to detect
this at runtime, even if compiler optimizes based on presumptions of
finite math etc implied by -ffast-math.

If, as a statistical outlier, the two variables (whose values are only
known at run time) are say multiplied together and an overflow occurs
- the fpu hardware (for example) sets the fpu status registers to
indicate the overflow... which is what I was referring to in my
original post: "via reading the FPU status register, which hardware
itself may flag appropriately; or via the 'fetestexcept' et al
wrappers". One can even do the run time verification via an external
link to 'isfinite' function (compiled from a differently-optimized
translation unit without the -ffinite-math et al) - ie individually
guarding various expressions. The only thing being that 'fetestexcept'
is much more efficient in some cases (as once again I think i had
mentioned in my original post).

in other words - just as there is a run time after-the-fact way to
observe/detect unexpected non-finite values which is very useful in
some petformance-oriented deployment scenarios-- it would also be good
to do so for the compile-time stage also (ESP. when it is the compile
state which produces such values).

regards leon zadorin.

  reply	other threads:[~2011-11-03 14:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-02  4:31 leon zadorin
2011-11-02  9:01 ` Vincent Lefevre
2011-11-02  9:37   ` Andrew Haley
2011-11-02 13:36     ` leon zadorin
2011-11-03 12:30       ` Vincent Lefevre
2011-11-03 14:28         ` leon zadorin [this message]
2011-11-03 15:12           ` Vincent Lefevre
2011-11-03 15:56             ` leon zadorin
2011-11-03 12:15     ` Vincent Lefevre

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='CAPpySAbqg=d8AdjoTgqdUcqf7PDpHtC+K9AZ-DH+YqDcH6dBTQ@mail.gmail.com' \
    --to=leonleon77@gmail.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).