1 |
207 |
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 _EXPM1F4_H_
|
41 |
|
|
#define _EXPM1F4_H_ 1
|
42 |
|
|
|
43 |
|
|
#include <spu_intrinsics.h>
|
44 |
|
|
|
45 |
|
|
#include "expf4.h"
|
46 |
|
|
#include "divf4.h"
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
#define EXPM1F4_P0 0.0000000000000000000000000e-00
|
50 |
|
|
#define EXPM1F4_P1 9.9999999999999988897769754e-01
|
51 |
|
|
#define EXPM1F4_P2 -6.5597409827762467697531701e-04
|
52 |
|
|
#define EXPM1F4_P3 2.3800889637330315679042414e-02
|
53 |
|
|
#define EXPM1F4_P4 -1.0914929910143700584950963e-05
|
54 |
|
|
|
55 |
|
|
#define EXPM1F4_Q0 1.0000000000000000000000000e-00
|
56 |
|
|
#define EXPM1F4_Q1 -5.0065597410018825019761834e-01
|
57 |
|
|
#define EXPM1F4_Q2 1.0746220997195164714721471e-01
|
58 |
|
|
#define EXPM1F4_Q3 -1.1966024153043854083566799e-02
|
59 |
|
|
#define EXPM1F4_Q4 5.9997727954467768105711878e-04
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
/*
|
63 |
|
|
* FUNCTION
|
64 |
|
|
* vector float _expm1f4(vector float x)
|
65 |
|
|
*
|
66 |
|
|
* _expm1d2 computes the exponential - 1 for each element
|
67 |
|
|
* of the input vector x.
|
68 |
|
|
*
|
69 |
|
|
* This function is intended to return accurate values, even
|
70 |
|
|
* where exp(x) - 1 would normally produce bad results due to
|
71 |
|
|
* floating-point cancellation errors.
|
72 |
|
|
*
|
73 |
|
|
*/
|
74 |
|
|
|
75 |
|
|
static __inline vector float _expm1f4(vector float x)
|
76 |
|
|
{
|
77 |
|
|
vector float onef = spu_splats(1.0f);
|
78 |
|
|
vector float rangelo = spu_splats(-0.4f);
|
79 |
|
|
vector float rangehi = spu_splats(0.35f);
|
80 |
|
|
vector unsigned int use_exp;
|
81 |
|
|
vector float pr, qr;
|
82 |
|
|
vector float eresult;
|
83 |
|
|
vector float rresult;
|
84 |
|
|
vector float result;
|
85 |
|
|
|
86 |
|
|
use_exp = spu_or(spu_cmpgt(x, rangehi), spu_cmpgt(rangelo, x));
|
87 |
|
|
|
88 |
|
|
/*
|
89 |
|
|
* Calculate directly using exp(x) - 1
|
90 |
|
|
*/
|
91 |
|
|
eresult = spu_sub(_expf4(x), onef);
|
92 |
|
|
|
93 |
|
|
/*
|
94 |
|
|
* For x in [-0.5,0.5], use a rational approximation.
|
95 |
|
|
* The madd's are interleaved to reduce dependency stalls. Looks
|
96 |
|
|
* like gcc is smart enough to do this on it's own... but why
|
97 |
|
|
* take the chance.
|
98 |
|
|
*/
|
99 |
|
|
pr = spu_madd(x, spu_splats((float)EXPM1F4_P4), spu_splats((float)EXPM1F4_P3));
|
100 |
|
|
qr = spu_madd(x, spu_splats((float)EXPM1F4_Q4), spu_splats((float)EXPM1F4_Q3));
|
101 |
|
|
pr = spu_madd(pr, x, spu_splats((float)EXPM1F4_P2));
|
102 |
|
|
qr = spu_madd(qr, x, spu_splats((float)EXPM1F4_Q2));
|
103 |
|
|
pr = spu_madd(pr, x, spu_splats((float)EXPM1F4_P1));
|
104 |
|
|
qr = spu_madd(qr, x, spu_splats((float)EXPM1F4_Q1));
|
105 |
|
|
pr = spu_madd(pr, x, spu_splats((float)EXPM1F4_P0));
|
106 |
|
|
qr = spu_madd(qr, x, spu_splats((float)EXPM1F4_Q0));
|
107 |
|
|
rresult = _divf4(pr, qr);
|
108 |
|
|
|
109 |
|
|
/*
|
110 |
|
|
* Select either direct calculation or rational approximation.
|
111 |
|
|
*/
|
112 |
|
|
result = spu_sel(rresult, eresult, use_exp);
|
113 |
|
|
|
114 |
|
|
return result;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
#endif /* _EXPM1F4_H_ */
|
118 |
|
|
#endif /* __SPU__ */
|