This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Optimize abs(x) < 0.0


Roger Sayle wrote:

> > Now computer hardware is forced to project that three valued logic onto a
> > two valued logical "true, false" dichotomy.  The solution chosen is to have
> > both comparisons above return "false".  That means that to check for a NaN
> > and use a > or <= comparison, you have to use *both*, else the NaN will
> > just escape your check.
> 
> When applying a code transformation it is sufficient to guarantee that
> the behaviour of the transformed code is the same as the original.
> In this case, I don't have to explicitly "check for a NaN" with two
> comparisons iff the optimized code produces the same results in the
> presence of NaNs and finite values.

Yep, rethinking this, it is the original code writer who should make sure
that abs(a) < 0.0 is the correct check, i.e.:

> [You might also appreciate that "x == x" is a better explicit check
> for finite vs. NaN that would require only a single comparison]

He/she should have done the above check.

The code in the patch is OK because it doesn't introduce a hole where there
wasn't one before :-)

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]