1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 *
5 * Generic256d added by Romain Dolbeau, and turned into simd-generic256.h
6 * with single & double precision by Erik Lindahl.
7 * Romain Dolbeau hereby places his modifications in the public domain.
8 * Erik Lindahl hereby places his modifications in the public domain.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 *
24 */
25
26 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD)
27 # error "Generic simd256 only works in single or double precision"
28 #endif
29
30 #define SIMD_SUFFIX _generic_simd256 /* for renaming */
31
32 #ifdef FFTW_SINGLE
33 # define DS(d,s) s /* single-precision option */
34 # define VDUPL(x) {x[0],x[0],x[2],x[2],x[4],x[4],x[6],x[6]}
35 # define VDUPH(x) {x[1],x[1],x[3],x[3],x[5],x[5],x[7],x[7]}
36 # define DVK(var, val) V var = {val,val,val,val,val,val,val,val}
37 #else
38 # define DS(d,s) d /* double-precision option */
39 # define VDUPL(x) {x[0],x[0],x[2],x[2]}
40 # define VDUPH(x) {x[1],x[1],x[3],x[3]}
41 # define DVK(var, val) V var = {val, val, val, val}
42 #endif
43
44 #define VL DS(2,4) /* SIMD vector length, in term of complex numbers */
45 #define SIMD_VSTRIDE_OKA(x) DS(1,((x) == 2))
46 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK
47
48 typedef DS(double,float) V __attribute__ ((vector_size(32)));
49
50 #define VADD(a,b) ((a)+(b))
51 #define VSUB(a,b) ((a)-(b))
52 #define VMUL(a,b) ((a)*(b))
53
54 #define LDK(x) x
55
LDA(const R * x,INT ivs,const R * aligned_like)56 static inline V LDA(const R *x, INT ivs, const R *aligned_like)
57 {
58 V var;
59 (void)aligned_like; /* UNUSED */
60 return *(const V *)x;
61 }
62
STA(R * x,V v,INT ovs,const R * aligned_like)63 static inline void STA(R *x, V v, INT ovs, const R *aligned_like)
64 {
65 (void)aligned_like; /* UNUSED */
66 (void)ovs; /* UNUSED */
67 *(V *)x = v;
68 }
69
LD(const R * x,INT ivs,const R * aligned_like)70 static inline V LD(const R *x, INT ivs, const R *aligned_like)
71 {
72 V var;
73 (void)aligned_like; /* UNUSED */
74 var[0] = x[0];
75 var[1] = x[1];
76 var[2] = x[ivs];
77 var[3] = x[ivs+1];
78 #ifdef FFTW_SINGLE
79 var[4] = x[2*ivs];
80 var[5] = x[2*ivs+1];
81 var[6] = x[3*ivs];
82 var[7] = x[3*ivs+1];
83 #endif
84 return var;
85 }
86
87
88 /* ST has to be separate due to the storage hack requiring reverse order */
89
ST(R * x,V v,INT ovs,const R * aligned_like)90 static inline void ST(R *x, V v, INT ovs, const R *aligned_like)
91 {
92 (void)aligned_like; /* UNUSED */
93 #ifdef FFTW_SINGLE
94 *(x + 3*ovs ) = v[6];
95 *(x + 3*ovs + 1) = v[7];
96 *(x + 2*ovs ) = v[4];
97 *(x + 2*ovs + 1) = v[5];
98 *(x + ovs ) = v[2];
99 *(x + ovs + 1) = v[3];
100 *(x ) = v[0];
101 *(x + 1) = v[1];
102 #else
103 *(x + ovs ) = v[2];
104 *(x + ovs + 1) = v[3];
105 *(x ) = v[0];
106 *(x + 1) = v[1];
107 #endif
108 }
109
110 #ifdef FFTW_SINGLE
111 #define STM2(x, v, ovs, a) /* no-op */
STN2(R * x,V v0,V v1,INT ovs)112 static inline void STN2(R *x, V v0, V v1, INT ovs)
113 {
114 x[ 0] = v0[0];
115 x[ 1] = v0[1];
116 x[ 2] = v1[0];
117 x[ 3] = v1[1];
118 x[ ovs ] = v0[2];
119 x[ ovs + 1] = v0[3];
120 x[ ovs + 2] = v1[2];
121 x[ ovs + 3] = v1[3];
122 x[2*ovs ] = v0[4];
123 x[2*ovs + 1] = v0[5];
124 x[2*ovs + 2] = v1[4];
125 x[2*ovs + 3] = v1[5];
126 x[3*ovs ] = v0[6];
127 x[3*ovs + 1] = v0[7];
128 x[3*ovs + 2] = v1[6];
129 x[3*ovs + 3] = v1[7];
130 }
131
132 # define STM4(x, v, ovs, aligned_like) /* no-op */
STN4(R * x,V v0,V v1,V v2,V v3,INT ovs)133 static inline void STN4(R *x, V v0, V v1, V v2, V v3, INT ovs)
134 {
135 *(x ) = v0[0];
136 *(x + 1) = v1[0];
137 *(x + 2) = v2[0];
138 *(x + 3) = v3[0];
139 *(x + ovs ) = v0[1];
140 *(x + ovs + 1) = v1[1];
141 *(x + ovs + 2) = v2[1];
142 *(x + ovs + 3) = v3[1];
143 *(x + 2 * ovs ) = v0[2];
144 *(x + 2 * ovs + 1) = v1[2];
145 *(x + 2 * ovs + 2) = v2[2];
146 *(x + 2 * ovs + 3) = v3[2];
147 *(x + 3 * ovs ) = v0[3];
148 *(x + 3 * ovs + 1) = v1[3];
149 *(x + 3 * ovs + 2) = v2[3];
150 *(x + 3 * ovs + 3) = v3[3];
151 *(x + 4 * ovs ) = v0[4];
152 *(x + 4 * ovs + 1) = v1[4];
153 *(x + 4 * ovs + 2) = v2[4];
154 *(x + 4 * ovs + 3) = v3[4];
155 *(x + 5 * ovs ) = v0[5];
156 *(x + 5 * ovs + 1) = v1[5];
157 *(x + 5 * ovs + 2) = v2[5];
158 *(x + 5 * ovs + 3) = v3[5];
159 *(x + 6 * ovs ) = v0[6];
160 *(x + 6 * ovs + 1) = v1[6];
161 *(x + 6 * ovs + 2) = v2[6];
162 *(x + 6 * ovs + 3) = v3[6];
163 *(x + 7 * ovs ) = v0[7];
164 *(x + 7 * ovs + 1) = v1[7];
165 *(x + 7 * ovs + 2) = v2[7];
166 *(x + 7 * ovs + 3) = v3[7];
167 }
168
169 #else
170 /* FFTW_DOUBLE */
171
172 #define STM2 ST
173 #define STN2(x, v0, v1, ovs) /* nop */
174 #define STM4(x, v, ovs, aligned_like) /* no-op */
175
STN4(R * x,V v0,V v1,V v2,V v3,INT ovs)176 static inline void STN4(R *x, V v0, V v1, V v2, V v3, INT ovs) {
177 *(x ) = v0[0];
178 *(x + 1) = v1[0];
179 *(x + 2) = v2[0];
180 *(x + 3) = v3[0];
181 *(x + ovs ) = v0[1];
182 *(x + ovs + 1) = v1[1];
183 *(x + ovs + 2) = v2[1];
184 *(x + ovs + 3) = v3[1];
185 *(x + 2 * ovs ) = v0[2];
186 *(x + 2 * ovs + 1) = v1[2];
187 *(x + 2 * ovs + 2) = v2[2];
188 *(x + 2 * ovs + 3) = v3[2];
189 *(x + 3 * ovs ) = v0[3];
190 *(x + 3 * ovs + 1) = v1[3];
191 *(x + 3 * ovs + 2) = v2[3];
192 *(x + 3 * ovs + 3) = v3[3];
193 }
194 #endif
195
FLIP_RI(V x)196 static inline V FLIP_RI(V x)
197 {
198 #ifdef FFTW_SINGLE
199 return (V){x[1],x[0],x[3],x[2],x[5],x[4],x[7],x[6]};
200 #else
201 return (V){x[1],x[0],x[3],x[2]};
202 #endif
203 }
204
VCONJ(V x)205 static inline V VCONJ(V x)
206 {
207 #ifdef FFTW_SINGLE
208 return (x * (V){1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0});
209 #else
210 return (x * (V){1.0,-1.0,1.0,-1.0});
211 #endif
212 }
213
VBYI(V x)214 static inline V VBYI(V x)
215 {
216 return FLIP_RI(VCONJ(x));
217 }
218
219 /* FMA support */
220 #define VFMA(a, b, c) VADD(c, VMUL(a, b))
221 #define VFNMS(a, b, c) VSUB(c, VMUL(a, b))
222 #define VFMS(a, b, c) VSUB(VMUL(a, b), c)
223 #define VFMAI(b, c) VADD(c, VBYI(b))
224 #define VFNMSI(b, c) VSUB(c, VBYI(b))
225 #define VFMACONJ(b,c) VADD(VCONJ(b),c)
226 #define VFMSCONJ(b,c) VSUB(VCONJ(b),c)
227 #define VFNMSCONJ(b,c) VSUB(c, VCONJ(b))
228
VZMUL(V tx,V sr)229 static inline V VZMUL(V tx, V sr)
230 {
231 V tr = VDUPL(tx);
232 V ti = VDUPH(tx);
233 tr = VMUL(sr, tr);
234 sr = VBYI(sr);
235 return VFMA(ti, sr, tr);
236 }
237
VZMULJ(V tx,V sr)238 static inline V VZMULJ(V tx, V sr)
239 {
240 V tr = VDUPL(tx);
241 V ti = VDUPH(tx);
242 tr = VMUL(sr, tr);
243 sr = VBYI(sr);
244 return VFNMS(ti, sr, tr);
245 }
246
VZMULI(V tx,V sr)247 static inline V VZMULI(V tx, V sr)
248 {
249 V tr = VDUPL(tx);
250 V ti = VDUPH(tx);
251 ti = VMUL(ti, sr);
252 sr = VBYI(sr);
253 return VFMS(tr, sr, ti);
254 }
255
VZMULIJ(V tx,V sr)256 static inline V VZMULIJ(V tx, V sr)
257 {
258 V tr = VDUPL(tx);
259 V ti = VDUPH(tx);
260 ti = VMUL(ti, sr);
261 sr = VBYI(sr);
262 return VFMA(tr, sr, ti);
263 }
264
265 /* twiddle storage #1: compact, slower */
266 #ifdef FFTW_SINGLE
267 # define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}, {TW_CEXP, v+2, x}, {TW_CEXP, v+3, x}
268 #else
269 # define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}
270 #endif
271 #define TWVL1 (VL)
272
BYTW1(const R * t,V sr)273 static inline V BYTW1(const R *t, V sr)
274 {
275 return VZMUL(LDA(t, 2, t), sr);
276 }
277
BYTWJ1(const R * t,V sr)278 static inline V BYTWJ1(const R *t, V sr)
279 {
280 return VZMULJ(LDA(t, 2, t), sr);
281 }
282
283 /* twiddle storage #2: twice the space, faster (when in cache) */
284 #ifdef FFTW_SINGLE
285 # define VTW2(v,x) \
286 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
287 {TW_COS, v+2, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, {TW_COS, v+3, x}, \
288 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}, \
289 {TW_SIN, v+2, -x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, -x}, {TW_SIN, v+3, x}
290 #else
291 # define VTW2(v,x) \
292 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
293 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}
294 #endif
295 #define TWVL2 (2 * VL)
296
BYTW2(const R * t,V sr)297 static inline V BYTW2(const R *t, V sr)
298 {
299 const V *twp = (const V *)t;
300 V si = FLIP_RI(sr);
301 V tr = twp[0], ti = twp[1];
302 return VFMA(tr, sr, VMUL(ti, si));
303 }
304
BYTWJ2(const R * t,V sr)305 static inline V BYTWJ2(const R *t, V sr)
306 {
307 const V *twp = (const V *)t;
308 V si = FLIP_RI(sr);
309 V tr = twp[0], ti = twp[1];
310 return VFNMS(ti, si, VMUL(tr, sr));
311 }
312
313 /* twiddle storage #3 */
314 #define VTW3 VTW1
315 #define TWVL3 TWVL1
316
317 /* twiddle storage for split arrays */
318 #ifdef FFTW_SINGLE
319 # define VTWS(v,x) \
320 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
321 {TW_COS, v+4, x}, {TW_COS, v+5, x}, {TW_COS, v+6, x}, {TW_COS, v+7, x}, \
322 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}, \
323 {TW_SIN, v+4, x}, {TW_SIN, v+5, x}, {TW_SIN, v+6, x}, {TW_SIN, v+7, x}
324 #else
325 # define VTWS(v,x) \
326 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
327 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}
328 #endif
329 #define TWVLS (2 * VL)
330
331 #define VLEAVE() /* nothing */
332
333 #include "simd-common.h"
334