On 5/9/08, Paolo Bonzini <[EMAIL PROTECTED]> wrote:
>  The idea is to use integer arithmetic to compute the right exponent, and
> the lookup table to estimate the mantissa.  I used something like this for
> square root:
>
>  1) shift the entire FP number by 1 to the right (logical right shift)
>  2) sum 0x20000000 so that the exponent is still offset by 64
>  3) extract the 8 bits from 14 to 22 and look them up in a 256-entry, 32-bit
> table
>  4) sum the value (as a 32-bit integer!) with the content of the table
>  5) perform 2 Newton-Raphson iterations as necessary

It normally turns out to be faster to use the magic integer sqrt
algorithm, even when you have multiplication and division in hardware

unsigned long
isqrt(x)
unsigned long x;
{
    register unsigned long op, res, one;

    op = x;
    res = 0;

    /* "one" starts at the highest power of four <= than the argument. */
    one = 1 << 30;  /* second-to-top bit set */
    while (one > op) one >>= 2;

    while (one != 0) {
        if (op >= res + one) {
            op = op - (res + one);
            res = res +  2 * one;
        }
        res >>= 1;
        one >>= 2;
    }
    return(res);
}

The current soft-fp routine in libm seems to use a variant of this,
but of course it may be faster if implemented using the Maverick's
64-bit add/sub/cmp.

    M

Reply via email to