1 |
207 |
jeremybenn |
/* -------------------------------------------------------------- */
|
2 |
|
|
/* (C)Copyright 2001,2008, */
|
3 |
|
|
/* International Business Machines Corporation, */
|
4 |
|
|
/* Sony Computer Entertainment, Incorporated, */
|
5 |
|
|
/* Toshiba Corporation, */
|
6 |
|
|
/* */
|
7 |
|
|
/* All Rights Reserved. */
|
8 |
|
|
/* */
|
9 |
|
|
/* Redistribution and use in source and binary forms, with or */
|
10 |
|
|
/* without modification, are permitted provided that the */
|
11 |
|
|
/* following conditions are met: */
|
12 |
|
|
/* */
|
13 |
|
|
/* - Redistributions of source code must retain the above copyright*/
|
14 |
|
|
/* notice, this list of conditions and the following disclaimer. */
|
15 |
|
|
/* */
|
16 |
|
|
/* - Redistributions in binary form must reproduce the above */
|
17 |
|
|
/* copyright notice, this list of conditions and the following */
|
18 |
|
|
/* disclaimer in the documentation and/or other materials */
|
19 |
|
|
/* provided with the distribution. */
|
20 |
|
|
/* */
|
21 |
|
|
/* - Neither the name of IBM Corporation nor the names of its */
|
22 |
|
|
/* contributors may be used to endorse or promote products */
|
23 |
|
|
/* derived from this software without specific prior written */
|
24 |
|
|
/* permission. */
|
25 |
|
|
/* */
|
26 |
|
|
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
|
27 |
|
|
/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
28 |
|
|
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
29 |
|
|
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
30 |
|
|
/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
|
31 |
|
|
/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
|
32 |
|
|
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
|
33 |
|
|
/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
|
34 |
|
|
/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
|
35 |
|
|
/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
|
36 |
|
|
/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
|
37 |
|
|
/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
|
38 |
|
|
/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
39 |
|
|
/* -------------------------------------------------------------- */
|
40 |
|
|
/* PROLOG END TAG zYx */
|
41 |
|
|
#ifdef __SPU__
|
42 |
|
|
|
43 |
|
|
#ifndef _ASINF4_H_
|
44 |
|
|
#define _ASINF4_H_ 1
|
45 |
|
|
|
46 |
|
|
#include <spu_intrinsics.h>
|
47 |
|
|
|
48 |
|
|
#include "divf4.h"
|
49 |
|
|
#include "sqrtf4.h"
|
50 |
|
|
|
51 |
|
|
/*
|
52 |
|
|
* FUNCTION
|
53 |
|
|
* vector float _asinf4(vector float x)
|
54 |
|
|
*
|
55 |
|
|
* DESCRIPTION
|
56 |
|
|
* The _asinf4 function computes the arc sine for a vector of values x;
|
57 |
|
|
* that is the values whose sine is x. Results are undefined if x is
|
58 |
|
|
* outside the range [-1, 1].
|
59 |
|
|
*
|
60 |
|
|
*/
|
61 |
|
|
static __inline vector float _asinf4(vector float x)
|
62 |
|
|
{
|
63 |
|
|
/* The arcsin is computed using two different algorithms, depending
|
64 |
|
|
* upon the absolute value of the input. For inputs in the range
|
65 |
|
|
* [0, PI/4], it is computed as the ratio of two polynomials.
|
66 |
|
|
*
|
67 |
|
|
* asin(x) = p/q;
|
68 |
|
|
*
|
69 |
|
|
* where p = P11*x^11 + P09*x^9 + P07*x^7 + P05*x^5 + P03*x3 + x
|
70 |
|
|
* q = Q08*x^8 + Q06*x^6 + Q04*x^4 + Q02*x^2 + Q00
|
71 |
|
|
*
|
72 |
|
|
* For the range of value [PI/4, 1], the arcsin is computed using:
|
73 |
|
|
*
|
74 |
|
|
* asin = PI/2 - sqrt(1 - x) * r;
|
75 |
|
|
*
|
76 |
|
|
* where r = C07*x^7 + C06*x^6 + C05*x^5 + C04*x^4 + C03*x^3 + C02*x^2
|
77 |
|
|
* C01*x + C00;
|
78 |
|
|
*/
|
79 |
|
|
vector float r, r1, r2, r_hi, r_lo;
|
80 |
|
|
vector float xabs, x2, x4, x6;
|
81 |
|
|
vector float p, p_hi, p_lo;
|
82 |
|
|
vector float q, q_hi, q_lo;
|
83 |
|
|
vector float pi_over_2 = spu_splats(1.5707963267949f);
|
84 |
|
|
vector float pi_over_4 = spu_splats(0.7853981633974f);
|
85 |
|
|
vector unsigned int msb = spu_splats(0x80000000);
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
x2 = spu_mul(x, x);
|
89 |
|
|
x4 = spu_mul(x2, x2);
|
90 |
|
|
x6 = spu_mul(x4, x2);
|
91 |
|
|
|
92 |
|
|
xabs = spu_andc(x, (vector float)msb);
|
93 |
|
|
|
94 |
|
|
/* Compute arc-sin for values in the range [0, PI/4]
|
95 |
|
|
*/
|
96 |
|
|
p_hi = spu_madd(spu_splats(0.0000347933107596021167570f), x2,
|
97 |
|
|
spu_splats(0.000791534994289814532176f));
|
98 |
|
|
p_hi = spu_madd(p_hi, x2, spu_splats(-0.0400555345006794114027f));
|
99 |
|
|
|
100 |
|
|
p_lo = spu_madd(spu_splats(0.201212532134862925881f), x2,
|
101 |
|
|
spu_splats(-0.325565818622400915405f));
|
102 |
|
|
p_lo = spu_madd(p_lo, x2, spu_splats(0.166666666666666657415f));
|
103 |
|
|
|
104 |
|
|
p = spu_madd(p_hi, x6, p_lo);
|
105 |
|
|
|
106 |
|
|
q_hi = spu_madd(spu_splats(0.0770381505559019352791f), x2,
|
107 |
|
|
spu_splats(-0.688283971605453293030f));
|
108 |
|
|
q_hi = spu_madd(q_hi, x2, spu_splats(2.02094576023350569471f));
|
109 |
|
|
|
110 |
|
|
q_lo = spu_madd(spu_splats(-2.40339491173441421878f), x2,
|
111 |
|
|
spu_splats(1.0f));
|
112 |
|
|
|
113 |
|
|
q = spu_madd(q_hi, x4, q_lo);
|
114 |
|
|
|
115 |
|
|
r1 = spu_madd(_divf4(p, q), spu_mul(xabs, x2), xabs);
|
116 |
|
|
|
117 |
|
|
/* Compute arc-sin for values in the range [PI/4, 1]
|
118 |
|
|
*/
|
119 |
|
|
r_hi = spu_madd(spu_splats(-0.0012624911f), xabs,
|
120 |
|
|
spu_splats(0.0066700901f));
|
121 |
|
|
r_hi = spu_madd(r_hi, xabs, spu_splats(-0.0170881256f));
|
122 |
|
|
r_hi = spu_madd(r_hi, xabs, spu_splats(0.0308918810f));
|
123 |
|
|
|
124 |
|
|
r_lo = spu_madd(spu_splats(-0.0501743046f), xabs,
|
125 |
|
|
spu_splats(0.0889789874f));
|
126 |
|
|
r_lo = spu_madd(r_lo, xabs, spu_splats(-0.2145988016f));
|
127 |
|
|
r_lo = spu_madd(r_lo, xabs, pi_over_2);
|
128 |
|
|
|
129 |
|
|
r = spu_madd(r_hi, x4, r_lo);
|
130 |
|
|
|
131 |
|
|
r2 = spu_nmsub(r, _sqrtf4(spu_sub(spu_splats(1.0f), xabs)),
|
132 |
|
|
pi_over_2);
|
133 |
|
|
|
134 |
|
|
/* Select the result depending upon the input value. Correct the
|
135 |
|
|
* sign of the result.
|
136 |
|
|
*/
|
137 |
|
|
return (spu_sel(spu_sel(r1, r2, spu_cmpgt(xabs, pi_over_4)),
|
138 |
|
|
x, msb));
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
#endif /* _ASINF4_H_ */
|
142 |
|
|
#endif /* __SPU__ */
|
143 |
|
|
|
144 |
|
|
|