~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to extern/fftw/simd/simd-altivec.h

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2003, 2006 Matteo Frigo
 
3
 * Copyright (c) 2003, 2006 Massachusetts Institute of Technology
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef FFTW_SINGLE
 
22
#error "ALTIVEC only works in single precision"
 
23
#endif
 
24
 
 
25
/* define these unconditionally, because they are used by
 
26
   taint.c which is compiled without altivec */
 
27
#define VL 2            /* SIMD complex vector length */
 
28
#define ALIGNMENT 8     /* alignment for LD/ST */
 
29
#define ALIGNMENTA 16   /* alignment for LDA/STA */
 
30
#define SIMD_VSTRIDE_OKA(x) ((x) == 2)
 
31
#define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OKA
 
32
 
 
33
#define RIGHT_CPU X(have_altivec)
 
34
extern int RIGHT_CPU(void);
 
35
 
 
36
#if defined(__VEC__) || defined(FAKE__VEC__)
 
37
 
 
38
#ifdef HAVE_ALTIVEC_H
 
39
#include <altivec.h>
 
40
#endif
 
41
 
 
42
typedef vector float V;
 
43
#define VLIT(x0, x1, x2, x3) {x0, x1, x2, x3}
 
44
#define LDK(x) x
 
45
#define DVK(var, val) const V var = VLIT(val, val, val, val)
 
46
 
 
47
static inline V VADD(V a, V b) { return vec_add(a, b); }
 
48
static inline V VSUB(V a, V b) { return vec_sub(a, b); }
 
49
static inline V VFMA(V a, V b, V c) { return vec_madd(a, b, c); }
 
50
static inline V VFNMS(V a, V b, V c) { return vec_nmsub(a, b, c); }
 
51
 
 
52
static inline V VMUL(V a, V b)
 
53
{
 
54
     DVK(zero, -0.0);
 
55
     return VFMA(a, b, zero);
 
56
}
 
57
 
 
58
static inline V VFMS(V a, V b, V c) { return VSUB(VMUL(a, b), c); }
 
59
 
 
60
static inline V LDA(const R *x, INT ivs, const R *aligned_like) 
 
61
{
 
62
     UNUSED(ivs);
 
63
     UNUSED(aligned_like);
 
64
     return vec_ld(0, x);
 
65
}
 
66
 
 
67
static inline V LD(const R *x, INT ivs, const R *aligned_like) 
 
68
{
 
69
     /* common subexpressions */
 
70
     const INT fivs = sizeof(R) * ivs;
 
71
       /* you are not expected to understand this: */
 
72
     const vector unsigned int perm = VLIT(0, 0, 0xFFFFFFFF, 0xFFFFFFFF);
 
73
     vector unsigned char ml = vec_lvsr(fivs + 8, aligned_like);
 
74
     vector unsigned char mh = vec_lvsl(0, aligned_like);
 
75
     vector unsigned char msk = 
 
76
          (vector unsigned char)vec_sel((V)mh, (V)ml, perm);
 
77
     /* end of common subexpressions */
 
78
 
 
79
     return vec_perm(vec_ld(0, x), vec_ld(fivs, x), msk);
 
80
}
 
81
 
 
82
/* store lower half */
 
83
static inline void STH(R *x, V v, R *aligned_like)
 
84
{
 
85
     v = vec_perm(v, v, vec_lvsr(0, aligned_like));
 
86
     vec_ste(v, 0, x);
 
87
     vec_ste(v, sizeof(R), x);
 
88
}
 
89
 
 
90
static inline void STL(R *x, V v, INT ovs, R *aligned_like)
 
91
{
 
92
     const INT fovs = sizeof(R) * ovs;
 
93
     v = vec_perm(v, v, vec_lvsr(fovs + 8, aligned_like));
 
94
     vec_ste(v, fovs, x);
 
95
     vec_ste(v, sizeof(R) + fovs, x);
 
96
}
 
97
 
 
98
static inline void STA(R *x, V v, INT ovs, R *aligned_like) 
 
99
{
 
100
     UNUSED(ovs);
 
101
     UNUSED(aligned_like);
 
102
     vec_st(v, 0, x);
 
103
}
 
104
 
 
105
static inline void ST(R *x, V v, INT ovs, R *aligned_like) 
 
106
{
 
107
     STH(x, v, aligned_like);
 
108
     STL(x, v, ovs, aligned_like);
 
109
}
 
110
 
 
111
#define STM2(x, v, ovs, aligned_like) /* no-op */
 
112
 
 
113
static inline void STN2(R *x, V v0, V v1, INT ovs)
 
114
{
 
115
     const INT fovs = sizeof(R) * ovs;
 
116
     const vector unsigned int even = 
 
117
          VLIT(0x00010203, 0x04050607, 0x10111213, 0x14151617);
 
118
     const vector unsigned int odd = 
 
119
          VLIT(0x08090a0b, 0x0c0d0e0f, 0x18191a1b, 0x1c1d1e1f);
 
120
     vec_st(vec_perm(v0, v1, (vector unsigned char)even), 0, x);
 
121
     vec_st(vec_perm(v0, v1, (vector unsigned char)odd), fovs, x);
 
122
}
 
123
 
 
124
#define STM4(x, v, ovs, aligned_like) /* no-op */
 
125
 
 
126
static inline void STN4(R *x, V v0, V v1, V v2, V v3, INT ovs)
 
127
{
 
128
     const INT fovs = sizeof(R) * ovs;
 
129
     V x0 = vec_mergeh(v0, v2);
 
130
     V x1 = vec_mergel(v0, v2);
 
131
     V x2 = vec_mergeh(v1, v3);
 
132
     V x3 = vec_mergel(v1, v3);
 
133
     V y0 = vec_mergeh(x0, x2);
 
134
     V y1 = vec_mergel(x0, x2);
 
135
     V y2 = vec_mergeh(x1, x3);
 
136
     V y3 = vec_mergel(x1, x3);
 
137
     vec_st(y0, 0, x);
 
138
     vec_st(y1, fovs, x);
 
139
     vec_st(y2, 2 * fovs, x);
 
140
     vec_st(y3, 3 * fovs, x);
 
141
}
 
142
 
 
143
static inline V FLIP_RI(V x)
 
144
{
 
145
     const vector unsigned int perm = 
 
146
          VLIT(0x04050607, 0x00010203, 0x0c0d0e0f, 0x08090a0b);
 
147
     return vec_perm(x, x, (vector unsigned char)perm);
 
148
}
 
149
 
 
150
static inline V CHS_R(V x)
 
151
{
 
152
     const V pmpm = VLIT(-0.0, 0.0, -0.0, 0.0);
 
153
     return vec_xor(x, pmpm);
 
154
}
 
155
 
 
156
static inline V VBYI(V x)
 
157
{
 
158
     return CHS_R(FLIP_RI(x));
 
159
}
 
160
 
 
161
static inline V VFMAI(V b, V c)
 
162
{
 
163
     const V pmpm = VLIT(-1.0, 1.0, -1.0, 1.0);
 
164
     return VFMA(FLIP_RI(b), pmpm, c);
 
165
}
 
166
 
 
167
static inline V VFNMSI(V b, V c)
 
168
{
 
169
     const V pmpm = VLIT(-1.0, 1.0, -1.0, 1.0);
 
170
     return VFNMS(FLIP_RI(b), pmpm, c);
 
171
}
 
172
 
 
173
static inline V VZMUL(V tx, V sr)
 
174
{
 
175
     const vector unsigned int real = 
 
176
          VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b);
 
177
     const vector unsigned int imag = 
 
178
          VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f);
 
179
     V si = VBYI(sr);
 
180
     V tr = vec_perm(tx, tx, (vector unsigned char)real);
 
181
     V ti = vec_perm(tx, tx, (vector unsigned char)imag);
 
182
     return VFMA(ti, si, VMUL(tr, sr));
 
183
}
 
184
 
 
185
static inline V VZMULJ(V tx, V sr)
 
186
{
 
187
     const vector unsigned int real = 
 
188
          VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b);
 
189
     const vector unsigned int imag = 
 
190
          VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f);
 
191
     V si = VBYI(sr);
 
192
     V tr = vec_perm(tx, tx, (vector unsigned char)real);
 
193
     V ti = vec_perm(tx, tx, (vector unsigned char)imag);
 
194
     return VFNMS(ti, si, VMUL(tr, sr));
 
195
}
 
196
 
 
197
/* twiddle storage #1: compact, slower */
 
198
#define VTW1(x) {TW_COS, 0, x}, {TW_COS, 1, x}, {TW_SIN, 0, x}, {TW_SIN, 1, x}
 
199
#define TWVL1 (VL)
 
200
 
 
201
static inline V BYTW1(const R *t, V sr)
 
202
{
 
203
     const V *twp = (const V *)t;
 
204
     V si = VBYI(sr);
 
205
     V tx = twp[0];
 
206
     V tr = vec_mergeh(tx, tx);
 
207
     V ti = vec_mergel(tx, tx);
 
208
     return VFMA(ti, si, VMUL(tr, sr));
 
209
}
 
210
 
 
211
static inline V BYTWJ1(const R *t, V sr)
 
212
{
 
213
     const V *twp = (const V *)t;
 
214
     V si = VBYI(sr);
 
215
     V tx = twp[0];
 
216
     V tr = vec_mergeh(tx, tx);
 
217
     V ti = vec_mergel(tx, tx);
 
218
     return VFNMS(ti, si, VMUL(tr, sr));
 
219
}
 
220
 
 
221
/* twiddle storage #2: twice the space, faster (when in cache) */
 
222
#define VTW2(x)                                                         \
 
223
  {TW_COS, 0, x}, {TW_COS, 0, x}, {TW_COS, 1, x}, {TW_COS, 1, x},       \
 
224
  {TW_SIN, 0, -x}, {TW_SIN, 0, x}, {TW_SIN, 1, -x}, {TW_SIN, 1, x}
 
225
#define TWVL2 (2 * VL)
 
226
 
 
227
static inline V BYTW2(const R *t, V sr)
 
228
{
 
229
     const V *twp = (const V *)t;
 
230
     V si = FLIP_RI(sr);
 
231
     V tr = twp[0], ti = twp[1];
 
232
     return VFMA(ti, si, VMUL(tr, sr));
 
233
}
 
234
 
 
235
static inline V BYTWJ2(const R *t, V sr)
 
236
{
 
237
     const V *twp = (const V *)t;
 
238
     V si = FLIP_RI(sr);
 
239
     V tr = twp[0], ti = twp[1];
 
240
     return VFNMS(ti, si, VMUL(tr, sr));
 
241
}
 
242
 
 
243
/* twiddle storage #3 */
 
244
#define VTW3(x) {TW_CEXP, 0, x}, {TW_CEXP, 1, x}
 
245
#define TWVL3 (VL)
 
246
 
 
247
/* twiddle storage for split arrays */
 
248
#define VTWS(x)                                                         \
 
249
  {TW_COS, 0, x}, {TW_COS, 1, x}, {TW_COS, 2, x}, {TW_COS, 3, x},       \
 
250
  {TW_SIN, 0, x}, {TW_SIN, 1, x}, {TW_SIN, 2, x}, {TW_SIN, 3, x}
 
251
#define TWVLS (2 * VL)
 
252
 
 
253
#endif /* #ifdef __VEC__ */