1 |
148 |
jeremybenn |
/* -------------------------------------------------------------- */
|
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 |
|
|
|
39 |
|
|
#ifdef __SPU__
|
40 |
|
|
|
41 |
|
|
#ifndef _ATAND2_H_
|
42 |
|
|
#define _ATAND2_H_ 1
|
43 |
|
|
|
44 |
|
|
#include <spu_intrinsics.h>
|
45 |
|
|
|
46 |
|
|
#include "simdmath.h"
|
47 |
|
|
#include "recipd2.h"
|
48 |
|
|
#include "logd2.h"
|
49 |
|
|
#include "acosd2.h"
|
50 |
|
|
#include "asind2.h"
|
51 |
|
|
#include "sqrtd2.h"
|
52 |
|
|
|
53 |
|
|
/*
|
54 |
|
|
* FUNCTION
|
55 |
|
|
* vector double _atand2(vector double x)
|
56 |
|
|
*
|
57 |
|
|
* DESCRIPTION
|
58 |
|
|
* The _atand2 function computes the arc tangent of a vector of values x.
|
59 |
|
|
*
|
60 |
|
|
* The arc tangent function is computed using the following relations:
|
61 |
|
|
* [0, 1] : arcsin(x1/sqrt(spu_add(x1squ + 1 )));
|
62 |
|
|
* (1, infinity] : PI/2 + atanf(-1/x)
|
63 |
|
|
* [-infinity, 0) : -arcsin(|x|)
|
64 |
|
|
*
|
65 |
|
|
*/
|
66 |
|
|
|
67 |
|
|
static __inline vector double _atand2(vector double x)
|
68 |
|
|
{
|
69 |
|
|
vector double signbit = spu_splats(-0.0);
|
70 |
|
|
vector double oned = spu_splats(1.0);
|
71 |
|
|
vector double pi2 = spu_splats(SM_PI_2);
|
72 |
|
|
vector double xabs, x1;
|
73 |
|
|
vector double result;
|
74 |
|
|
vector unsigned long long gt1;
|
75 |
|
|
|
76 |
|
|
xabs = spu_andc(x, signbit);
|
77 |
|
|
gt1 = spu_cmpgt(xabs, oned);
|
78 |
|
|
|
79 |
|
|
/*
|
80 |
|
|
* For x > 1, use the relation:
|
81 |
|
|
* atan(x) = pi/2 - atan(1/x), x>1
|
82 |
|
|
*/
|
83 |
|
|
x1 = spu_sel(xabs, _recipd2(xabs), gt1);
|
84 |
|
|
|
85 |
|
|
vector double x1squ = spu_mul(x1, x1);
|
86 |
|
|
|
87 |
|
|
result = _asind2(_divd2(x1, _sqrtd2(spu_add(x1squ, oned))));
|
88 |
|
|
|
89 |
|
|
/*
|
90 |
|
|
* For x > 1, use the relation: atan(x) = pi/2 - atan(1/x), x>1
|
91 |
|
|
*/
|
92 |
|
|
result = spu_sel(result, spu_sub(pi2, result), gt1);
|
93 |
|
|
|
94 |
|
|
/*
|
95 |
|
|
* Antisymmetric function - preserve sign of x in result.
|
96 |
|
|
*/
|
97 |
|
|
result = spu_sel(result, x, (vec_ullong2)signbit);
|
98 |
|
|
|
99 |
|
|
return (result);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
#endif /* _ATAND2_H_ */
|
103 |
|
|
#endif /* __SPU__ */
|