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] Constant fold sqrt at compile time


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~


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