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

131 lines
4.4 KiB
C
Raw Normal View History

2007-09-28 Patrick Mansfield <patmans@us.ibm.com> * configure.host: Define _POSIX_MODE to match the existing vector math code, as we don't support the matherr callout. * libm/machine/spu/Makefile.am: New file. * libm/machine/spu/Makefile.in: Auto-generated. * libm/machine/spu/headers/atanf.h: New file. * libm/machine/spu/headers/cbrt.h: Ditto. * libm/machine/spu/headers/cbrtf.h: Ditto. * libm/machine/spu/headers/ceil.h: Ditto. * libm/machine/spu/headers/ceilf.h: Ditto. * libm/machine/spu/headers/copysign.h: Ditto. * libm/machine/spu/headers/copysignf.h: Ditto. * libm/machine/spu/headers/exp2f.h: Ditto. * libm/machine/spu/headers/expf.h: Ditto. * libm/machine/spu/headers/fabs.h: Ditto. * libm/machine/spu/headers/fabsf.h: Ditto. * libm/machine/spu/headers/fdim.h: Ditto. * libm/machine/spu/headers/fdimf.h: Ditto. * libm/machine/spu/headers/floor.h: Ditto. * libm/machine/spu/headers/floorf.h: Ditto. * libm/machine/spu/headers/fma.h: Ditto. * libm/machine/spu/headers/fmaf.h: Ditto. * libm/machine/spu/headers/fmax.h: Ditto. * libm/machine/spu/headers/fmaxf.h: Ditto. * libm/machine/spu/headers/fmin.h: Ditto. * libm/machine/spu/headers/fminf.h: Ditto. * libm/machine/spu/headers/fmod.h: Ditto. * libm/machine/spu/headers/fmodf.h: Ditto. * libm/machine/spu/headers/frexp.h: Ditto. * libm/machine/spu/headers/frexpf.h: Ditto. * libm/machine/spu/headers/ilogb.h: Ditto. * libm/machine/spu/headers/ilogbf.h: Ditto. * libm/machine/spu/headers/ldexp.h: Ditto. * libm/machine/spu/headers/ldexpf.h: Ditto. * libm/machine/spu/headers/llrint.h: Ditto. * libm/machine/spu/headers/llrintf.h: Ditto. * libm/machine/spu/headers/llround.h: Ditto. * libm/machine/spu/headers/llroundf.h: Ditto. * libm/machine/spu/headers/log10f.h: Ditto. * libm/machine/spu/headers/log2f.h: Ditto. * libm/machine/spu/headers/logf.h: Ditto. * libm/machine/spu/headers/lrint.h: Ditto. * libm/machine/spu/headers/lrintf.h: Ditto. * libm/machine/spu/headers/lround.h: Ditto. * libm/machine/spu/headers/lroundf.h: Ditto. * libm/machine/spu/headers/nearbyint.h: Ditto. * libm/machine/spu/headers/remainder.h: Ditto. * libm/machine/spu/headers/remainderf.h: Ditto. * libm/machine/spu/headers/remquo.h: Ditto. * libm/machine/spu/headers/remquof.h: Ditto. * libm/machine/spu/headers/rint.h: Ditto. * libm/machine/spu/headers/round.h: Ditto. * libm/machine/spu/headers/roundf.h: Ditto. * libm/machine/spu/headers/scalbn.h: Ditto. * libm/machine/spu/headers/scalbnf.h: Ditto. * libm/machine/spu/headers/sqrt.h: Ditto. * libm/machine/spu/headers/trunc.h: Ditto. * libm/machine/spu/headers/truncf.h: Ditto. * libm/machine/spu/headers/vec_literal.h: Ditto. * libm/machine/spu/llrint.c: Ditto. * libm/machine/spu/llrintf.c: Ditto. * libm/machine/spu/llround.c: Ditto. * libm/machine/spu/llroundf.c: Ditto. * libm/machine/spu/log2f.c: Ditto. * libm/machine/spu/s_cbrt.c: Ditto. * libm/machine/spu/s_ceil.c: Ditto. * libm/machine/spu/s_copysign.c: Ditto. * libm/machine/spu/s_fabs.c: Ditto. * libm/machine/spu/s_fdim.c: Ditto. * libm/machine/spu/s_floor.c: Ditto. * libm/machine/spu/s_fma.c: Ditto. * libm/machine/spu/s_fmax.c: Ditto. * libm/machine/spu/s_fmin.c: Ditto. * libm/machine/spu/s_frexp.c: Ditto. * libm/machine/spu/s_ilogb.c: Ditto. * libm/machine/spu/s_ldexp.c: Ditto. * libm/machine/spu/s_lrint.c: Ditto. * libm/machine/spu/s_lround.c: Ditto. * libm/machine/spu/s_nearbyint.c: Ditto. * libm/machine/spu/s_remquo.c: Ditto. * libm/machine/spu/s_rint.c: Ditto. * libm/machine/spu/s_round.c: Ditto. * libm/machine/spu/s_scalbn.c: Ditto. * libm/machine/spu/s_trunc.c: Ditto. * libm/machine/spu/sf_atan.c: Ditto. * libm/machine/spu/sf_cbrt.c: Ditto. * libm/machine/spu/sf_ceil.c: Ditto. * libm/machine/spu/sf_copysign.c: Ditto. * libm/machine/spu/sf_fabs.c: Ditto. * libm/machine/spu/sf_fdim.c: Ditto. * libm/machine/spu/sf_floor.c: Ditto. * libm/machine/spu/sf_fma.c: Ditto. * libm/machine/spu/sf_fmax.c: Ditto. * libm/machine/spu/sf_fmin.c: Ditto. * libm/machine/spu/sf_frexp.c: Ditto. * libm/machine/spu/sf_ilogb.c: Ditto. * libm/machine/spu/sf_ldexp.c: Ditto. * libm/machine/spu/sf_lrint.c: Ditto. * libm/machine/spu/sf_lround.c: Ditto. * libm/machine/spu/sf_remquo.c: Ditto. * libm/machine/spu/sf_round.c: Ditto. * libm/machine/spu/sf_scalbn.c: Ditto. * libm/machine/spu/sf_trunc.c: Ditto. * libm/machine/spu/w_fmod.c: Ditto. * libm/machine/spu/w_remainder.c: Ditto. * libm/machine/spu/w_sqrt.c: Ditto. * libm/machine/spu/wf_exp.c: Ditto. * libm/machine/spu/wf_exp2.c: Ditto. * libm/machine/spu/wf_fmod.c: Ditto. * libm/machine/spu/wf_log.c: Ditto. * libm/machine/spu/wf_log10.c: Ditto. * libm/machine/spu/wf_remainder.c: Ditto.
2007-09-29 02:32:57 +08:00
/*
(C) Copyright 2001,2006,
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 names of the copyright holders nor the names of their
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.
*/
#ifndef _CBRTF_H_
#define _CBRTF_H_ 1
#include <spu_intrinsics.h>
#include "headers/vec_literal.h"
static double cbrt_factors[5] = {
0.629960524947436484311, /* 2^(-2/3) */
0.793700525984099680699, /* 2^(-1/3) */
1.0, /* 2^(0) */
1.259921049894873164666, /* 2^(1/3) */
1.587401051968199583441 /* 2^(2/3) */
};
2007-09-28 Patrick Mansfield <patmans@us.ibm.com> * configure.host: Define _POSIX_MODE to match the existing vector math code, as we don't support the matherr callout. * libm/machine/spu/Makefile.am: New file. * libm/machine/spu/Makefile.in: Auto-generated. * libm/machine/spu/headers/atanf.h: New file. * libm/machine/spu/headers/cbrt.h: Ditto. * libm/machine/spu/headers/cbrtf.h: Ditto. * libm/machine/spu/headers/ceil.h: Ditto. * libm/machine/spu/headers/ceilf.h: Ditto. * libm/machine/spu/headers/copysign.h: Ditto. * libm/machine/spu/headers/copysignf.h: Ditto. * libm/machine/spu/headers/exp2f.h: Ditto. * libm/machine/spu/headers/expf.h: Ditto. * libm/machine/spu/headers/fabs.h: Ditto. * libm/machine/spu/headers/fabsf.h: Ditto. * libm/machine/spu/headers/fdim.h: Ditto. * libm/machine/spu/headers/fdimf.h: Ditto. * libm/machine/spu/headers/floor.h: Ditto. * libm/machine/spu/headers/floorf.h: Ditto. * libm/machine/spu/headers/fma.h: Ditto. * libm/machine/spu/headers/fmaf.h: Ditto. * libm/machine/spu/headers/fmax.h: Ditto. * libm/machine/spu/headers/fmaxf.h: Ditto. * libm/machine/spu/headers/fmin.h: Ditto. * libm/machine/spu/headers/fminf.h: Ditto. * libm/machine/spu/headers/fmod.h: Ditto. * libm/machine/spu/headers/fmodf.h: Ditto. * libm/machine/spu/headers/frexp.h: Ditto. * libm/machine/spu/headers/frexpf.h: Ditto. * libm/machine/spu/headers/ilogb.h: Ditto. * libm/machine/spu/headers/ilogbf.h: Ditto. * libm/machine/spu/headers/ldexp.h: Ditto. * libm/machine/spu/headers/ldexpf.h: Ditto. * libm/machine/spu/headers/llrint.h: Ditto. * libm/machine/spu/headers/llrintf.h: Ditto. * libm/machine/spu/headers/llround.h: Ditto. * libm/machine/spu/headers/llroundf.h: Ditto. * libm/machine/spu/headers/log10f.h: Ditto. * libm/machine/spu/headers/log2f.h: Ditto. * libm/machine/spu/headers/logf.h: Ditto. * libm/machine/spu/headers/lrint.h: Ditto. * libm/machine/spu/headers/lrintf.h: Ditto. * libm/machine/spu/headers/lround.h: Ditto. * libm/machine/spu/headers/lroundf.h: Ditto. * libm/machine/spu/headers/nearbyint.h: Ditto. * libm/machine/spu/headers/remainder.h: Ditto. * libm/machine/spu/headers/remainderf.h: Ditto. * libm/machine/spu/headers/remquo.h: Ditto. * libm/machine/spu/headers/remquof.h: Ditto. * libm/machine/spu/headers/rint.h: Ditto. * libm/machine/spu/headers/round.h: Ditto. * libm/machine/spu/headers/roundf.h: Ditto. * libm/machine/spu/headers/scalbn.h: Ditto. * libm/machine/spu/headers/scalbnf.h: Ditto. * libm/machine/spu/headers/sqrt.h: Ditto. * libm/machine/spu/headers/trunc.h: Ditto. * libm/machine/spu/headers/truncf.h: Ditto. * libm/machine/spu/headers/vec_literal.h: Ditto. * libm/machine/spu/llrint.c: Ditto. * libm/machine/spu/llrintf.c: Ditto. * libm/machine/spu/llround.c: Ditto. * libm/machine/spu/llroundf.c: Ditto. * libm/machine/spu/log2f.c: Ditto. * libm/machine/spu/s_cbrt.c: Ditto. * libm/machine/spu/s_ceil.c: Ditto. * libm/machine/spu/s_copysign.c: Ditto. * libm/machine/spu/s_fabs.c: Ditto. * libm/machine/spu/s_fdim.c: Ditto. * libm/machine/spu/s_floor.c: Ditto. * libm/machine/spu/s_fma.c: Ditto. * libm/machine/spu/s_fmax.c: Ditto. * libm/machine/spu/s_fmin.c: Ditto. * libm/machine/spu/s_frexp.c: Ditto. * libm/machine/spu/s_ilogb.c: Ditto. * libm/machine/spu/s_ldexp.c: Ditto. * libm/machine/spu/s_lrint.c: Ditto. * libm/machine/spu/s_lround.c: Ditto. * libm/machine/spu/s_nearbyint.c: Ditto. * libm/machine/spu/s_remquo.c: Ditto. * libm/machine/spu/s_rint.c: Ditto. * libm/machine/spu/s_round.c: Ditto. * libm/machine/spu/s_scalbn.c: Ditto. * libm/machine/spu/s_trunc.c: Ditto. * libm/machine/spu/sf_atan.c: Ditto. * libm/machine/spu/sf_cbrt.c: Ditto. * libm/machine/spu/sf_ceil.c: Ditto. * libm/machine/spu/sf_copysign.c: Ditto. * libm/machine/spu/sf_fabs.c: Ditto. * libm/machine/spu/sf_fdim.c: Ditto. * libm/machine/spu/sf_floor.c: Ditto. * libm/machine/spu/sf_fma.c: Ditto. * libm/machine/spu/sf_fmax.c: Ditto. * libm/machine/spu/sf_fmin.c: Ditto. * libm/machine/spu/sf_frexp.c: Ditto. * libm/machine/spu/sf_ilogb.c: Ditto. * libm/machine/spu/sf_ldexp.c: Ditto. * libm/machine/spu/sf_lrint.c: Ditto. * libm/machine/spu/sf_lround.c: Ditto. * libm/machine/spu/sf_remquo.c: Ditto. * libm/machine/spu/sf_round.c: Ditto. * libm/machine/spu/sf_scalbn.c: Ditto. * libm/machine/spu/sf_trunc.c: Ditto. * libm/machine/spu/w_fmod.c: Ditto. * libm/machine/spu/w_remainder.c: Ditto. * libm/machine/spu/w_sqrt.c: Ditto. * libm/machine/spu/wf_exp.c: Ditto. * libm/machine/spu/wf_exp2.c: Ditto. * libm/machine/spu/wf_fmod.c: Ditto. * libm/machine/spu/wf_log.c: Ditto. * libm/machine/spu/wf_log10.c: Ditto. * libm/machine/spu/wf_remainder.c: Ditto.
2007-09-29 02:32:57 +08:00
/* Compute the cube root of the floating point input x.
*/
static __inline float _cbrtf(float x)
{
vec_int4 exp, bias;
vec_uint4 mask, e_div_3, e_mod_3;
vec_uint4 mant_mask = VEC_SPLAT_U32(0x7FFFFF);
vec_float4 in;
vec_float4 half = VEC_SPLAT_F32(0.5f);
vec_float4 onef = VEC_SPLAT_F32(1.0f);
vec_float4 out, mant, ym, bf, inv_bf;
vec_double2 two = VEC_SPLAT_F64(2.0);
/* Polynomial coefficients */
vec_double2 c2 = VEC_SPLAT_F64(0.191502161678719066);
vec_double2 c1 = VEC_SPLAT_F64(0.697570460207922770);
vec_double2 c0 = VEC_SPLAT_F64(0.492659620528969547);
vec_double2 a0, b0, inv_b0, ym0;
vec_double2 mant0, u0, u0_3, factor0;
in = spu_promote(x, 0);
/* Normalize the mantissa (fraction part) into the range [0.5, 1.0) and
* extract the exponent.
*/
mant = spu_sel(half, in, mant_mask);
exp = spu_and(spu_rlmask((vec_int4)in, -23), 0xFF);
/* Generate mask used to zero result if the exponent is zero (ie, in is either
* zero or a denorm
*/
mask = spu_cmpeq(exp, 0);
exp = spu_add(exp, -126);
mant0 = spu_extend(mant);
u0 = spu_madd(mant0, spu_nmsub(mant0, c2, c1), c0);
u0_3 = spu_mul(spu_mul(u0, u0), u0);
/* Compute: e_div_3 = exp/3
*
* Fetch: factor = factor[2+exp%3]
*
* The factors array contains 5 values: 2^(-2/3), 2^(-1/3), 2^0, 2^(1/3), 2^(2/3), 2^1.
*/
bias = spu_rlmask(spu_rlmaska(exp, -15), -16);
e_div_3 = (vec_uint4)spu_rlmaska(spu_madd((vec_short8)exp, VEC_SPLAT_S16(0x5556), bias), -16);
e_mod_3 = (vec_uint4)spu_sub((vec_int4)(exp), spu_mulo((vec_short8)e_div_3, VEC_SPLAT_S16(3)));
e_mod_3 = spu_add(e_mod_3, 2);
factor0 = spu_promote(cbrt_factors[spu_extract(e_mod_3, 0)], 0);
/* Compute the estimated mantissa cube root (ym) equals:
* ym = (u * factor * (2.0 * mant + u3)) / (2.0 * u3 + mant);
*/
a0 = spu_mul(spu_mul(factor0, u0), spu_madd(two, mant0, u0_3));
b0 = spu_madd(two, u0_3, mant0);
bf = spu_roundtf(b0);
inv_bf = spu_re(bf);
inv_bf = spu_madd(spu_nmsub(bf, inv_bf, onef), inv_bf, inv_bf);
inv_b0 = spu_extend(inv_bf);
ym0 = spu_mul(a0, inv_b0);
ym0 = spu_madd(spu_nmsub(b0, ym0, a0), inv_b0, ym0);
ym = spu_roundtf(ym0);
/* Merge sign, computed exponent, and computed mantissa.
*/
exp = spu_rl(spu_add((vec_int4)e_div_3, 127), 23);
out = spu_sel((vec_float4)exp, in, VEC_SPLAT_U32(0x80000000));
out = spu_mul(out, ym);
out = spu_andc(out, (vec_float4)mask);
return (spu_extract(out, 0));
}
#endif /* _CBRTF_H_ */