Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/simd-support/simd-avx512.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-11 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology | |
4 * | |
5 * AVX-512 support implemented by Romain Dolbeau. | |
6 * Romain Dolbeau hereby places his modifications in the public domain. | |
7 * | |
8 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 * of this software and associated documentation files (the "Software"), to deal | |
10 * in the Software without restriction, including without limitation the rights | |
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 * copies of the Software, and to permit persons to whom the Software is | |
13 * furnished to do so, subject to the following conditions: | |
14 * | |
15 * The above copyright notice and this permission notice shall be included in | |
16 * all copies or substantial portions of the Software. | |
17 * | |
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
24 * THE SOFTWARE. | |
25 * | |
26 */ | |
27 | |
28 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD) | |
29 #error "AVX-512 vector instructions only works in single or double precision" | |
30 #endif | |
31 | |
32 #ifdef FFTW_SINGLE | |
33 # define DS(d,s) s /* single-precision option */ | |
34 # define SUFF(name) name ## _ps | |
35 # define SCAL(x) x ## f | |
36 #else /* !FFTW_SINGLE */ | |
37 # define DS(d,s) d /* double-precision option */ | |
38 # define SUFF(name) name ## _pd | |
39 # define SCAL(x) x | |
40 #endif /* FFTW_SINGLE */ | |
41 | |
42 #define SIMD_SUFFIX _avx512 /* for renaming */ | |
43 #define VL DS(4, 8) /* SIMD complex vector length */ | |
44 #define SIMD_VSTRIDE_OKA(x) ((x) == 2) | |
45 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK | |
46 | |
47 #if defined(__GNUC__) && !defined(__AVX512F__) /* sanity check */ | |
48 #error "compiling simd-avx512.h without avx-512f support" | |
49 #endif | |
50 | |
51 #if !defined(HAVE_AVX2) | |
52 #warning "You should probably enable AVX2 with --enable-avx2 for AVX-512" | |
53 #endif | |
54 | |
55 #include <immintrin.h> | |
56 | |
57 typedef DS(__m512d, __m512) V; | |
58 | |
59 #define VLIT(re, im) DS(SUFF(_mm512_setr)(im, re, im, re, im, re, im, re),SUFF(_mm512_setr)(im, re, im, re, im, re, im, re, im, re, im, re, im, re, im, re)) | |
60 #define VLIT1(val) SUFF(_mm512_set1)(val) | |
61 #define LDK(x) x | |
62 #define DVK(var, val) V var = VLIT1(val) | |
63 #define VZERO SUFF(_mm512_setzero)() | |
64 | |
65 #define VDUPL(x) DS(_mm512_movedup_pd(x),_mm512_moveldup_ps(x)) | |
66 #define VDUPH(x) DS(_mm512_unpackhi_pd(x, x),_mm512_movehdup_ps(x)) | |
67 #define FLIP_RI(x) SUFF(_mm512_shuffle)(x, x, DS(0x55,0xB1)) | |
68 #define VCONJ(x) SUFF(_mm512_fmsubadd)(VZERO, VZERO, x) | |
69 static inline V VBYI(V x) | |
70 { | |
71 return FLIP_RI(VCONJ(x)); | |
72 } | |
73 | |
74 #define VADD(a,b) SUFF(_mm512_add)(a,b) | |
75 #define VSUB(a,b) SUFF(_mm512_sub)(a,b) | |
76 #define VMUL(a,b) SUFF(_mm512_mul)(a,b) | |
77 #define VFMA(a, b, c) SUFF(_mm512_fmadd)(a, b, c) | |
78 #define VFMS(a, b, c) SUFF(_mm512_fmsub)(a, b, c) | |
79 #define VFNMS(a, b, c) SUFF(_mm512_fnmadd)(a, b, c) | |
80 #define VFMAI(b, c) SUFF(_mm512_fmaddsub)(VLIT1(1.), c, FLIP_RI(b)) | |
81 #define VFNMSI(b, c) SUFF(_mm512_fmsubadd)(VLIT1(1.), c, FLIP_RI(b)) | |
82 #define VFMACONJ(b,c) SUFF(_mm512_fmsubadd)(VLIT1(1.), c, b) | |
83 #define VFMSCONJ(b,c) SUFF(_mm512_fmsubadd)(VLIT1(-1.), c, b) | |
84 #define VFNMSCONJ(b,c) SUFF(_mm512_fmaddsub)(VLIT1(1.), c, b) | |
85 | |
86 static inline V LDA(const R *x, INT ivs, const R *aligned_like) { | |
87 (void)aligned_like; /* UNUSED */ | |
88 (void)ivs; /* UNUSED */ | |
89 return SUFF(_mm512_loadu)(x); | |
90 } | |
91 static inline void STA(R *x, V v, INT ovs, const R *aligned_like) { | |
92 (void)aligned_like; /* UNUSED */ | |
93 (void)ovs; /* UNUSED */ | |
94 SUFF(_mm512_storeu)(x, v); | |
95 } | |
96 | |
97 #if FFTW_SINGLE | |
98 | |
99 static inline V LDu(const R *x, INT ivs, const R *aligned_like) | |
100 { | |
101 (void)aligned_like; /* UNUSED */ | |
102 __m512i index = _mm512_set_epi32(7 * ivs + 1, 7 * ivs, | |
103 6 * ivs + 1, 6 * ivs, | |
104 5 * ivs + 1, 5 * ivs, | |
105 4 * ivs + 1, 4 * ivs, | |
106 3 * ivs + 1, 3 * ivs, | |
107 2 * ivs + 1, 2 * ivs, | |
108 1 * ivs + 1, 1 * ivs, | |
109 0 * ivs + 1, 0 * ivs); | |
110 | |
111 return _mm512_i32gather_ps(index, x, 4); | |
112 } | |
113 | |
114 static inline void STu(R *x, V v, INT ovs, const R *aligned_like) | |
115 { | |
116 (void)aligned_like; /* UNUSED */ | |
117 __m512i index = _mm512_set_epi32(7 * ovs + 1, 7 * ovs, | |
118 6 * ovs + 1, 6 * ovs, | |
119 5 * ovs + 1, 5 * ovs, | |
120 4 * ovs + 1, 4 * ovs, | |
121 3 * ovs + 1, 3 * ovs, | |
122 2 * ovs + 1, 2 * ovs, | |
123 1 * ovs + 1, 1 * ovs, | |
124 0 * ovs + 1, 0 * ovs); | |
125 | |
126 _mm512_i32scatter_ps(x, index, v, 4); | |
127 } | |
128 | |
129 #else /* !FFTW_SINGLE */ | |
130 | |
131 static inline V LDu(const R *x, INT ivs, const R *aligned_like) | |
132 { | |
133 (void)aligned_like; /* UNUSED */ | |
134 __m256i index = _mm256_set_epi32(3 * ivs + 1, 3 * ivs, | |
135 2 * ivs + 1, 2 * ivs, | |
136 1 * ivs + 1, 1 * ivs, | |
137 0 * ivs + 1, 0 * ivs); | |
138 | |
139 return _mm512_i32gather_pd(index, x, 8); | |
140 } | |
141 | |
142 static inline void STu(R *x, V v, INT ovs, const R *aligned_like) | |
143 { | |
144 (void)aligned_like; /* UNUSED */ | |
145 __m256i index = _mm256_set_epi32(3 * ovs + 1, 3 * ovs, | |
146 2 * ovs + 1, 2 * ovs, | |
147 1 * ovs + 1, 1 * ovs, | |
148 0 * ovs + 1, 0 * ovs); | |
149 | |
150 _mm512_i32scatter_pd(x, index, v, 8); | |
151 } | |
152 | |
153 #endif /* FFTW_SINGLE */ | |
154 | |
155 #define LD LDu | |
156 #define ST STu | |
157 | |
158 #ifdef FFTW_SINGLE | |
159 #define STM2(x, v, ovs, a) ST(x, v, ovs, a) | |
160 #define STN2(x, v0, v1, ovs) /* nop */ | |
161 | |
162 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like) | |
163 { | |
164 (void)aligned_like; /* UNUSED */ | |
165 __m512i index = _mm512_set_epi32(15 * ovs, 14 * ovs, | |
166 13 * ovs, 12 * ovs, | |
167 11 * ovs, 10 * ovs, | |
168 9 * ovs, 8 * ovs, | |
169 7 * ovs, 6 * ovs, | |
170 5 * ovs, 4 * ovs, | |
171 3 * ovs, 2 * ovs, | |
172 1 * ovs, 0 * ovs); | |
173 | |
174 _mm512_i32scatter_ps(x, index, v, 4); | |
175 } | |
176 #define STN4(x, v0, v1, v2, v3, ovs) /* no-op */ | |
177 #else /* !FFTW_SINGLE */ | |
178 #define STM2(x, v, ovs, a) ST(x, v, ovs, a) | |
179 #define STN2(x, v0, v1, ovs) /* nop */ | |
180 | |
181 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like) | |
182 { | |
183 (void)aligned_like; /* UNUSED */ | |
184 __m256i index = _mm256_set_epi32(7 * ovs, 6 * ovs, | |
185 5 * ovs, 4 * ovs, | |
186 3 * ovs, 2 * ovs, | |
187 1 * ovs, 0 * ovs); | |
188 | |
189 _mm512_i32scatter_pd(x, index, v, 8); | |
190 } | |
191 #define STN4(x, v0, v1, v2, v3, ovs) /* no-op */ | |
192 #endif /* FFTW_SINGLE */ | |
193 | |
194 static inline V VZMUL(V tx, V sr) | |
195 { | |
196 /* V tr = VDUPL(tx); */ | |
197 /* V ti = VDUPH(tx); */ | |
198 /* tr = VMUL(sr, tr); */ | |
199 /* sr = VBYI(sr); */ | |
200 /* return VFMA(ti, sr, tr); */ | |
201 return SUFF(_mm512_fmaddsub)(sr, VDUPL(tx), VMUL(FLIP_RI(sr), VDUPH(tx))); | |
202 } | |
203 | |
204 static inline V VZMULJ(V tx, V sr) | |
205 { | |
206 /* V tr = VDUPL(tx); */ | |
207 /* V ti = VDUPH(tx); */ | |
208 /* tr = VMUL(sr, tr); */ | |
209 /* sr = VBYI(sr); */ | |
210 /* return VFNMS(ti, sr, tr); */ | |
211 return SUFF(_mm512_fmsubadd)(sr, VDUPL(tx), VMUL(FLIP_RI(sr), VDUPH(tx))); | |
212 } | |
213 | |
214 static inline V VZMULI(V tx, V sr) | |
215 { | |
216 V tr = VDUPL(tx); | |
217 V ti = VDUPH(tx); | |
218 ti = VMUL(ti, sr); | |
219 sr = VBYI(sr); | |
220 return VFMS(tr, sr, ti); | |
221 /* return SUFF(_mm512_addsub)(SUFF(_mm512_fnmadd)(sr, VDUPH(tx), VZERO), VMUL(FLIP_RI(sr), VDUPL(tx))); */ | |
222 } | |
223 | |
224 static inline V VZMULIJ(V tx, V sr) | |
225 { | |
226 /* V tr = VDUPL(tx); */ | |
227 /* V ti = VDUPH(tx); */ | |
228 /* ti = VMUL(ti, sr); */ | |
229 /* sr = VBYI(sr); */ | |
230 /* return VFMA(tr, sr, ti); */ | |
231 return SUFF(_mm512_fmaddsub)(sr, VDUPH(tx), VMUL(FLIP_RI(sr), VDUPL(tx))); | |
232 } | |
233 | |
234 /* twiddle storage #1: compact, slower */ | |
235 #ifdef FFTW_SINGLE | |
236 # define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}, {TW_CEXP, v+2, x}, {TW_CEXP, v+3, x}, {TW_CEXP, v+4, x}, {TW_CEXP, v+5, x}, {TW_CEXP, v+6, x}, {TW_CEXP, v+7, x} | |
237 #else /* !FFTW_SINGLE */ | |
238 # define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}, {TW_CEXP, v+2, x}, {TW_CEXP, v+3, x} | |
239 #endif /* FFTW_SINGLE */ | |
240 #define TWVL1 (VL) | |
241 | |
242 static inline V BYTW1(const R *t, V sr) | |
243 { | |
244 return VZMUL(LDA(t, 2, t), sr); | |
245 } | |
246 | |
247 static inline V BYTWJ1(const R *t, V sr) | |
248 { | |
249 return VZMULJ(LDA(t, 2, t), sr); | |
250 } | |
251 | |
252 /* twiddle storage #2: twice the space, faster (when in cache) */ | |
253 #ifdef FFTW_SINGLE | |
254 # define VTW2(v,x) \ | |
255 {TW_COS, v , x}, {TW_COS, v , x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \ | |
256 {TW_COS, v+2, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, {TW_COS, v+3, x}, \ | |
257 {TW_COS, v+4, x}, {TW_COS, v+4, x}, {TW_COS, v+5, x}, {TW_COS, v+5, x}, \ | |
258 {TW_COS, v+6, x}, {TW_COS, v+6, x}, {TW_COS, v+7, x}, {TW_COS, v+7, x}, \ | |
259 {TW_SIN, v , -x}, {TW_SIN, v , x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}, \ | |
260 {TW_SIN, v+2, -x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, -x}, {TW_SIN, v+3, x}, \ | |
261 {TW_SIN, v+4, -x}, {TW_SIN, v+4, x}, {TW_SIN, v+5, -x}, {TW_SIN, v+5, x}, \ | |
262 {TW_SIN, v+6, -x}, {TW_SIN, v+6, x}, {TW_SIN, v+7, -x}, {TW_SIN, v+7, x} | |
263 #else /* !FFTW_SINGLE */ | |
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_COS, v+2, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, {TW_COS, v+3, x}, \ | |
267 {TW_SIN, v , -x}, {TW_SIN, v , x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}, \ | |
268 {TW_SIN, v+2, -x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, -x}, {TW_SIN, v+3, x} | |
269 #endif /* FFTW_SINGLE */ | |
270 #define TWVL2 (2 * VL) | |
271 | |
272 static inline V BYTW2(const R *t, V sr) | |
273 { | |
274 const V *twp = (const V *)t; | |
275 V si = FLIP_RI(sr); | |
276 V tr = twp[0], ti = twp[1]; | |
277 /* V tr = LD(t, 2, t), ti = LD(t + VL, 2, t + VL); */ | |
278 return VFMA(tr, sr, VMUL(ti, si)); | |
279 } | |
280 | |
281 static inline V BYTWJ2(const R *t, V sr) | |
282 { | |
283 const V *twp = (const V *)t; | |
284 V si = FLIP_RI(sr); | |
285 V tr = twp[0], ti = twp[1]; | |
286 /* V tr = LD(t, 2, t), ti = LD(t + VL, 2, t + VL); */ | |
287 return VFNMS(ti, si, VMUL(tr, sr)); | |
288 } | |
289 | |
290 /* twiddle storage #3 */ | |
291 #define VTW3(v,x) VTW1(v,x) | |
292 #define TWVL3 TWVL1 | |
293 | |
294 /* twiddle storage for split arrays */ | |
295 #ifdef FFTW_SINGLE | |
296 # define VTWS(v,x) \ | |
297 {TW_COS, v , x}, {TW_COS, v+1 , x}, {TW_COS, v+2 , x}, {TW_COS, v+3 , x}, \ | |
298 {TW_COS, v+4 , x}, {TW_COS, v+5 , x}, {TW_COS, v+6 , x}, {TW_COS, v+7 , x}, \ | |
299 {TW_COS, v+8 , x}, {TW_COS, v+9 , x}, {TW_COS, v+10, x}, {TW_COS, v+11, x}, \ | |
300 {TW_COS, v+12, x}, {TW_COS, v+13, x}, {TW_COS, v+14, x}, {TW_COS, v+15, x}, \ | |
301 {TW_SIN, v , x}, {TW_SIN, v+1 , x}, {TW_SIN, v+2 , x}, {TW_SIN, v+3 , x}, \ | |
302 {TW_SIN, v+4 , x}, {TW_SIN, v+5 , x}, {TW_SIN, v+6 , x}, {TW_SIN, v+7 , x}, \ | |
303 {TW_SIN, v+8 , x}, {TW_SIN, v+9 , x}, {TW_SIN, v+10, x}, {TW_SIN, v+11, x}, \ | |
304 {TW_SIN, v+12, x}, {TW_SIN, v+13, x}, {TW_SIN, v+14, x}, {TW_SIN, v+15, x} | |
305 #else /* !FFTW_SINGLE */ | |
306 # define VTWS(v,x) \ | |
307 {TW_COS, v , x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \ | |
308 {TW_COS, v+4, x}, {TW_COS, v+5, x}, {TW_COS, v+6, x}, {TW_COS, v+7, x}, \ | |
309 {TW_SIN, v , x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}, \ | |
310 {TW_SIN, v+4, x}, {TW_SIN, v+5, x}, {TW_SIN, v+6, x}, {TW_SIN, v+7, x} | |
311 #endif /* FFTW_SINGLE */ | |
312 #define TWVLS (2 * VL) | |
313 | |
314 #define VLEAVE _mm256_zeroupper | |
315 | |
316 #include "simd-common.h" |