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 |
|
|
#ifdef __SPU__
|
39 |
|
|
|
40 |
|
|
#ifndef _EXPM1D2_H_
|
41 |
|
|
#define _EXPM1D2_H_ 1
|
42 |
|
|
|
43 |
|
|
#include <spu_intrinsics.h>
|
44 |
|
|
|
45 |
|
|
#include "expd2.h"
|
46 |
|
|
#include "divd2.h"
|
47 |
|
|
|
48 |
|
|
#define EXPM1_P0 0.0000000000000000000000000e+00
|
49 |
|
|
#define EXPM1_P1 1.0000000000000000000000000e+00
|
50 |
|
|
#define EXPM1_P2 9.7234232565378004697204117e-04
|
51 |
|
|
#define EXPM1_P3 3.3328278237299953368211192e-02
|
52 |
|
|
#define EXPM1_P4 3.1156225044634678993365345e-05
|
53 |
|
|
#define EXPM1_P5 2.1352206553343212164751408e-04
|
54 |
|
|
#define EXPM1_P6 1.6975135794626144795757452e-07
|
55 |
|
|
#define EXPM1_P7 2.7686287801334994383131629e-07
|
56 |
|
|
#define EXPM1_P8 1.1186114936216450015354379e-10
|
57 |
|
|
|
58 |
|
|
#define EXPM1_Q0 1.0000000000000000000000000e+00
|
59 |
|
|
#define EXPM1_Q1 -4.9902765767434620336473472e-01
|
60 |
|
|
#define EXPM1_Q2 1.1617544040780639069687652e-01
|
61 |
|
|
#define EXPM1_Q3 -1.6551954366467523660499950e-02
|
62 |
|
|
#define EXPM1_Q4 1.5864115838972218334307351e-03
|
63 |
|
|
#define EXPM1_Q5 -1.0534540477401370666288988e-04
|
64 |
|
|
#define EXPM1_Q6 4.7650003993592160620959043e-06
|
65 |
|
|
#define EXPM1_Q7 -1.3529198871087017840776265e-07
|
66 |
|
|
#define EXPM1_Q8 1.8635779407675460757658020e-09
|
67 |
|
|
|
68 |
|
|
/*
|
69 |
|
|
* FUNCTION
|
70 |
|
|
* vector double _expm1d2(vector double x)
|
71 |
|
|
*
|
72 |
|
|
* DESCRIPTION
|
73 |
|
|
* _expm1d2 computes the exponential - 1 for each element
|
74 |
|
|
* of the input vector x.
|
75 |
|
|
*
|
76 |
|
|
* This function is intended to return accurate values, even
|
77 |
|
|
* where exp(x) - 1 would normally produce bad results due to
|
78 |
|
|
* floating-point cancellation errors.
|
79 |
|
|
*
|
80 |
|
|
*/
|
81 |
|
|
|
82 |
|
|
static __inline vector double _expm1d2(vector double x)
|
83 |
|
|
{
|
84 |
|
|
vector double oned = spu_splats(1.0);
|
85 |
|
|
vector double range = spu_splats(1.0625);
|
86 |
|
|
vector unsigned long long use_exp;
|
87 |
|
|
vector double pr, qr;
|
88 |
|
|
vector double eresult;
|
89 |
|
|
vector double rresult;
|
90 |
|
|
vector double result;
|
91 |
|
|
|
92 |
|
|
/* Compiler Bug. Replace xbug with x when spu_cmp*() doesn't
|
93 |
|
|
* modify it's arguments! */
|
94 |
|
|
volatile vector double xbug = x;
|
95 |
|
|
use_exp = spu_cmpabsgt(xbug, range);
|
96 |
|
|
|
97 |
|
|
/*
|
98 |
|
|
* Calculate directly using exp(x) - 1
|
99 |
|
|
*/
|
100 |
|
|
eresult = spu_sub(_expd2(x), oned);
|
101 |
|
|
|
102 |
|
|
/*
|
103 |
|
|
* For x in [-1.0625,1.0625], use a rational approximation.
|
104 |
|
|
* The madd's are interleaved to reduce dependency stalls. Looks
|
105 |
|
|
* like gcc is smart enough to do this on it's own... but why
|
106 |
|
|
* take the chance.
|
107 |
|
|
*/
|
108 |
|
|
pr = spu_madd(x, spu_splats(EXPM1_P8), spu_splats(EXPM1_P7));
|
109 |
|
|
qr = spu_madd(x, spu_splats(EXPM1_Q8), spu_splats(EXPM1_Q7));
|
110 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P6));
|
111 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q6));
|
112 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P5));
|
113 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q5));
|
114 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P4));
|
115 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q4));
|
116 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P3));
|
117 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q3));
|
118 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P2));
|
119 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q2));
|
120 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P1));
|
121 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q1));
|
122 |
|
|
pr = spu_madd(pr, x, spu_splats(EXPM1_P0));
|
123 |
|
|
qr = spu_madd(qr, x, spu_splats(EXPM1_Q0));
|
124 |
|
|
rresult = _divd2(pr, qr);
|
125 |
|
|
|
126 |
|
|
/*
|
127 |
|
|
* Select either direct calculation or rational approximation.
|
128 |
|
|
*/
|
129 |
|
|
result = spu_sel(rresult, eresult, use_exp);
|
130 |
|
|
|
131 |
|
|
return result;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
#endif /* _EXPM1D2_H_ */
|
135 |
|
|
#endif /* __SPU__ */
|