source: trunk/libs/newlib/src/newlib/libm/machine/spu/headers/acoshd2.h

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 7.2 KB
Line 
1/* --------------------------------------------------------------  */
2/* (C)Copyright 2007,2008,                                         */
3/* International Business Machines Corporation                     */
4/* All Rights Reserved.                                            */
5/*                                                                 */
6/* Redistribution and use in source and binary forms, with or      */
7/* without modification, are permitted provided that the           */
8/* following conditions are met:                                   */
9/*                                                                 */
10/* - Redistributions of source code must retain the above copyright*/
11/*   notice, this list of conditions and the following disclaimer. */
12/*                                                                 */
13/* - Redistributions in binary form must reproduce the above       */
14/*   copyright notice, this list of conditions and the following   */
15/*   disclaimer in the documentation and/or other materials        */
16/*   provided with the distribution.                               */
17/*                                                                 */
18/* - Neither the name of IBM Corporation nor the names of its      */
19/*   contributors may be used to endorse or promote products       */
20/*   derived from this software without specific prior written     */
21/*   permission.                                                   */
22/*                                                                 */
23/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
24/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
25/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
26/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
27/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
28/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
29/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
30/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
31/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
32/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
33/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
34/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
35/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
36/* --------------------------------------------------------------  */
37/* PROLOG END TAG zYx                                              */
38#ifdef __SPU__
39#ifndef _ACOSHD2_H_
40#define _ACOSHD2_H_     1
41
42#include <spu_intrinsics.h>
43#include "logd2.h"
44#include "sqrtd2.h"
45
46/*
47 * FUNCTION
48 *  vector double _acoshd2(vector double x)
49 *
50 * DESCRIPTION
51 *  The acoshd2 function returns a vector containing the hyperbolic
52 *  arccosines of the corresponding elements of the input vector.
53 *
54 *  We are using the formula:
55 *    acosh = ln(x + sqrt(x^2 - 1))
56 *
57 *  For x near one, we use the Taylor series:
58 *
59 *                infinity
60 *                 ------
61 *                  -   '       
62 *                   -                 k
63 *    acosh x =       -      C  (x - 1)
64 *                   -        k
65 *                  -   ,
66 *                 ------
67 *                 k = 0
68 *
69 *
70 *  Special Cases:
71 *      - acosh(1)        = +0
72 *      - acosh(NaN)      = NaN
73 *      - acosh(Infinity) = Infinity
74 *      - acosh(x < 1)    = NaN
75 *
76 */
77
78/*
79 * Taylor Series Coefficients
80 * for x around 1.
81 */
82#define SDM_ACOSHD2_TAY01  1.000000000000000000000000000000000E0  /* 1 / 1                            */
83#define SDM_ACOSHD2_TAY02 -8.333333333333333333333333333333333E-2 /* 1 / 12                           */
84#define SDM_ACOSHD2_TAY03  1.875000000000000000000000000000000E-2 /* 3 / 160                          */
85#define SDM_ACOSHD2_TAY04 -5.580357142857142857142857142857142E-3 /* 5 / 896                          */
86#define SDM_ACOSHD2_TAY05  1.898871527777777777777777777777777E-3 /* 35 / 18432                       */
87#define SDM_ACOSHD2_TAY06 -6.991299715909090909090909090909090E-4 /* 63 / 90112                       */
88#define SDM_ACOSHD2_TAY07  2.711369441105769230769230769230769E-4 /* 231 / 851968                     */
89#define SDM_ACOSHD2_TAY08 -1.091003417968750000000000000000000E-4 /* 143 / 1310720                    */
90#define SDM_ACOSHD2_TAY09  4.512422225054572610294117647058823E-5 /* 6435 / 142606336                 */
91#define SDM_ACOSHD2_TAY10 -1.906564361170718544407894736842105E-5 /* 12155 / 637534208                */
92#define SDM_ACOSHD2_TAY11  8.193687314078921363467261904761904E-6 /* 46189 / 5637144576               */
93#define SDM_ACOSHD2_TAY12 -3.570569274218186088230298913043478E-6 /* 88179 / 24696061952              */
94#define SDM_ACOSHD2_TAY13  1.574025955051183700561523437500000E-6 /* 676039 / 429496729600            */
95#define SDM_ACOSHD2_TAY14 -7.006881922414457356488263165509259E-7 /* 1300075 / 1855425871872          */
96#define SDM_ACOSHD2_TAY15  3.145330616650332150788142763335129E-7 /* 5014575 / 15942918602752         */
97
98static __inline vector double _acoshd2(vector double x)
99{
100    vec_uchar16 dup_even  = ((vec_uchar16) { 0,1,2,3,  0,1,2,3, 8,9,10,11, 8,9,10,11 });
101    vec_double2 minus_oned = spu_splats(-1.0);
102    vec_double2 twod       = spu_splats(2.0);
103    /* Where we switch from taylor to formula */
104    vec_float4  switch_approx = spu_splats(1.15f);
105    vec_double2 result, fresult, mresult;;
106
107   
108    vec_double2 xminus1 = spu_add(x, minus_oned);
109    vec_float4  xf = spu_roundtf(x);
110    xf = spu_shuffle(xf, xf, dup_even);
111
112    vec_ullong2 use_form = (vec_ullong2)spu_cmpgt(xf, switch_approx);
113
114    vec_double2 sqrtargformula = spu_madd(x, x, minus_oned);
115    vec_double2 sqrtargtaylor  = spu_mul(xminus1, twod);
116    vec_double2 sqrtarg = spu_sel(sqrtargtaylor, sqrtargformula, use_form);
117
118    vec_double2 sqrtresult = _sqrtd2(sqrtarg);
119
120    /*
121     * Formula:
122     *   acosh = ln(x + sqrt(x^2 - 1))
123     */
124    fresult = spu_add(x, sqrtresult);
125    fresult = _logd2(fresult);
126
127    /*
128     * Taylor Series
129     */
130    mresult = spu_splats(SDM_ACOSHD2_TAY15);
131    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY14));
132    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY13));
133    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY12));
134    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY11));
135    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY10));
136    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY09));
137    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY08));
138    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY07));
139    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY06));
140    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY05));
141    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY04));
142    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY03));
143    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY02));
144    mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHD2_TAY01));
145
146
147    mresult = spu_mul(mresult, sqrtresult);
148
149
150    /*
151     * Select series or formula
152     */
153    result = spu_sel(mresult, fresult, use_form);
154
155    return result;
156}
157
158#endif /* _ACOSHD2_H_ */
159#endif /* __SPU__ */
Note: See TracBrowser for help on using the repository browser.