1 |
148 |
jeremybenn |
/* -------------------------------------------------------------- */
|
2 |
|
|
/* (C)Copyright 2006,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 _SINHF4_H_
|
40 |
|
|
#define _SINHF4_H_ 1
|
41 |
|
|
|
42 |
|
|
#include <spu_intrinsics.h>
|
43 |
|
|
|
44 |
|
|
#include "expf4.h"
|
45 |
|
|
#include "recipf4.h"
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
/*
|
49 |
|
|
* FUNCTION
|
50 |
|
|
* vector float _sinhf4(vector float angle)
|
51 |
|
|
*
|
52 |
|
|
* DESCRIPTION
|
53 |
|
|
* The _sinhf4 function computes the hyperbolic sine of a vector of
|
54 |
|
|
* angles (expressed in radians) to an accuracy of a single precision
|
55 |
|
|
* floating point.
|
56 |
|
|
*
|
57 |
|
|
*/
|
58 |
|
|
static __inline vector float _sinhf4(vector float x)
|
59 |
|
|
{
|
60 |
|
|
// 1.0000 (above this number, use sinh(x) = 0.5 * (e^x - e^-x)
|
61 |
|
|
vec_uint4 threshold = (vec_uint4)spu_splats(0x3F800000);
|
62 |
|
|
|
63 |
|
|
vec_uint4 sign_mask = (vec_uint4)spu_splats(0x80000000);
|
64 |
|
|
|
65 |
|
|
// Coefficents for the Taylor series
|
66 |
|
|
vec_float4 f03 = spu_splats(1.6666666666666667E-1f); // 1/3!
|
67 |
|
|
vec_float4 f05 = spu_splats(8.3333333333333333E-3f); // 1/5!
|
68 |
|
|
vec_float4 f07 = spu_splats(1.9841269841269841E-4f); // 1/7!
|
69 |
|
|
vec_float4 f09 = spu_splats(2.7557319223985891E-6f); // 1/9!
|
70 |
|
|
vec_float4 f11 = spu_splats(2.5052108385441719E-8f); // 1/11!
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
// Perform the calculation as a Taylor series
|
74 |
|
|
vec_float4 result;
|
75 |
|
|
vec_float4 x2 = spu_mul(x,x);
|
76 |
|
|
result = spu_madd(x2,f11,f09);
|
77 |
|
|
result = spu_madd(x2,result,f07);
|
78 |
|
|
result = spu_madd(x2,result,f05);
|
79 |
|
|
result = spu_madd(x2,result,f03);
|
80 |
|
|
result = spu_madd(x2,result,spu_splats(1.0f));
|
81 |
|
|
result = spu_mul(x,result);
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
// Perform calculation as a function of 0.5 * (e^x - e^-x)
|
85 |
|
|
vec_float4 ex =_expf4(x);
|
86 |
|
|
vec_float4 ex_inv = _recipf4(ex);
|
87 |
|
|
|
88 |
|
|
vec_float4 r2= spu_sub(ex,ex_inv);
|
89 |
|
|
r2 = spu_mul(r2,spu_splats(0.5f));
|
90 |
|
|
|
91 |
|
|
vec_uint4 xabs = spu_andc((vec_uint4)x,sign_mask);
|
92 |
|
|
vec_uint4 use_exp = spu_cmpgt(xabs,threshold);
|
93 |
|
|
|
94 |
|
|
// Select either the Taylor or exp version
|
95 |
|
|
result = spu_sel(result,r2,use_exp);
|
96 |
|
|
|
97 |
|
|
// Flip the sign if needed
|
98 |
|
|
result = (vec_float4)spu_or((vec_uint4)result,spu_and((vec_uint4)x,sign_mask));
|
99 |
|
|
|
100 |
|
|
return result;
|
101 |
|
|
|
102 |
|
|
}
|
103 |
|
|
#endif /* _SINHF4_H_ */
|
104 |
|
|
#endif /* __SPU__ */
|