1 | /* -------------------------------------------------------------- */ |
---|
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 | #ifndef _TAND2_H_ |
---|
43 | #define _TAND2_H_ 1 |
---|
44 | |
---|
45 | #include <spu_intrinsics.h> |
---|
46 | |
---|
47 | #include "cos_sin.h" |
---|
48 | #include "divd2.h" |
---|
49 | |
---|
50 | /* |
---|
51 | * FUNCTION |
---|
52 | * vector double _tand2(vector double angle) |
---|
53 | * |
---|
54 | * DESCRIPTION |
---|
55 | * The _tand2 function computes the tangent of a vector of "angle"s |
---|
56 | * (expressed in radians) to an accuracy of double precision floating |
---|
57 | * point. |
---|
58 | * |
---|
59 | */ |
---|
60 | static __inline vector double _tand2(vector double angle) |
---|
61 | { |
---|
62 | vec_int4 octant; |
---|
63 | vec_ullong2 select; |
---|
64 | vec_double2 cos, sin; |
---|
65 | vec_double2 num, den; |
---|
66 | vec_double2 toggle_sign, answer; |
---|
67 | |
---|
68 | /* Range reduce the input angle x into the range -PI/4 to PI/4 |
---|
69 | * by performing simple modulus. |
---|
70 | */ |
---|
71 | MOD_PI_OVER_FOUR(angle, octant); |
---|
72 | |
---|
73 | /* Compute the cosine and sine of the range reduced input. |
---|
74 | */ |
---|
75 | COMPUTE_COS_SIN(angle, cos, sin); |
---|
76 | |
---|
77 | /* For each SIMD element, select the numerator, denominator, and sign |
---|
78 | * correction depending upon the octant of the original angle. |
---|
79 | * |
---|
80 | * octants angles numerator denominator sign toggle |
---|
81 | * ------- ------------ --------- ----------- ----------- |
---|
82 | * 0 0 to 45 sin cos no |
---|
83 | * 1,2 45 to 135 cos sin no,yes |
---|
84 | * 3,4 135 to 225 sin cos yes,no |
---|
85 | * 5,6 225 to 315 cos sin no,yes |
---|
86 | * 7 315 to 360 sin cos yes |
---|
87 | */ |
---|
88 | octant = spu_shuffle(octant, octant, ((vec_uchar16) { |
---|
89 | 0,1, 2, 3, 0,1, 2, 3, |
---|
90 | 8,9,10,11, 8,9,10,11 })); |
---|
91 | |
---|
92 | toggle_sign = spu_and((vec_double2)spu_sl(octant, 30), |
---|
93 | (vec_double2) spu_splats(0x8000000000000000ULL)); |
---|
94 | |
---|
95 | select = (vec_ullong2)spu_cmpeq(spu_and(octant, 2), 0); |
---|
96 | num = spu_sel(cos, sin, select); |
---|
97 | den = spu_sel(sin, cos, select); |
---|
98 | |
---|
99 | answer = spu_xor(_divd2(num, den), toggle_sign); |
---|
100 | |
---|
101 | return (answer); |
---|
102 | } |
---|
103 | |
---|
104 | #endif /* _TAND2_H_ */ |
---|
105 | #endif /* __SPU__ */ |
---|