This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: IEEE inexact-flag not working on the Alpha (despite -mieee-with-inexact)?
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: Roberto Bagnara <bagnara at cs dot unipr dot it>, gcc at gcc dot gnu dot org, The Parma Polyhedra Library developers' list <ppl-devel at cs dot unipr dot it>
- Date: Thu, 18 Sep 2008 17:16:04 +0000 (UTC)
- Subject: Re: IEEE inexact-flag not working on the Alpha (despite -mieee-with-inexact)?
- References: <48D23D14.2030006@cs.unipr.it> <jek5d9hcz1.fsf@sykes.suse.de>
On Thu, 18 Sep 2008, Andreas Schwab wrote:
> Roberto Bagnara <bagnara@cs.unipr.it> writes:
>
> > $ cat sf.cc
> > #include <fenv.h>
> > #include <cstdio>
> >
> > int main() {
> > float x = 2;
> > float y = 3;
> > feclearexcept(FE_INEXACT);
> > x = x / y;
> > printf("%d %.1000g\n", fetestexcept(FE_INEXACT) != 0, x);
>
> You need to enable the FENV_ACCESS pragma (which is not yet implemented)
> to get defined behaviour.
It's more complicated than that.
In theory, GCC represents parts of the FENV_ACCESS pragma with the options
-ftrapping-math and -frounding-math, enables -ftrapping-math by default,
disables -frounding-math by default, documents that -frounding-math will
determine the default setting of FENV_ACCESS in future, and documents that
-frounding-math is experimental and that some optimizations affected by
rounding mode may not have been found and disabled.
In theory, -ftrapping-math should suffice to ensure the correct set of
exceptions are generated between any two calls to fenv.h functions (or
between calls to other functions that might call those functions
indirectly). (As per C99 Annex F, there is no requirement to generate an
exception the correct number of times as long as it's generated at least
once iff it would be generated at least once in the abstract machine.)
In practice, there are many cases where -ftrapping-math does not cause the
right exceptions to be generated, or where spurious exceptions are
generated, and a few open PRs for such cases. Inexact folding without
generating the inexact exception is only one example. Furthermore, the
results will vary between GCC versions and target processors and
optimization levels.
It's my suspicion that if we implement everything needed to preserve
exceptions properly in accordance with Annex F, it will turn out there is
a significant performance cost to the default -ftrapping-math mode and we
will need to consider whether the option can be split up so parts can be
disabled selectively.
--
Joseph S. Myers
joseph@codesourcery.com