/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/isa_defs.h>
#include "libm_inlines.h"
#ifdef _LITTLE_ENDIAN
#define LO(x) *(unsigned*)x
#else
#define HI(x) *(int*)x
#endif
#ifdef __RESTRICT
#define restrict _Restrict
#else
#define restrict
#endif
/* double rsqrt(double x)
*
* Method :
* 1. Special cases:
* for x = NaN => QNaN;
* for x = +Inf => 0;
* for x is negative, -Inf => QNaN + invalid;
* for x = +0 => +Inf + divide-by-zero;
* for x = -0 => -Inf + divide-by-zero.
* 2. Computes reciprocal square root from:
* x = m * 2**n
* Where:
* m = [0.5, 2),
* n = ((exponent + 1) & ~1).
* Then:
* rsqrt(x) = 1/sqrt( m * 2**n ) = (2 ** (-n/2)) * (1/sqrt(m))
* 2. Computes 1/sqrt(m) from:
* 1/sqrt(m) = (1/sqrt(m0)) * (1/sqrt(1 + (1/m0)*dm))
* Where:
* m = m0 + dm,
* m0 = 0.5 * (1 + k/64) for m = [0.5, 0.5+127/256), k = [0, 63];
* m0 = 1.0 * (0 + k/64) for m = [0.5+127/256, 1.0+127/128), k = [64, 127];
* m0 = 2.0 for m = [1.0+127/128, 2.0), k = 128.
* Then:
* 1/sqrt(m0) is looked up in a table,
* 1/m0 is computed as (1/sqrt(m0)) * (1/sqrt(m0)).
* 1/sqrt(1 + (1/m0)*dm) is computed using approximation:
* 1/sqrt(1 + z) = (((((a6 * z + a5) * z + a4) * z + a3)
* * z + a2) * z + a1) * z + a0
* where z = [-1/128, 1/128].
*
* Accuracy:
* The maximum relative error for the approximating
* polynomial is 2**(-56.26).
* Maximum error observed: less than 0.563 ulp after 1.500.000.000
* results.
*/
extern double sqrt (double);
extern const double __vlibm_TBL_rsqrt[];
static void
#pragma no_inline(__vrsqrt_n)
{ \
if (n_n == 0) \
{ \
continue; \
} \
n--; \
break; \
}
static const double
void
{
double res;
while (n > 1)
{
n_n = 0;
for (; n > 1 ; n--)
{
{
}
{
{
}
else if (hx >= 0) /* X = denormal */
{
LO(&dsqrt_exp0) = 0;
res *= dsqrt_exp0;
}
else /* X = negative */
{
}
}
n_n++;
}
if (n_n > 0)
}
if (n > 0)
{
{
}
{
{
}
else if (hx >= 0) /* X = denormal */
{
LO(&dsqrt_exp0) = 0;
res *= dsqrt_exp0;
}
else /* X = negative */
{
}
}
else
{
LO(&dsqrt_exp0) = 0;
res *= dsqrt_exp0;
}
}
}
static void
{
LO(&dsqrt_exp0) = 0;
LO(&dsqrt_exp1) = 0;
LO(&dsqrt_exp2) = 0;
for(; n > 2 ; n -= 3)
{
res0 *= dsqrt_exp0;
res1 *= dsqrt_exp1;
res2 *= dsqrt_exp2;
}
for(; n > 0 ; n--)
{
LO(&dsqrt_exp0) = 0;
res0 *= dsqrt_exp0;
}
}