annotate src/fftw-3.3.8/simd-support/simd-avx-128-fma.h @ 168:ceec0dd9ec9c

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