[PATCH] Constant fold sqrt at compile time

Richard Henderson rth@redhat.com
Thu Oct 31 15:17:00 GMT 2002


On Fri, Oct 25, 2002 at 07:42:13PM -0600, Roger Sayle wrote:
> Can this now be replaced with the less
> restrictive "flag_signaling_nans", and evaluate everything
> except "sqrt(sNaN)"?

I expect so.

> I know that Brad Lucier has ideas on how the accuracy can be
> improved.  My understanding is that the current algorithm (or
> together with a minor tweak) is accurate to 2 ulps, but always
> under-estimates the result.  The HP technical report by Markstein
> recommends zeroing the last few bits of the mantissa, and then
> filling them in with a bit-at-a-time iterative algorithm (like
> the one you suggest).

Interesting.

The thing about the bit-at-a-time algorithm is that it's
easy to get the sticky bit set right, which means that 
rounding is then correct for all of the machine modes.

> My proposal is more efficient but requires the function:
> 
> void real_inc_ulps(REAL_VALUE_TYPE *r, enum machine_mode mode)
> 
> which will increment the value "r" by one ulps.

Well, really I'd rather the sqrt function be implemented with
the internal routines, which I think makes it a bit cleaner,
and makes this function trivial.  It's add_significand with one
of the significands with bit 1 set.


r~



More information about the Gcc-patches mailing list