[444] | 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 _ATAN2D2_H_ |
---|
| 40 | #define _ATAN2D2_H_ 1 |
---|
| 41 | |
---|
| 42 | #include <spu_intrinsics.h> |
---|
| 43 | |
---|
| 44 | #include "divd2.h" |
---|
| 45 | #include "atand2.h" |
---|
| 46 | |
---|
| 47 | /* |
---|
| 48 | * FUNCTION |
---|
| 49 | * vector double _atan2d2(vector double y, vector double x) |
---|
| 50 | * |
---|
| 51 | * DESCRIPTION |
---|
| 52 | * The atan2d2 function returns a vector containing the angles |
---|
| 53 | * whose tangets are y/x for the corresponding elements of the |
---|
| 54 | * input vectors. |
---|
| 55 | * |
---|
| 56 | * The reason this function exists is to use the signs of the |
---|
| 57 | * arguments to determine the quadrant of the result. Consider |
---|
| 58 | * sin(x)/cos(x) on the domain (-pi, pi]. Four quadrants are |
---|
| 59 | * defined by the signs of sin and cos on this domain. |
---|
| 60 | * |
---|
| 61 | * Special Cases: |
---|
| 62 | * - If the corresponding elements of x and y are zero, the |
---|
| 63 | * resulting element is undefined. |
---|
| 64 | * |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | static __inline vector double _atan2d2(vector double y, vector double x) |
---|
| 68 | { |
---|
| 69 | vec_uchar16 dup_even = ((vec_uchar16) { 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 }); |
---|
| 70 | vector double pi = spu_splats(SM_PI); |
---|
| 71 | vector unsigned long long ones = spu_splats(0xFFFFFFFFFFFFFFFFull); |
---|
| 72 | vector unsigned long long quad1; |
---|
| 73 | vector unsigned long long quad4; |
---|
| 74 | vector double result; |
---|
| 75 | |
---|
| 76 | vector unsigned long long xlt0; |
---|
| 77 | vector unsigned long long yge0; |
---|
| 78 | vector unsigned long long ylt0; |
---|
| 79 | |
---|
| 80 | xlt0 = (vec_ullong2)spu_rlmaska((vec_int4)spu_shuffle(x,x,dup_even), 31); |
---|
| 81 | ylt0 = (vec_ullong2)spu_rlmaska((vec_int4)spu_shuffle(y,y,dup_even), 31); |
---|
| 82 | yge0 = spu_xor(ylt0, ones); |
---|
| 83 | |
---|
| 84 | quad1 = spu_and(ylt0, xlt0); |
---|
| 85 | quad4 = spu_and(yge0, xlt0); |
---|
| 86 | |
---|
| 87 | result = _atand2(_divd2(y,x)); |
---|
| 88 | |
---|
| 89 | result = spu_sel(result, spu_sub(result, pi), quad1); |
---|
| 90 | result = spu_sel(result, spu_add(result, pi), quad4); |
---|
| 91 | |
---|
| 92 | return result; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | #endif /* _ATAN2D2_H_ */ |
---|
| 96 | #endif /* __SPU__ */ |
---|