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 _ACOSHF4_H_
40 #define _ACOSHF4_H_ 1
41
42 #include <spu_intrinsics.h>
43 #include "logf4.h"
44 #include "sqrtf4.h"
45
46 /*
47 * FUNCTION
48 * vector float _acoshf4(vector float x)
49 *
50 * DESCRIPTION
51 * The acoshf4 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 * - NaNs and Infinity aren't supported for single-precision on SPU.
73 *
74 */
75
76 /*
77 * Taylor Series Coefficients
78 * for x around 1.
79 */
80 #define SDM_ACOSHF4_TAY01 1.00000000000000000000000000000000000E0f /* 1 / 1 */
81 #define SDM_ACOSHF4_TAY02 -8.33333333333333333333333333333333333E-2f /* 1 / 12 */
82 #define SDM_ACOSHF4_TAY03 1.87500000000000000000000000000000000E-2f /* 3 / 160 */
83 #define SDM_ACOSHF4_TAY04 -5.58035714285714285714285714285714286E-3f /* 5 / 896 */
84 #define SDM_ACOSHF4_TAY05 1.89887152777777777777777777777777778E-3f /* 35 / 18432 */
85 #define SDM_ACOSHF4_TAY06 -6.99129971590909090909090909090909091E-4f /* 63 / 90112 */
86 #define SDM_ACOSHF4_TAY07 2.71136944110576923076923076923076923E-4f /* 231 / 851968 */
87 #define SDM_ACOSHF4_TAY08 -1.09100341796875000000000000000000000E-4f /* 143 / 1310720 */
88 #define SDM_ACOSHF4_TAY09 4.51242222505457261029411764705882353E-5f /* 6435 / 142606336 */
89 #define SDM_ACOSHF4_TAY10 -1.90656436117071854440789473684210526E-5f /* 12155 / 637534208 */
90 #define SDM_ACOSHF4_TAY11 8.19368731407892136346726190476190476E-6f /* 46189 / 5637144576 */
91 #define SDM_ACOSHF4_TAY12 -3.57056927421818608823029891304347826E-6f /* 88179 / 24696061952 */
92 #define SDM_ACOSHF4_TAY13 1.57402595505118370056152343750000000E-6f /* 676039 / 429496729600 */
93 #define SDM_ACOSHF4_TAY14 -7.00688192241445735648826316550925926E-7f /* 1300075 / 1855425871872 */
94 #define SDM_ACOSHF4_TAY15 3.14533061665033215078814276333512931E-7f /* 5014575 / 15942918602752 */
95 #if 0
96 #define SDM_ACOSHF4_TAY16 -1.42216292935641362301764949675529234E-7f /* 9694845 / 68169720922112 */
97 #define SDM_ACOSHF4_TAY17 6.47111067761133282064375552264126864E-8f /* 100180065 / 1548112371908608 */
98 #define SDM_ACOSHF4_TAY18 -2.96094097811711825280716376645224435E-8f /* 116680311 / 3940649673949184 */
99 #define SDM_ACOSHF4_TAY19 1.36154380562817937676005090612011987E-8f /* 2268783825 / 166633186212708352 */
100 #endif
101
102
103
_acoshf4(vector float x)104 static __inline vector float _acoshf4(vector float x)
105 {
106 vec_float4 minus_onef = spu_splats(-1.0f);
107 vec_float4 twof = spu_splats(2.0f);
108 vec_float4 largef = spu_splats(2.5e19f);
109 vec_float4 xminus1;
110 /* Where we switch from taylor to formula */
111 vec_float4 switch_approx = spu_splats(2.0f);
112 vec_uint4 use_form;
113 vec_float4 result, fresult, mresult;;
114
115
116 /*
117 * Formula:
118 * acosh = ln(x + sqrt(x^2 - 1))
119 */
120 fresult = _sqrtf4(spu_madd(x, x, minus_onef));
121 fresult = spu_add(x, spu_sel(fresult, x, spu_cmpgt(x, largef)));
122 fresult = _logf4(fresult);
123 fresult = (vec_float4)spu_add((vec_uint4)fresult, spu_splats(2u));
124
125 /*
126 * Taylor Series
127 */
128 xminus1 = spu_add(x, minus_onef);
129
130 mresult = spu_splats(SDM_ACOSHF4_TAY15);
131 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY14));
132 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY13));
133 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY12));
134 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY11));
135 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY10));
136 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY09));
137 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY08));
138 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY07));
139 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY06));
140 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY05));
141 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY04));
142 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY03));
143 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY02));
144 mresult = spu_madd(xminus1, mresult, spu_splats(SDM_ACOSHF4_TAY01));
145
146 mresult = spu_mul(mresult, _sqrtf4(spu_mul(xminus1, twof)));
147 mresult = (vec_float4)spu_add((vec_uint4)mresult, spu_splats(1u));
148
149 /*
150 * Select series or formula
151 */
152 use_form = spu_cmpgt(x, switch_approx);
153 result = spu_sel(mresult, fresult, use_form);
154
155
156 return result;
157 }
158
159 #endif /* _ACOSHF4_H_ */
160 #endif /* __SPU__ */
161