newlib-cygwin/newlib/libm/machine/spu/headers/cos_sin.h

217 lines
9.1 KiB
C
Raw Normal View History

2007-09-28 Patrick Mansfield <patmans@us.ibm.com> * libm/machine/spu/Makefile.am: Add new C files. * libm/machine/spu/Makefile.in: Regenerate. * libm/machine/spu/headers/acos.h: New file. * libm/machine/spu/headers/acosd2.h: Ditto. * libm/machine/spu/headers/acosf.h: Ditto. * libm/machine/spu/headers/acosf4.h: Ditto. * libm/machine/spu/headers/acosh.h: Ditto. * libm/machine/spu/headers/acoshd2.h: Ditto. * libm/machine/spu/headers/acoshf.h: Ditto. * libm/machine/spu/headers/acoshf4.h: Ditto. * libm/machine/spu/headers/asin.h: Ditto. * libm/machine/spu/headers/asind2.h: Ditto. * libm/machine/spu/headers/asinf.h: Ditto. * libm/machine/spu/headers/asinf4.h: Ditto. * libm/machine/spu/headers/asinh.h: Ditto. * libm/machine/spu/headers/asinhd2.h: Ditto. * libm/machine/spu/headers/asinhf.h: Ditto. * libm/machine/spu/headers/asinhf4.h: Ditto. * libm/machine/spu/headers/atan.h: Ditto. * libm/machine/spu/headers/atan2.h: Ditto. * libm/machine/spu/headers/atan2d2.h: Ditto. * libm/machine/spu/headers/atan2f.h: Ditto. * libm/machine/spu/headers/atan2f4.h: Ditto. * libm/machine/spu/headers/atand2.h: Ditto. * libm/machine/spu/headers/atanf4.h: Ditto. * libm/machine/spu/headers/atanh.h: Ditto. * libm/machine/spu/headers/atanhd2.h: Ditto. * libm/machine/spu/headers/atanhf.h: Ditto. * libm/machine/spu/headers/atanhf4.h: Ditto. * libm/machine/spu/headers/cos.h: Ditto. * libm/machine/spu/headers/cos_sin.h: Ditto. * libm/machine/spu/headers/cosd2.h: Ditto. * libm/machine/spu/headers/cosf.h: Ditto. * libm/machine/spu/headers/cosf4.h: Ditto. * libm/machine/spu/headers/cosh.h: Ditto. * libm/machine/spu/headers/coshd2.h: Ditto. * libm/machine/spu/headers/coshf.h: Ditto. * libm/machine/spu/headers/coshf4.h: Ditto. * libm/machine/spu/headers/divd2.h: Ditto. * libm/machine/spu/headers/divf4.h: Ditto. * libm/machine/spu/headers/erf.h: Ditto. * libm/machine/spu/headers/erf_utils.h: Ditto. * libm/machine/spu/headers/erfc.h: Ditto. * libm/machine/spu/headers/erfcd2.h: Ditto. * libm/machine/spu/headers/erfcf.h: Ditto. * libm/machine/spu/headers/erfcf4.h: Ditto. * libm/machine/spu/headers/erfd2.h: Ditto. * libm/machine/spu/headers/erff.h: Ditto. * libm/machine/spu/headers/erff4.h: Ditto. * libm/machine/spu/headers/exp.h: Ditto. * libm/machine/spu/headers/exp2.h: Ditto. * libm/machine/spu/headers/exp2d2.h: Ditto. * libm/machine/spu/headers/exp2f4.h: Ditto. * libm/machine/spu/headers/expd2.h: Ditto. * libm/machine/spu/headers/expf4.h: Ditto. * libm/machine/spu/headers/expm1.h: Ditto. * libm/machine/spu/headers/expm1d2.h: Ditto. * libm/machine/spu/headers/expm1f.h: Ditto. * libm/machine/spu/headers/expm1f4.h: Ditto. * libm/machine/spu/headers/floord2.h: Ditto. * libm/machine/spu/headers/floorf4.h: Ditto. * libm/machine/spu/headers/hypot.h: Ditto. * libm/machine/spu/headers/hypotd2.h: Ditto. * libm/machine/spu/headers/hypotf.h: Ditto. * libm/machine/spu/headers/hypotf4.h: Ditto. * libm/machine/spu/headers/isnan.h: Ditto. * libm/machine/spu/headers/isnand2.h: Ditto. * libm/machine/spu/headers/isnanf.h: Ditto. * libm/machine/spu/headers/isnanf4.h: Ditto. * libm/machine/spu/headers/ldexpd2.h: Ditto. * libm/machine/spu/headers/ldexpf4.h: Ditto. * libm/machine/spu/headers/lgamma.h: Ditto. * libm/machine/spu/headers/lgammad2.h: Ditto. * libm/machine/spu/headers/lgammaf.h: Ditto. * libm/machine/spu/headers/lgammaf4.h: Ditto. * libm/machine/spu/headers/log.h: Ditto. * libm/machine/spu/headers/log10.h: Ditto. * libm/machine/spu/headers/log10d2.h: Ditto. * libm/machine/spu/headers/log1p.h: Ditto. * libm/machine/spu/headers/log1pd2.h: Ditto. * libm/machine/spu/headers/log1pf.h: Ditto. * libm/machine/spu/headers/log1pf4.h: Ditto. * libm/machine/spu/headers/log2.h: Ditto. * libm/machine/spu/headers/log2d2.h: Ditto. * libm/machine/spu/headers/log2f4.h: Ditto. * libm/machine/spu/headers/logbf.h: Ditto. * libm/machine/spu/headers/logbf4.h: Ditto. * libm/machine/spu/headers/logd2.h: Ditto. * libm/machine/spu/headers/logf4.h: Ditto. * libm/machine/spu/headers/nearbyintf.h: Ditto. * libm/machine/spu/headers/nearbyintf4.h: Ditto. * libm/machine/spu/headers/nextafter.h: Ditto. * libm/machine/spu/headers/nextafterd2.h: Ditto. * libm/machine/spu/headers/nextafterf.h: Ditto. * libm/machine/spu/headers/nextafterf4.h: Ditto. * libm/machine/spu/headers/pow.h: Ditto. * libm/machine/spu/headers/powd2.h: Ditto. * libm/machine/spu/headers/powf.h: Ditto. * libm/machine/spu/headers/powf4.h: Ditto. * libm/machine/spu/headers/recipd2.h: Ditto. * libm/machine/spu/headers/recipf4.h: Ditto. * libm/machine/spu/headers/rintf.h: Ditto. * libm/machine/spu/headers/rintf4.h: Ditto. * libm/machine/spu/headers/scalbnf4.h: Ditto. * libm/machine/spu/headers/signbit.h: Ditto. * libm/machine/spu/headers/signbitd2.h: Ditto. * libm/machine/spu/headers/simdmath.h: Ditto. * libm/machine/spu/headers/sin.h: Ditto. * libm/machine/spu/headers/sincos.h: Ditto. * libm/machine/spu/headers/sincosd2.h: Ditto. * libm/machine/spu/headers/sincosf.h: Ditto. * libm/machine/spu/headers/sincosf4.h: Ditto. * libm/machine/spu/headers/sind2.h: Ditto. * libm/machine/spu/headers/sinf.h: Ditto. * libm/machine/spu/headers/sinf4.h: Ditto. * libm/machine/spu/headers/sinh.h: Ditto. * libm/machine/spu/headers/sinhd2.h: Ditto. * libm/machine/spu/headers/sinhf.h: Ditto. * libm/machine/spu/headers/sinhf4.h: Ditto. * libm/machine/spu/headers/sqrtd2.h: Ditto. * libm/machine/spu/headers/sqrtf.h: Ditto. * libm/machine/spu/headers/sqrtf4.h: Ditto. * libm/machine/spu/headers/tan.h: Ditto. * libm/machine/spu/headers/tand2.h: Ditto. * libm/machine/spu/headers/tanf.h: Ditto. * libm/machine/spu/headers/tanf4.h: Ditto. * libm/machine/spu/headers/tanh.h: Ditto. * libm/machine/spu/headers/tanhd2.h: Ditto. * libm/machine/spu/headers/tanhf.h: Ditto. * libm/machine/spu/headers/tanhf4.h: Ditto. * libm/machine/spu/headers/tgamma.h: Ditto. * libm/machine/spu/headers/tgammad2.h: Ditto. * libm/machine/spu/headers/tgammaf.h: Ditto. * libm/machine/spu/headers/tgammaf4.h: Ditto. * libm/machine/spu/headers/truncd2.h: Ditto. * libm/machine/spu/headers/truncf4.h: Ditto. * libm/machine/spu/log2.c: Ditto. * libm/machine/spu/s_asinh.c: Ditto. * libm/machine/spu/s_atan.c: Ditto. * libm/machine/spu/s_cos.c: Ditto. * libm/machine/spu/s_erf.c: Ditto. * libm/machine/spu/s_expm1.c: Ditto. * libm/machine/spu/s_isnan.c: Ditto. * libm/machine/spu/s_log1p.c: Ditto. * libm/machine/spu/s_nextafter.c: Ditto. * libm/machine/spu/s_sin.c: Ditto. * libm/machine/spu/s_tan.c: Ditto. * libm/machine/spu/s_tanh.c: Ditto. * libm/machine/spu/sf_asinh.c: Ditto. * libm/machine/spu/sf_cos.c: Ditto. * libm/machine/spu/sf_erf.c: Ditto. * libm/machine/spu/sf_expm1.c: Ditto. * libm/machine/spu/sf_log1p.c: Ditto. * libm/machine/spu/sf_logb.c: Ditto. * libm/machine/spu/sf_nearbyint.c: Ditto. * libm/machine/spu/sf_nextafter.c: Ditto. * libm/machine/spu/sf_rint.c: Ditto. * libm/machine/spu/sf_sin.c: Ditto. * libm/machine/spu/sf_tan.c: Ditto. * libm/machine/spu/sf_tanh.c: Ditto. * libm/machine/spu/w_acos.c: Ditto. * libm/machine/spu/w_acosh.c: Ditto. * libm/machine/spu/w_asin.c: Ditto. * libm/machine/spu/w_atan2.c: Ditto. * libm/machine/spu/w_atanh.c: Ditto. * libm/machine/spu/w_cosh.c: Ditto. * libm/machine/spu/w_exp.c: Ditto. * libm/machine/spu/w_exp2.c: Ditto. * libm/machine/spu/w_hypot.c: Ditto. * libm/machine/spu/w_lgamma.c: Ditto. * libm/machine/spu/w_log.c: Ditto. * libm/machine/spu/w_log10.c: Ditto. * libm/machine/spu/w_pow.c: Ditto. * libm/machine/spu/w_sincos.c: Ditto. * libm/machine/spu/w_sinh.c: Ditto. * libm/machine/spu/w_tgamma.c: Ditto. * libm/machine/spu/wf_acos.c: Ditto. * libm/machine/spu/wf_acosh.c: Ditto. * libm/machine/spu/wf_asin.c: Ditto. * libm/machine/spu/wf_atan2.c: Ditto. * libm/machine/spu/wf_atanh.c: Ditto. * libm/machine/spu/wf_cosh.c: Ditto. * libm/machine/spu/wf_hypot.c: Ditto. * libm/machine/spu/wf_lgamma.c: Ditto. * libm/machine/spu/wf_pow.c: Ditto. * libm/machine/spu/wf_sincos.c: Ditto. * libm/machine/spu/wf_sinh.c: Ditto. * libm/machine/spu/wf_sqrt.c: Ditto. * libm/machine/spu/wf_tgamma.c: Ditto.
2007-09-29 02:44:24 +08:00
/* -------------------------------------------------------------- */
/* (C)Copyright 2006,2007, */
/* 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. */
/* 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 _COS_SIN_H_
#define _COS_SIN_H_ 1
#define M_PI_OVER_4_HI_32 0x3fe921fb
#define M_PI_OVER_4 0.78539816339744827900
#define M_FOUR_OVER_PI 1.27323954478442180616
#define M_PI_OVER_2 1.57079632679489655800
#define M_PI_OVER_2_HI 1.57079632673412561417
#define M_PI_OVER_2_LO 0.0000000000607710050650619224932
#define M_PI_OVER_2F_HI 1.570312500000000000
#define M_PI_OVER_2F_LO 0.000483826794896558
/* The following coefficients correspond to the Taylor series
* coefficients for cos and sin.
*/
#define COS_14 -0.00000000001138218794258068723867
#define COS_12 0.000000002087614008917893178252
#define COS_10 -0.0000002755731724204127572108
#define COS_08 0.00002480158729870839541888
#define COS_06 -0.001388888888888735934799
#define COS_04 0.04166666666666666534980
#define COS_02 -0.5000000000000000000000
#define COS_00 1.0
#define SIN_15 -0.00000000000076471637318198164759
#define SIN_13 0.00000000016059043836821614599
#define SIN_11 -0.000000025052108385441718775
#define SIN_09 0.0000027557319223985890653
#define SIN_07 -0.0001984126984126984127
#define SIN_05 0.008333333333333333333
#define SIN_03 -0.16666666666666666666
#define SIN_01 1.0
/* Compute the following for each floating point element of x.
* x = fmod(x, PI/4);
* ix = (int)x * PI/4;
* This allows one to compute cos / sin over the limited range
* and select the sign and correct result based upon the octant
* of the original angle (as defined by the ix result).
*
* Expected Inputs Types:
* x = vec_float4
* ix = vec_int4
*/
#define MOD_PI_OVER_FOUR_F(_x, _ix) { \
vec_float4 fx; \
\
_ix = spu_convts(spu_mul(_x, spu_splats((float)M_FOUR_OVER_PI)), 0); \
_ix = spu_add(_ix, spu_add(spu_rlmaska((vec_int4)_x, -31), 1)); \
\
fx = spu_convtf(spu_rlmaska(_ix, -1), 0); \
_x = spu_nmsub(fx, spu_splats((float)M_PI_OVER_2F_HI), _x); \
_x = spu_nmsub(fx, spu_splats((float)M_PI_OVER_2F_LO), _x); \
}
/* Double precision MOD_PI_OVER_FOUR
*
* Expected Inputs Types:
* x = vec_double2
* ix = vec_int4
*/
#define MOD_PI_OVER_FOUR(_x, _ix) { \
vec_float4 fx; \
vec_double2 dix; \
\
fx = spu_roundtf(spu_mul(_x, spu_splats(M_FOUR_OVER_PI))); \
_ix = spu_convts(fx, 0); \
_ix = spu_add(_ix, spu_add(spu_rlmaska((vec_int4)fx, -31), 1)); \
\
dix = spu_extend(spu_convtf(spu_rlmaska(_ix, -1), 0)); \
_x = spu_nmsub(spu_splats(M_PI_OVER_2_HI), dix, _x); \
_x = spu_nmsub(spu_splats(M_PI_OVER_2_LO), dix, _x); \
}
/* Compute the cos(x) and sin(x) for the range reduced angle x.
* In order to compute these trig functions to full single precision
* accuracy, we solve the Taylor series.
*
* c = cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! - x^10/10!
* s = sin(x) = x - x^3/4! + x^5/5! - x^7/7! + x^9/9! - x^11/11!
*
* Expected Inputs Types:
* x = vec_float4
* c = vec_float4
* s = vec_float4
*/
#define COMPUTE_COS_SIN_F(_x, _c, _s) { \
vec_float4 x2, x4, x6; \
vec_float4 cos_hi, cos_lo; \
vec_float4 sin_hi, sin_lo; \
\
x2 = spu_mul(_x, _x); \
x4 = spu_mul(x2, x2); \
x6 = spu_mul(x2, x4); \
\
cos_hi = spu_madd(spu_splats((float)COS_10), x2, spu_splats((float)COS_08)); \
cos_lo = spu_madd(spu_splats((float)COS_04), x2, spu_splats((float)COS_02)); \
cos_hi = spu_madd(cos_hi, x2, spu_splats((float)COS_06)); \
cos_lo = spu_madd(cos_lo, x2, spu_splats((float)COS_00)); \
_c = spu_madd(cos_hi, x6, cos_lo); \
\
sin_hi = spu_madd(spu_splats((float)SIN_11), x2, spu_splats((float)SIN_09)); \
sin_lo = spu_madd(spu_splats((float)SIN_05), x2, spu_splats((float)SIN_03)); \
sin_hi = spu_madd(sin_hi, x2, spu_splats((float)SIN_07)); \
sin_lo = spu_madd(sin_lo, x2, spu_splats((float)SIN_01)); \
_s = spu_madd(sin_hi, x6, sin_lo); \
_s = spu_mul(_s, _x); \
}
/* Compute the cos(x) and sin(x) for the range reduced angle x.
* This version computes the cosine and sine to double precision
* accuracy using the Taylor series:
*
* c = cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! - x^10/10! + x^12/12! - x^14/14!
* s = sin(x) = x - x^3/4! + x^5/5! - x^7/7! + x^9/9! - x^11/11! + x^13/13! - x^15/15!
*
* Expected Inputs Types:
* x = vec_double2
* c = vec_double2
* s = vec_double2
*/
#define COMPUTE_COS_SIN(_x, _c, _s) { \
vec_double2 x2, x4, x8; \
vec_double2 cos_hi, cos_lo; \
vec_double2 sin_hi, sin_lo; \
\
x2 = spu_mul(_x, _x); \
x4 = spu_mul(x2, x2); \
x8 = spu_mul(x4, x4); \
\
cos_hi = spu_madd(spu_splats(COS_14), x2, spu_splats(COS_12)); \
cos_lo = spu_madd(spu_splats(COS_06), x2, spu_splats(COS_04)); \
cos_hi = spu_madd(cos_hi, x2, spu_splats(COS_10)); \
cos_lo = spu_madd(cos_lo, x2, spu_splats(COS_02)); \
cos_hi = spu_madd(cos_hi, x2, spu_splats(COS_08)); \
cos_lo = spu_madd(cos_lo, x2, spu_splats(COS_00)); \
_c = spu_madd(cos_hi, x8, cos_lo); \
\
sin_hi = spu_madd(spu_splats(SIN_15), x2, spu_splats(SIN_13)); \
sin_lo = spu_madd(spu_splats(SIN_07), x2, spu_splats(SIN_05)); \
sin_hi = spu_madd(sin_hi, x2, spu_splats(SIN_11)); \
sin_lo = spu_madd(sin_lo, x2, spu_splats(SIN_03)); \
sin_hi = spu_madd(sin_hi, x2, spu_splats(SIN_09)); \
sin_lo = spu_madd(sin_lo, x2, spu_splats(SIN_01)); \
_s = spu_madd(sin_hi, x8, sin_lo); \
_s = spu_mul(_s, _x); \
}
#endif /* _COS_SIN_H_ */
#endif /* __SPU__ */