4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-14 09:49:14 +08:00
Jeff Johnston 27b975f6fd 2008-09-04 Ken Werner <ken.werner@de.ibm.com>
* libm/machine/spu/headers/acosd2.h: Duplicated preamble text removed.
        * libm/machine/spu/headers/acosf4.h: Likewise.
        * libm/machine/spu/headers/acoshd2.h: Likewise.
        * libm/machine/spu/headers/acoshf4.h: Likewise.
        * libm/machine/spu/headers/asind2.h: Likewise.
        * libm/machine/spu/headers/asinf4.h: Likewise.
        * libm/machine/spu/headers/asinhd2.h: Likewise.
        * libm/machine/spu/headers/asinhf4.h: Likewise.
        * libm/machine/spu/headers/atan2d2.h: Likewise.
        * libm/machine/spu/headers/atan2f4.h: Likewise.
        * libm/machine/spu/headers/atand2.h: Likewise.
        * libm/machine/spu/headers/atanf4.h: Likewise.
        * libm/machine/spu/headers/atanhd2.h: Likewise.
        * libm/machine/spu/headers/atanhf4.h: Likewise.
        * libm/machine/spu/headers/cos_sin.h: Likewise.
        * libm/machine/spu/headers/cosd2.h: Likewise.
        * libm/machine/spu/headers/cosf4.h: Likewise.
        * libm/machine/spu/headers/coshd2.h: Likewise.
        * libm/machine/spu/headers/coshf4.h: Likewise.
        * libm/machine/spu/headers/divd2.h: Likewise.
        * libm/machine/spu/headers/divf4.h: Likewise.
        * libm/machine/spu/headers/erf_utils.h: Likewise.
        * libm/machine/spu/headers/erfcd2.h: Likewise.
        * libm/machine/spu/headers/erfcf4.h: Likewise.
        * libm/machine/spu/headers/erfd2.h: Likewise.
        * libm/machine/spu/headers/erff4.h: Likewise.
        * libm/machine/spu/headers/exp2d2.h: Likewise.
        * libm/machine/spu/headers/exp2f4.h: Likewise.
        * libm/machine/spu/headers/expd2.h: Likewise.
        * libm/machine/spu/headers/expf4.h: Likewise.
        * libm/machine/spu/headers/expm1d2.h: Likewise.
        * libm/machine/spu/headers/expm1f4.h: Likewise.
        * libm/machine/spu/headers/floord2.h: Likewise.
        * libm/machine/spu/headers/floorf4.h: Likewise.
        * libm/machine/spu/headers/hypotd2.h: Likewise.
        * libm/machine/spu/headers/hypotf4.h: Likewise.
        * libm/machine/spu/headers/isnand2.h: Likewise.
        * libm/machine/spu/headers/isnanf4.h: Likewise.
        * libm/machine/spu/headers/ldexpd2.h: Likewise.
        * libm/machine/spu/headers/ldexpf4.h: Likewise.
        * libm/machine/spu/headers/lgammad2.h: Likewise.
        * libm/machine/spu/headers/lgammaf4.h: Likewise.
        * libm/machine/spu/headers/log10d2.h: Likewise.
        * libm/machine/spu/headers/log1pd2.h: Likewise.
        * libm/machine/spu/headers/log1pf4.h: Likewise.
        * libm/machine/spu/headers/log2d2.h: Likewise.
        * libm/machine/spu/headers/log2f4.h: Likewise.
        * libm/machine/spu/headers/logbf4.h: Likewise.
        * libm/machine/spu/headers/logd2.h: Likewise.
        * libm/machine/spu/headers/logf4.h: Likewise.
        * libm/machine/spu/headers/nearbyintf4.h: Likewise.
        * libm/machine/spu/headers/nextafterd2.h: Likewise.
        * libm/machine/spu/headers/nextafterf4.h: Likewise.
        * libm/machine/spu/headers/powd2.h: Likewise.
        * libm/machine/spu/headers/powf4.h: Likewise.
        * libm/machine/spu/headers/recipd2.h: Likewise.
        * libm/machine/spu/headers/recipf4.h: Likewise.
        * libm/machine/spu/headers/rintf4.h: Likewise.
        * libm/machine/spu/headers/scalbnf4.h: Likewise.
        * libm/machine/spu/headers/signbitd2.h: Likewise.
        * libm/machine/spu/headers/sincosd2.h: Likewise.
        * libm/machine/spu/headers/sincosf4.h: Likewise.
        * libm/machine/spu/headers/sind2.h: Likewise.
        * libm/machine/spu/headers/sinf4.h: Likewise.
        * libm/machine/spu/headers/sinhd2.h: Likewise.
        * libm/machine/spu/headers/sinhf4.h: Likewise.
        * libm/machine/spu/headers/sqrtd2.h: Likewise.
        * libm/machine/spu/headers/sqrtf4.h: Likewise.
        * libm/machine/spu/headers/tand2.h: Likewise.
        * libm/machine/spu/headers/tanf4.h: Likewise.
        * libm/machine/spu/headers/tanhd2.h: Likewise.
        * libm/machine/spu/headers/tanhf4.h: Likewise.
        * libm/machine/spu/headers/tgammad2.h: Likewise.
        * libm/machine/spu/headers/tgammaf4.h: Likewise.
        * libm/machine/spu/headers/truncd2.h: Likewise.
        * libm/machine/spu/headers/truncf4.h: Likewise.
        * libm/machine/spu/headers/simdmath.h: Likewise.
2008-09-04 17:50:56 +00:00

117 lines
5.1 KiB
C

/* -------------------------------------------------------------- */
/* (C)Copyright 2001,2008, */
/* International Business Machines Corporation, */
/* Sony Computer Entertainment, Incorporated, */
/* Toshiba Corporation, */
/* */
/* All Rights Reserved. */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the */
/* following conditions are met: */
/* */
/* - Redistributions of source code must retain the above copyright*/
/* notice, this list of conditions and the following disclaimer. */
/* */
/* - Redistributions in binary form must reproduce the above */
/* copyright notice, this list of conditions and the following */
/* disclaimer in the documentation and/or other materials */
/* provided with the distribution. */
/* */
/* - Neither the name of IBM Corporation nor the names of its */
/* contributors may be used to endorse or promote products */
/* derived from this software without specific prior written */
/* permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* -------------------------------------------------------------- */
/* PROLOG END TAG zYx */
#ifdef __SPU__
#ifndef _SQRTF4_H_
#define _SQRTF4_H_ 1
#include <spu_intrinsics.h>
/*
* FUNCTION
* vector float _sqrtf4(vector float in)
*
* DESCRIPTION
* The _sqrtf4 function computes the square root of the vector input "in"
*and returns the result.
*
*/
static __inline vector float _sqrtf4(vector float in)
{
vec_uint4 exp, valid;
vec_uint4 mask = spu_splats((unsigned int)0xFF000000);
vec_uint4 half = spu_splats((unsigned int)0x00800000);
vec_float4 one = spu_splats(1.0f);
vec_float4 three = spu_splats(3.0f);
vec_float4 x, y0, y1, y1_n1, y1_p1, y1_p2, y1_p3;
vec_float4 mant, err, err_p1, err_p2, err_p3;
vec_float4 out;
/* Compute the mantissa of the result seperately from
* the exponent to assure complete accuracy over the allowable
* input range. The mantissa is computed for inputs in the
* range [0.5, 2.0).
*/
x = spu_sel(in, one, mask);
y0 = spu_rsqrte(x);
/* Perform one iteration of the Newton-Raphsom method in single precision
* arithmetic.
*/
y1 = spu_mul(spu_nmsub(x, spu_mul(y0, y0), three),
spu_mul(y0, (vec_float4)(spu_sub((vec_uint4)(x), half))));
/* Correct the result for possible error. The range of error is -3 to +1.
* Identify the extent of the error and correct for it.
*/
y1_p3 = (vec_float4)spu_add((vec_uint4)(y1), 3);
y1_p2 = (vec_float4)spu_add((vec_uint4)(y1), 2);
y1_p1 = (vec_float4)spu_add((vec_uint4)(y1), 1);
y1_n1 = (vec_float4)spu_add((vec_uint4)(y1), -1);
err = spu_nmsub(y1, y1, x);
err_p1 = spu_nmsub(y1_p1, y1_p1, x);
err_p2 = spu_nmsub(y1_p2, y1_p2, x);
err_p3 = spu_nmsub(y1_p3, y1_p3, x);
mant = spu_sel(y1_n1, y1, spu_cmpgt((vec_int4)(err), -1));
mant = spu_sel(mant, y1_p1, spu_cmpgt((vec_int4)(err_p1), -1));
mant = spu_sel(mant, y1_p2, spu_cmpgt((vec_int4)(err_p2), -1));
mant = spu_sel(mant, y1_p3, spu_cmpgt((vec_int4)(err_p3), -1));
/* Compute the expected exponent. If the exponent is zero or the input is
* negative, then set the result to zero.
*/
exp = spu_rlmask(spu_add((vec_uint4)(in), (vec_uint4)(one)), -1);
valid = spu_cmpgt(spu_and((vec_int4)(in), (vec_int4)(mask)), 0);
/* Merge the computed exponent and mantissa.
*/
out = spu_and(spu_sel(mant, (vec_float4)(exp), spu_splats(0xFF800000)), (vec_float4)(valid));
return (out);
}
#endif /* _SQRTF4_H_ */
#endif /* __SPU__ */