This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Constant fold sqrt at compile time
- From: Richard Henderson <rth at redhat dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 25 Oct 2002 17:05:06 -0700
- Subject: Re: [PATCH] Constant fold sqrt at compile time
- References: <Pine.LNX.4.33.0210162316360.10993-100000@www.eyesopen.com>
On Wed, Oct 16, 2002 at 11:45:50PM -0600, Roger Sayle wrote:
> + /* Calculate the square root of X in mode MODE, and store the result
> + in R. Returns true if this doesn't trap and doesn't set errno. */
> +
> + bool
> + real_sqrt (r, mode, x)
I don't see how "set errno" is relevant. If you go ahead and
return NaN, then
/* Test the result; if it is NaN, set errno=EDOM because
the argument was not in the domain. */
emit_cmp_and_jump_insns (target, target, EQ, 0, GET_MODE (target),
0, lab1);
will evaluate to true at compile time, which will arrange for
errno to get set appropriately.
> + /* Newton's iteration for reciprocal sqrt, i */
> + for (iter = 0; iter < 16; iter++)
[...]
> + /* Final result is original value, x, multiplied by i. */
> + real_arithmetic (&t, MULT_EXPR, &i, x);
I know that there are iterative integer solutions that generate
one bit at a time, just like the standard divide loop. I wonder
if those more accurate results? Certainly I can see avoiding
double-rounding issues that way...
r~