Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/simd-support/simd-avx-128-fma.h @ 167:bd3cc4d1df30
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
166:cbd6d7e562c7 | 167:bd3cc4d1df30 |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology | |
4 * | |
5 * 128-bit AVX support by Erik Lindahl, 2015. | |
6 * Erik Lindahl hereby places his modifications in the public domain. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 * | |
22 */ | |
23 | |
24 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD) | |
25 #error "AVX only works in single or double precision" | |
26 #endif | |
27 | |
28 #ifdef FFTW_SINGLE | |
29 # define DS(d,s) s /* single-precision option */ | |
30 # define SUFF(name) name ## s | |
31 #else | |
32 # define DS(d,s) d /* double-precision option */ | |
33 # define SUFF(name) name ## d | |
34 #endif | |
35 | |
36 #define SIMD_SUFFIX _avx_128_fma /* for renaming */ | |
37 #define VL DS(1,2) /* SIMD vector length, in term of complex numbers */ | |
38 #define SIMD_VSTRIDE_OKA(x) DS(1,((x) == 2)) | |
39 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK | |
40 | |
41 #ifdef _MSC_VER | |
42 #ifndef inline | |
43 #define inline __inline | |
44 #endif | |
45 #endif | |
46 | |
47 #include <immintrin.h> | |
48 #ifdef _MSC_VER | |
49 # include <intrin.h> | |
50 #elif defined (__GNUC__) | |
51 # include <x86intrin.h> | |
52 #endif | |
53 | |
54 #if !(defined(__AVX__) && defined(__FMA4__)) /* sanity check */ | |
55 #error "compiling simd-avx-128-fma.h without -mavx or -mfma4" | |
56 #endif | |
57 | |
58 typedef DS(__m128d,__m128) V; | |
59 #define VADD SUFF(_mm_add_p) | |
60 #define VSUB SUFF(_mm_sub_p) | |
61 #define VMUL SUFF(_mm_mul_p) | |
62 #define VXOR SUFF(_mm_xor_p) | |
63 #define SHUF SUFF(_mm_shuffle_p) | |
64 #define VPERM1 SUFF(_mm_permute_p) | |
65 #define UNPCKL SUFF(_mm_unpacklo_p) | |
66 #define UNPCKH SUFF(_mm_unpackhi_p) | |
67 | |
68 #define SHUFVALS(fp0,fp1,fp2,fp3) \ | |
69 (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | ((fp0))) | |
70 | |
71 #define VDUPL(x) DS(_mm_permute_pd(x,0), _mm_moveldup_ps(x)) | |
72 #define VDUPH(x) DS(_mm_permute_pd(x,3), _mm_movehdup_ps(x)) | |
73 #define LOADH(addr, val) _mm_loadh_pi(val, (const __m64 *)(addr)) | |
74 #define LOADL(addr, val) _mm_loadl_pi(val, (const __m64 *)(addr)) | |
75 #define STOREH(a, v) DS(_mm_storeh_pd(a, v), _mm_storeh_pi((__m64 *)(a), v)) | |
76 #define STOREL(a, v) DS(_mm_storel_pd(a, v), _mm_storel_pi((__m64 *)(a), v)) | |
77 | |
78 #define VLIT(x0, x1) DS(_mm_set_pd(x0, x1), _mm_set_ps(x0, x1, x0, x1)) | |
79 #define DVK(var, val) V var = VLIT(val, val) | |
80 #define LDK(x) x | |
81 | |
82 static inline V LDA(const R *x, INT ivs, const R *aligned_like) | |
83 { | |
84 (void)aligned_like; /* UNUSED */ | |
85 (void)ivs; /* UNUSED */ | |
86 return *(const V *)x; | |
87 } | |
88 | |
89 static inline void STA(R *x, V v, INT ovs, const R *aligned_like) | |
90 { | |
91 (void)aligned_like; /* UNUSED */ | |
92 (void)ovs; /* UNUSED */ | |
93 *(V *)x = v; | |
94 } | |
95 | |
96 #ifdef FFTW_SINGLE | |
97 | |
98 static inline V LD(const R *x, INT ivs, const R *aligned_like) | |
99 { | |
100 V var; | |
101 #if defined(__ICC) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 8) | |
102 var = LOADL(x, SUFF(_mm_undefined_p)()); | |
103 var = LOADH(x + ivs, var); | |
104 #else | |
105 var = LOADL(x, var); | |
106 var = LOADH(x + ivs, var); | |
107 #endif | |
108 return var; | |
109 } | |
110 | |
111 # ifdef _MSC_VER | |
112 # pragma warning(default : 4700) | |
113 # pragma runtime_checks("u", restore) | |
114 # endif | |
115 | |
116 static inline void ST(R *x, V v, INT ovs, const R *aligned_like) | |
117 { | |
118 (void)aligned_like; /* UNUSED */ | |
119 /* WARNING: the extra_iter hack depends upon STOREL occurring | |
120 after STOREH */ | |
121 STOREH(x + ovs, v); | |
122 STOREL(x, v); | |
123 } | |
124 | |
125 #else /* ! FFTW_SINGLE */ | |
126 # define LD LDA | |
127 # define ST STA | |
128 #endif | |
129 | |
130 #define STM2 DS(STA,ST) | |
131 #define STN2(x, v0, v1, ovs) /* nop */ | |
132 | |
133 #ifdef FFTW_SINGLE | |
134 # define STM4(x, v, ovs, aligned_like) /* no-op */ | |
135 /* STN4 is a macro, not a function, thanks to Visual C++ developers | |
136 deciding "it would be infrequent that people would want to pass more | |
137 than 3 [__m128 parameters] by value." 3 parameters ought to be enough | |
138 for anybody. */ | |
139 # define STN4(x, v0, v1, v2, v3, ovs) \ | |
140 { \ | |
141 V xxx0, xxx1, xxx2, xxx3; \ | |
142 xxx0 = UNPCKL(v0, v2); \ | |
143 xxx1 = UNPCKH(v0, v2); \ | |
144 xxx2 = UNPCKL(v1, v3); \ | |
145 xxx3 = UNPCKH(v1, v3); \ | |
146 STA(x, UNPCKL(xxx0, xxx2), 0, 0); \ | |
147 STA(x + ovs, UNPCKH(xxx0, xxx2), 0, 0); \ | |
148 STA(x + 2 * ovs, UNPCKL(xxx1, xxx3), 0, 0); \ | |
149 STA(x + 3 * ovs, UNPCKH(xxx1, xxx3), 0, 0); \ | |
150 } | |
151 #else /* !FFTW_SINGLE */ | |
152 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like) | |
153 { | |
154 (void)aligned_like; /* UNUSED */ | |
155 STOREL(x, v); | |
156 STOREH(x + ovs, v); | |
157 } | |
158 # define STN4(x, v0, v1, v2, v3, ovs) /* nothing */ | |
159 #endif | |
160 | |
161 static inline V FLIP_RI(V x) | |
162 { | |
163 return VPERM1(x, DS(1, SHUFVALS(1, 0, 3, 2))); | |
164 } | |
165 | |
166 | |
167 static inline V VCONJ(V x) | |
168 { | |
169 /* Produce a SIMD vector[VL] of (0 + -0i). | |
170 | |
171 We really want to write this: | |
172 | |
173 V pmpm = VLIT(-0.0, 0.0); | |
174 | |
175 but historically some compilers have ignored the distiction | |
176 between +0 and -0. It looks like 'gcc-8 -fast-math' treats -0 | |
177 as 0 too. | |
178 */ | |
179 union uvec { | |
180 unsigned u[4]; | |
181 V v; | |
182 }; | |
183 static const union uvec pmpm = { | |
184 #ifdef FFTW_SINGLE | |
185 { 0x00000000, 0x80000000, 0x00000000, 0x80000000 } | |
186 #else | |
187 { 0x00000000, 0x00000000, 0x00000000, 0x80000000 } | |
188 #endif | |
189 }; | |
190 return VXOR(pmpm.v, x); | |
191 } | |
192 | |
193 static inline V VBYI(V x) | |
194 { | |
195 x = VCONJ(x); | |
196 x = FLIP_RI(x); | |
197 return x; | |
198 } | |
199 | |
200 /* FMA support */ | |
201 #define VFMA(a, b, c) SUFF(_mm_macc_p)(a,b,c) | |
202 #define VFNMS(a, b, c) SUFF(_mm_nmacc_p)(a,b,c) | |
203 #define VFMS(a, b, c) SUFF(_mm_msub_p)(a,b,c) | |
204 #define VFMAI(b, c) SUFF(_mm_addsub_p)(c,FLIP_RI(b)) | |
205 #define VFNMSI(b, c) VSUB(c, VBYI(b)) | |
206 #define VFMACONJ(b,c) VADD(VCONJ(b),c) | |
207 #define VFMSCONJ(b,c) VSUB(VCONJ(b),c) | |
208 #define VFNMSCONJ(b,c) SUFF(_mm_addsub_p)(c,b) | |
209 | |
210 static inline V VZMUL(V tx, V sr) | |
211 { | |
212 V tr = VDUPL(tx); | |
213 V ti = VDUPH(tx); | |
214 tr = VMUL(tr, sr); | |
215 ti = VMUL(ti, FLIP_RI(sr)); | |
216 return SUFF(_mm_addsub_p)(tr,ti); | |
217 } | |
218 | |
219 static inline V VZMULJ(V tx, V sr) | |
220 { | |
221 V tr = VDUPL(tx); | |
222 V ti = VDUPH(tx); | |
223 tr = VMUL(tr, sr); | |
224 sr = VBYI(sr); | |
225 return VFNMS(ti, sr, tr); | |
226 } | |
227 | |
228 static inline V VZMULI(V tx, V sr) | |
229 { | |
230 V tr = VDUPL(tx); | |
231 V ti = VDUPH(tx); | |
232 ti = VMUL(ti, sr); | |
233 sr = VBYI(sr); | |
234 return VFMS(tr, sr, ti); | |
235 } | |
236 | |
237 static inline V VZMULIJ(V tx, V sr) | |
238 { | |
239 V tr = VDUPL(tx); | |
240 V ti = VDUPH(tx); | |
241 ti = VMUL(ti, sr); | |
242 tr = VMUL(tr, FLIP_RI(sr)); | |
243 return SUFF(_mm_addsub_p)(ti,tr); | |
244 } | |
245 | |
246 /* twiddle storage #1: compact, slower */ | |
247 #ifdef FFTW_SINGLE | |
248 # define VTW1(v,x) \ | |
249 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
250 static inline V BYTW1(const R *t, V sr) | |
251 { | |
252 const V *twp = (const V *)t; | |
253 V tx = twp[0]; | |
254 V tr = UNPCKL(tx, tx); | |
255 V ti = UNPCKH(tx, tx); | |
256 tr = VMUL(tr, sr); | |
257 ti = VMUL(ti, FLIP_RI(sr)); | |
258 return SUFF(_mm_addsub_p)(tr,ti); | |
259 } | |
260 static inline V BYTWJ1(const R *t, V sr) | |
261 { | |
262 const V *twp = (const V *)t; | |
263 V tx = twp[0]; | |
264 V tr = UNPCKL(tx, tx); | |
265 V ti = UNPCKH(tx, tx); | |
266 tr = VMUL(tr, sr); | |
267 sr = VBYI(sr); | |
268 return VFNMS(ti, sr, tr); | |
269 } | |
270 #else /* !FFTW_SINGLE */ | |
271 # define VTW1(v,x) {TW_CEXP, v, x} | |
272 static inline V BYTW1(const R *t, V sr) | |
273 { | |
274 V tx = LD(t, 1, t); | |
275 return VZMUL(tx, sr); | |
276 } | |
277 static inline V BYTWJ1(const R *t, V sr) | |
278 { | |
279 V tx = LD(t, 1, t); | |
280 return VZMULJ(tx, sr); | |
281 } | |
282 #endif | |
283 #define TWVL1 (VL) | |
284 | |
285 /* twiddle storage #2: twice the space, faster (when in cache) */ | |
286 #ifdef FFTW_SINGLE | |
287 # define VTW2(v,x) \ | |
288 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \ | |
289 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x} | |
290 #else /* !FFTW_SINGLE */ | |
291 # define VTW2(v,x) \ | |
292 {TW_COS, v, x}, {TW_COS, v, x}, {TW_SIN, v, -x}, {TW_SIN, v, x} | |
293 #endif | |
294 #define TWVL2 (2 * VL) | |
295 static inline V BYTW2(const R *t, V sr) | |
296 { | |
297 const V *twp = (const V *)t; | |
298 V si = FLIP_RI(sr); | |
299 V tr = twp[0], ti = twp[1]; | |
300 return VFMA(tr, sr, VMUL(ti, si)); | |
301 } | |
302 static inline V BYTWJ2(const R *t, V sr) | |
303 { | |
304 const V *twp = (const V *)t; | |
305 V si = FLIP_RI(sr); | |
306 V tr = twp[0], ti = twp[1]; | |
307 return VFNMS(ti, si, VMUL(tr, sr)); | |
308 } | |
309 | |
310 /* twiddle storage #3 */ | |
311 #ifdef FFTW_SINGLE | |
312 # define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x} | |
313 # define TWVL3 (VL) | |
314 #else | |
315 # define VTW3(v,x) VTW1(v,x) | |
316 # define TWVL3 TWVL1 | |
317 #endif | |
318 | |
319 /* twiddle storage for split arrays */ | |
320 #ifdef FFTW_SINGLE | |
321 # define VTWS(v,x) \ | |
322 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \ | |
323 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x} | |
324 #else | |
325 # define VTWS(v,x) \ | |
326 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x} | |
327 #endif | |
328 #define TWVLS (2 * VL) | |
329 | |
330 #define VLEAVE() /* nothing */ | |
331 | |
332 #include "simd-common.h" |