Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.3/simd-support/simd-altivec.h @ 10:37bf6b4a2645
Add FFTW3
author | Chris Cannam |
---|---|
date | Wed, 20 Mar 2013 15:35:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:c0fb53affa76 | 10:37bf6b4a2645 |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-11 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-11 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 SIMD_SUFFIX _altivec /* for renaming */ | |
28 #define VL 2 /* SIMD complex vector length */ | |
29 #define SIMD_VSTRIDE_OKA(x) ((x) == 2) | |
30 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OKA | |
31 | |
32 #if !defined(__VEC__) && !defined(FAKE__VEC__) | |
33 # error "compiling simd-altivec.h requires -maltivec or equivalent" | |
34 #endif | |
35 | |
36 #ifdef HAVE_ALTIVEC_H | |
37 # include <altivec.h> | |
38 #endif | |
39 | |
40 typedef vector float V; | |
41 #define VLIT(x0, x1, x2, x3) {x0, x1, x2, x3} | |
42 #define LDK(x) x | |
43 #define DVK(var, val) const V var = VLIT(val, val, val, val) | |
44 | |
45 static inline V VADD(V a, V b) { return vec_add(a, b); } | |
46 static inline V VSUB(V a, V b) { return vec_sub(a, b); } | |
47 static inline V VFMA(V a, V b, V c) { return vec_madd(a, b, c); } | |
48 static inline V VFNMS(V a, V b, V c) { return vec_nmsub(a, b, c); } | |
49 | |
50 static inline V VMUL(V a, V b) | |
51 { | |
52 DVK(zero, -0.0); | |
53 return VFMA(a, b, zero); | |
54 } | |
55 | |
56 static inline V VFMS(V a, V b, V c) { return VSUB(VMUL(a, b), c); } | |
57 | |
58 static inline V LDA(const R *x, INT ivs, const R *aligned_like) | |
59 { | |
60 UNUSED(ivs); | |
61 UNUSED(aligned_like); | |
62 return vec_ld(0, x); | |
63 } | |
64 | |
65 static inline V LD(const R *x, INT ivs, const R *aligned_like) | |
66 { | |
67 /* common subexpressions */ | |
68 const INT fivs = sizeof(R) * ivs; | |
69 /* you are not expected to understand this: */ | |
70 const vector unsigned int perm = VLIT(0, 0, 0xFFFFFFFF, 0xFFFFFFFF); | |
71 vector unsigned char ml = vec_lvsr(fivs + 8, aligned_like); | |
72 vector unsigned char mh = vec_lvsl(0, aligned_like); | |
73 vector unsigned char msk = | |
74 (vector unsigned char)vec_sel((V)mh, (V)ml, perm); | |
75 /* end of common subexpressions */ | |
76 | |
77 return vec_perm(vec_ld(0, x), vec_ld(fivs, x), msk); | |
78 } | |
79 | |
80 /* store lower half */ | |
81 static inline void STH(R *x, V v, R *aligned_like) | |
82 { | |
83 v = vec_perm(v, v, vec_lvsr(0, aligned_like)); | |
84 vec_ste(v, 0, x); | |
85 vec_ste(v, sizeof(R), x); | |
86 } | |
87 | |
88 static inline void STL(R *x, V v, INT ovs, R *aligned_like) | |
89 { | |
90 const INT fovs = sizeof(R) * ovs; | |
91 v = vec_perm(v, v, vec_lvsr(fovs + 8, aligned_like)); | |
92 vec_ste(v, fovs, x); | |
93 vec_ste(v, sizeof(R) + fovs, x); | |
94 } | |
95 | |
96 static inline void STA(R *x, V v, INT ovs, R *aligned_like) | |
97 { | |
98 UNUSED(ovs); | |
99 UNUSED(aligned_like); | |
100 vec_st(v, 0, x); | |
101 } | |
102 | |
103 static inline void ST(R *x, V v, INT ovs, R *aligned_like) | |
104 { | |
105 /* WARNING: the extra_iter hack depends upon STH occurring after | |
106 STL */ | |
107 STL(x, v, ovs, aligned_like); | |
108 STH(x, v, 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 VCONJ(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 FLIP_RI(VCONJ(x)); | |
159 } | |
160 | |
161 static inline V VFMAI(V b, V c) | |
162 { | |
163 const V mpmp = VLIT(-1.0, 1.0, -1.0, 1.0); | |
164 return VFMA(FLIP_RI(b), mpmp, c); | |
165 } | |
166 | |
167 static inline V VFNMSI(V b, V c) | |
168 { | |
169 const V mpmp = VLIT(-1.0, 1.0, -1.0, 1.0); | |
170 return VFNMS(FLIP_RI(b), mpmp, c); | |
171 } | |
172 | |
173 static inline V VFMACONJ(V b, V c) | |
174 { | |
175 const V pmpm = VLIT(1.0, -1.0, 1.0, -1.0); | |
176 return VFMA(b, pmpm, c); | |
177 } | |
178 | |
179 static inline V VFNMSCONJ(V b, V c) | |
180 { | |
181 const V pmpm = VLIT(1.0, -1.0, 1.0, -1.0); | |
182 return VFNMS(b, pmpm, c); | |
183 } | |
184 | |
185 static inline V VFMSCONJ(V b, V c) | |
186 { | |
187 return VSUB(VCONJ(b), c); | |
188 } | |
189 | |
190 static inline V VZMUL(V tx, V sr) | |
191 { | |
192 const vector unsigned int real = | |
193 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b); | |
194 const vector unsigned int imag = | |
195 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f); | |
196 V si = VBYI(sr); | |
197 V tr = vec_perm(tx, tx, (vector unsigned char)real); | |
198 V ti = vec_perm(tx, tx, (vector unsigned char)imag); | |
199 return VFMA(ti, si, VMUL(tr, sr)); | |
200 } | |
201 | |
202 static inline V VZMULJ(V tx, V sr) | |
203 { | |
204 const vector unsigned int real = | |
205 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b); | |
206 const vector unsigned int imag = | |
207 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f); | |
208 V si = VBYI(sr); | |
209 V tr = vec_perm(tx, tx, (vector unsigned char)real); | |
210 V ti = vec_perm(tx, tx, (vector unsigned char)imag); | |
211 return VFNMS(ti, si, VMUL(tr, sr)); | |
212 } | |
213 | |
214 static inline V VZMULI(V tx, V si) | |
215 { | |
216 const vector unsigned int real = | |
217 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b); | |
218 const vector unsigned int imag = | |
219 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f); | |
220 V sr = VBYI(si); | |
221 V tr = vec_perm(tx, tx, (vector unsigned char)real); | |
222 V ti = vec_perm(tx, tx, (vector unsigned char)imag); | |
223 return VFNMS(ti, si, VMUL(tr, sr)); | |
224 } | |
225 | |
226 static inline V VZMULIJ(V tx, V si) | |
227 { | |
228 const vector unsigned int real = | |
229 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b); | |
230 const vector unsigned int imag = | |
231 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f); | |
232 V sr = VBYI(si); | |
233 V tr = vec_perm(tx, tx, (vector unsigned char)real); | |
234 V ti = vec_perm(tx, tx, (vector unsigned char)imag); | |
235 return VFMA(ti, si, VMUL(tr, sr)); | |
236 } | |
237 | |
238 /* twiddle storage #1: compact, slower */ | |
239 #define VTW1(v,x) \ | |
240 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
241 #define TWVL1 (VL) | |
242 | |
243 static inline V BYTW1(const R *t, V sr) | |
244 { | |
245 const V *twp = (const V *)t; | |
246 V si = VBYI(sr); | |
247 V tx = twp[0]; | |
248 V tr = vec_mergeh(tx, tx); | |
249 V ti = vec_mergel(tx, tx); | |
250 return VFMA(ti, si, VMUL(tr, sr)); | |
251 } | |
252 | |
253 static inline V BYTWJ1(const R *t, V sr) | |
254 { | |
255 const V *twp = (const V *)t; | |
256 V si = VBYI(sr); | |
257 V tx = twp[0]; | |
258 V tr = vec_mergeh(tx, tx); | |
259 V ti = vec_mergel(tx, tx); | |
260 return VFNMS(ti, si, VMUL(tr, sr)); | |
261 } | |
262 | |
263 /* twiddle storage #2: twice the space, faster (when in cache) */ | |
264 #define VTW2(v,x) \ | |
265 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \ | |
266 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x} | |
267 #define TWVL2 (2 * VL) | |
268 | |
269 static inline V BYTW2(const R *t, V sr) | |
270 { | |
271 const V *twp = (const V *)t; | |
272 V si = FLIP_RI(sr); | |
273 V tr = twp[0], ti = twp[1]; | |
274 return VFMA(ti, si, VMUL(tr, sr)); | |
275 } | |
276 | |
277 static inline V BYTWJ2(const R *t, V sr) | |
278 { | |
279 const V *twp = (const V *)t; | |
280 V si = FLIP_RI(sr); | |
281 V tr = twp[0], ti = twp[1]; | |
282 return VFNMS(ti, si, VMUL(tr, sr)); | |
283 } | |
284 | |
285 /* twiddle storage #3 */ | |
286 #define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x} | |
287 #define TWVL3 (VL) | |
288 | |
289 /* twiddle storage for split arrays */ | |
290 #define VTWS(v,x) \ | |
291 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \ | |
292 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x} | |
293 #define TWVLS (2 * VL) | |
294 | |
295 #define VLEAVE() /* nothing */ | |
296 | |
297 #include "simd-common.h" |