annotate src/fftw-3.3.5/simd-support/simd-sse2.h @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD)
Chris@42 22 # error "SSE/SSE2 only works in single/double precision"
Chris@42 23 #endif
Chris@42 24
Chris@42 25 #ifdef FFTW_SINGLE
Chris@42 26 # define DS(d,s) s /* single-precision option */
Chris@42 27 # define SUFF(name) name ## s
Chris@42 28 #else
Chris@42 29 # define DS(d,s) d /* double-precision option */
Chris@42 30 # define SUFF(name) name ## d
Chris@42 31 #endif
Chris@42 32
Chris@42 33 #define SIMD_SUFFIX _sse2 /* for renaming */
Chris@42 34 #define VL DS(1,2) /* SIMD vector length, in term of complex numbers */
Chris@42 35 #define SIMD_VSTRIDE_OKA(x) DS(1,((x) == 2))
Chris@42 36 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK
Chris@42 37
Chris@42 38 #if defined(__GNUC__) && !defined(FFTW_SINGLE) && !defined(__SSE2__)
Chris@42 39 # error "compiling simd-sse2.h in double precision without -msse2"
Chris@42 40 #elif defined(__GNUC__) && defined(FFTW_SINGLE) && !defined(__SSE__)
Chris@42 41 # error "compiling simd-sse2.h in single precision without -msse"
Chris@42 42 #endif
Chris@42 43
Chris@42 44 #ifdef _MSC_VER
Chris@42 45 #ifndef inline
Chris@42 46 #define inline __inline
Chris@42 47 #endif
Chris@42 48 #endif
Chris@42 49
Chris@42 50 /* some versions of glibc's sys/cdefs.h define __inline to be empty,
Chris@42 51 which is wrong because emmintrin.h defines several inline
Chris@42 52 procedures */
Chris@42 53 #ifndef _MSC_VER
Chris@42 54 #undef __inline
Chris@42 55 #endif
Chris@42 56
Chris@42 57 #ifdef FFTW_SINGLE
Chris@42 58 # include <xmmintrin.h>
Chris@42 59 #else
Chris@42 60 # include <emmintrin.h>
Chris@42 61 #endif
Chris@42 62
Chris@42 63 typedef DS(__m128d,__m128) V;
Chris@42 64 #define VADD SUFF(_mm_add_p)
Chris@42 65 #define VSUB SUFF(_mm_sub_p)
Chris@42 66 #define VMUL SUFF(_mm_mul_p)
Chris@42 67 #define VXOR SUFF(_mm_xor_p)
Chris@42 68 #define SHUF SUFF(_mm_shuffle_p)
Chris@42 69 #define UNPCKL SUFF(_mm_unpacklo_p)
Chris@42 70 #define UNPCKH SUFF(_mm_unpackhi_p)
Chris@42 71
Chris@42 72 #define SHUFVALS(fp0,fp1,fp2,fp3) \
Chris@42 73 (((fp3) << 6) | ((fp2) << 4) | ((fp1) << 2) | ((fp0)))
Chris@42 74
Chris@42 75 #define VDUPL(x) DS(UNPCKL(x, x), SHUF(x, x, SHUFVALS(0, 0, 2, 2)))
Chris@42 76 #define VDUPH(x) DS(UNPCKH(x, x), SHUF(x, x, SHUFVALS(1, 1, 3, 3)))
Chris@42 77 #define STOREH(a, v) DS(_mm_storeh_pd(a, v), _mm_storeh_pi((__m64 *)(a), v))
Chris@42 78 #define STOREL(a, v) DS(_mm_storel_pd(a, v), _mm_storel_pi((__m64 *)(a), v))
Chris@42 79
Chris@42 80
Chris@42 81 #ifdef __GNUC__
Chris@42 82 /*
Chris@42 83 * gcc-3.3 generates slow code for mm_set_ps (write all elements to
Chris@42 84 * the stack and load __m128 from the stack).
Chris@42 85 *
Chris@42 86 * gcc-3.[34] generates slow code for mm_set_ps1 (load into low element
Chris@42 87 * and shuffle).
Chris@42 88 *
Chris@42 89 * This hack forces gcc to generate a constant __m128 at compile time.
Chris@42 90 */
Chris@42 91 union rvec {
Chris@42 92 R r[DS(2,4)];
Chris@42 93 V v;
Chris@42 94 };
Chris@42 95
Chris@42 96 # ifdef FFTW_SINGLE
Chris@42 97 # define DVK(var, val) V var = __extension__ ({ \
Chris@42 98 static const union rvec _var = { {val,val,val,val} }; _var.v; })
Chris@42 99 # else
Chris@42 100 # define DVK(var, val) V var = __extension__ ({ \
Chris@42 101 static const union rvec _var = { {val,val} }; _var.v; })
Chris@42 102 # endif
Chris@42 103 # define LDK(x) x
Chris@42 104 #else
Chris@42 105 # define DVK(var, val) const R var = K(val)
Chris@42 106 # define LDK(x) DS(_mm_set1_pd,_mm_set_ps1)(x)
Chris@42 107 #endif
Chris@42 108
Chris@42 109 union uvec {
Chris@42 110 unsigned u[4];
Chris@42 111 V v;
Chris@42 112 };
Chris@42 113
Chris@42 114 static inline V LDA(const R *x, INT ivs, const R *aligned_like)
Chris@42 115 {
Chris@42 116 (void)aligned_like; /* UNUSED */
Chris@42 117 (void)ivs; /* UNUSED */
Chris@42 118 return *(const V *)x;
Chris@42 119 }
Chris@42 120
Chris@42 121 static inline void STA(R *x, V v, INT ovs, const R *aligned_like)
Chris@42 122 {
Chris@42 123 (void)aligned_like; /* UNUSED */
Chris@42 124 (void)ovs; /* UNUSED */
Chris@42 125 *(V *)x = v;
Chris@42 126 }
Chris@42 127
Chris@42 128 #ifdef FFTW_SINGLE
Chris@42 129
Chris@42 130 # ifdef _MSC_VER
Chris@42 131 /* Temporarily disable the warning "uninitialized local variable
Chris@42 132 'name' used" and runtime checks for using a variable before it is
Chris@42 133 defined which is erroneously triggered by the LOADL0 / LOADH macros
Chris@42 134 as they only modify VAL partly each. */
Chris@42 135 # pragma warning(disable : 4700)
Chris@42 136 # pragma runtime_checks("u", off)
Chris@42 137 # endif
Chris@42 138
Chris@42 139 static inline V LD(const R *x, INT ivs, const R *aligned_like)
Chris@42 140 {
Chris@42 141 V var;
Chris@42 142 (void)aligned_like; /* UNUSED */
Chris@42 143 # ifdef __GNUC__
Chris@42 144 /* We use inline asm because gcc-3.x generates slow code for
Chris@42 145 _mm_loadh_pi(). gcc-3.x insists upon having an existing variable for
Chris@42 146 VAL, which is however never used. Thus, it generates code to move
Chris@42 147 values in and out the variable. Worse still, gcc-4.0 stores VAL on
Chris@42 148 the stack, causing valgrind to complain about uninitialized reads. */
Chris@42 149 __asm__("movlps %1, %0\n\tmovhps %2, %0"
Chris@42 150 : "=x"(var) : "m"(x[0]), "m"(x[ivs]));
Chris@42 151 # else
Chris@42 152 # define LOADH(addr, val) _mm_loadh_pi(val, (const __m64 *)(addr))
Chris@42 153 # define LOADL0(addr, val) _mm_loadl_pi(val, (const __m64 *)(addr))
Chris@42 154 var = LOADL0(x, var);
Chris@42 155 var = LOADH(x + ivs, var);
Chris@42 156 # endif
Chris@42 157 return var;
Chris@42 158 }
Chris@42 159
Chris@42 160 # ifdef _MSC_VER
Chris@42 161 # pragma warning(default : 4700)
Chris@42 162 # pragma runtime_checks("u", restore)
Chris@42 163 # endif
Chris@42 164
Chris@42 165 static inline void ST(R *x, V v, INT ovs, const R *aligned_like)
Chris@42 166 {
Chris@42 167 (void)aligned_like; /* UNUSED */
Chris@42 168 /* WARNING: the extra_iter hack depends upon STOREL occurring
Chris@42 169 after STOREH */
Chris@42 170 STOREH(x + ovs, v);
Chris@42 171 STOREL(x, v);
Chris@42 172 }
Chris@42 173
Chris@42 174 #else /* ! FFTW_SINGLE */
Chris@42 175 # define LD LDA
Chris@42 176 # define ST STA
Chris@42 177 #endif
Chris@42 178
Chris@42 179 #define STM2 DS(STA,ST)
Chris@42 180 #define STN2(x, v0, v1, ovs) /* nop */
Chris@42 181
Chris@42 182 #ifdef FFTW_SINGLE
Chris@42 183 # define STM4(x, v, ovs, aligned_like) /* no-op */
Chris@42 184 /* STN4 is a macro, not a function, thanks to Visual C++ developers
Chris@42 185 deciding "it would be infrequent that people would want to pass more
Chris@42 186 than 3 [__m128 parameters] by value." 3 parameters ought to be enough
Chris@42 187 for anybody. */
Chris@42 188 # define STN4(x, v0, v1, v2, v3, ovs) \
Chris@42 189 { \
Chris@42 190 V xxx0, xxx1, xxx2, xxx3; \
Chris@42 191 xxx0 = UNPCKL(v0, v2); \
Chris@42 192 xxx1 = UNPCKH(v0, v2); \
Chris@42 193 xxx2 = UNPCKL(v1, v3); \
Chris@42 194 xxx3 = UNPCKH(v1, v3); \
Chris@42 195 STA(x, UNPCKL(xxx0, xxx2), 0, 0); \
Chris@42 196 STA(x + ovs, UNPCKH(xxx0, xxx2), 0, 0); \
Chris@42 197 STA(x + 2 * ovs, UNPCKL(xxx1, xxx3), 0, 0); \
Chris@42 198 STA(x + 3 * ovs, UNPCKH(xxx1, xxx3), 0, 0); \
Chris@42 199 }
Chris@42 200 #else /* !FFTW_SINGLE */
Chris@42 201 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like)
Chris@42 202 {
Chris@42 203 (void)aligned_like; /* UNUSED */
Chris@42 204 STOREL(x, v);
Chris@42 205 STOREH(x + ovs, v);
Chris@42 206 }
Chris@42 207 # define STN4(x, v0, v1, v2, v3, ovs) /* nothing */
Chris@42 208 #endif
Chris@42 209
Chris@42 210 static inline V FLIP_RI(V x)
Chris@42 211 {
Chris@42 212 return SHUF(x, x, DS(1, SHUFVALS(1, 0, 3, 2)));
Chris@42 213 }
Chris@42 214
Chris@42 215 extern const union uvec X(sse2_pm);
Chris@42 216 static inline V VCONJ(V x)
Chris@42 217 {
Chris@42 218 return VXOR(X(sse2_pm).v, x);
Chris@42 219 }
Chris@42 220
Chris@42 221 static inline V VBYI(V x)
Chris@42 222 {
Chris@42 223 x = VCONJ(x);
Chris@42 224 x = FLIP_RI(x);
Chris@42 225 return x;
Chris@42 226 }
Chris@42 227
Chris@42 228 /* FMA support */
Chris@42 229 #define VFMA(a, b, c) VADD(c, VMUL(a, b))
Chris@42 230 #define VFNMS(a, b, c) VSUB(c, VMUL(a, b))
Chris@42 231 #define VFMS(a, b, c) VSUB(VMUL(a, b), c)
Chris@42 232 #define VFMAI(b, c) VADD(c, VBYI(b))
Chris@42 233 #define VFNMSI(b, c) VSUB(c, VBYI(b))
Chris@42 234 #define VFMACONJ(b,c) VADD(VCONJ(b),c)
Chris@42 235 #define VFMSCONJ(b,c) VSUB(VCONJ(b),c)
Chris@42 236 #define VFNMSCONJ(b,c) VSUB(c, VCONJ(b))
Chris@42 237
Chris@42 238 static inline V VZMUL(V tx, V sr)
Chris@42 239 {
Chris@42 240 V tr = VDUPL(tx);
Chris@42 241 V ti = VDUPH(tx);
Chris@42 242 tr = VMUL(sr, tr);
Chris@42 243 sr = VBYI(sr);
Chris@42 244 return VFMA(ti, sr, tr);
Chris@42 245 }
Chris@42 246
Chris@42 247 static inline V VZMULJ(V tx, V sr)
Chris@42 248 {
Chris@42 249 V tr = VDUPL(tx);
Chris@42 250 V ti = VDUPH(tx);
Chris@42 251 tr = VMUL(sr, tr);
Chris@42 252 sr = VBYI(sr);
Chris@42 253 return VFNMS(ti, sr, tr);
Chris@42 254 }
Chris@42 255
Chris@42 256 static inline V VZMULI(V tx, V sr)
Chris@42 257 {
Chris@42 258 V tr = VDUPL(tx);
Chris@42 259 V ti = VDUPH(tx);
Chris@42 260 ti = VMUL(ti, sr);
Chris@42 261 sr = VBYI(sr);
Chris@42 262 return VFMS(tr, sr, ti);
Chris@42 263 }
Chris@42 264
Chris@42 265 static inline V VZMULIJ(V tx, V sr)
Chris@42 266 {
Chris@42 267 V tr = VDUPL(tx);
Chris@42 268 V ti = VDUPH(tx);
Chris@42 269 ti = VMUL(ti, sr);
Chris@42 270 sr = VBYI(sr);
Chris@42 271 return VFMA(tr, sr, ti);
Chris@42 272 }
Chris@42 273
Chris@42 274 /* twiddle storage #1: compact, slower */
Chris@42 275 #ifdef FFTW_SINGLE
Chris@42 276 # define VTW1(v,x) \
Chris@42 277 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x}
Chris@42 278 static inline V BYTW1(const R *t, V sr)
Chris@42 279 {
Chris@42 280 const V *twp = (const V *)t;
Chris@42 281 V tx = twp[0];
Chris@42 282 V tr = UNPCKL(tx, tx);
Chris@42 283 V ti = UNPCKH(tx, tx);
Chris@42 284 tr = VMUL(tr, sr);
Chris@42 285 sr = VBYI(sr);
Chris@42 286 return VFMA(ti, sr, tr);
Chris@42 287 }
Chris@42 288 static inline V BYTWJ1(const R *t, V sr)
Chris@42 289 {
Chris@42 290 const V *twp = (const V *)t;
Chris@42 291 V tx = twp[0];
Chris@42 292 V tr = UNPCKL(tx, tx);
Chris@42 293 V ti = UNPCKH(tx, tx);
Chris@42 294 tr = VMUL(tr, sr);
Chris@42 295 sr = VBYI(sr);
Chris@42 296 return VFNMS(ti, sr, tr);
Chris@42 297 }
Chris@42 298 #else /* !FFTW_SINGLE */
Chris@42 299 # define VTW1(v,x) {TW_CEXP, v, x}
Chris@42 300 static inline V BYTW1(const R *t, V sr)
Chris@42 301 {
Chris@42 302 V tx = LD(t, 1, t);
Chris@42 303 return VZMUL(tx, sr);
Chris@42 304 }
Chris@42 305 static inline V BYTWJ1(const R *t, V sr)
Chris@42 306 {
Chris@42 307 V tx = LD(t, 1, t);
Chris@42 308 return VZMULJ(tx, sr);
Chris@42 309 }
Chris@42 310 #endif
Chris@42 311 #define TWVL1 (VL)
Chris@42 312
Chris@42 313 /* twiddle storage #2: twice the space, faster (when in cache) */
Chris@42 314 #ifdef FFTW_SINGLE
Chris@42 315 # define VTW2(v,x) \
Chris@42 316 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
Chris@42 317 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}
Chris@42 318 #else /* !FFTW_SINGLE */
Chris@42 319 # define VTW2(v,x) \
Chris@42 320 {TW_COS, v, x}, {TW_COS, v, x}, {TW_SIN, v, -x}, {TW_SIN, v, x}
Chris@42 321 #endif
Chris@42 322 #define TWVL2 (2 * VL)
Chris@42 323 static inline V BYTW2(const R *t, V sr)
Chris@42 324 {
Chris@42 325 const V *twp = (const V *)t;
Chris@42 326 V si = FLIP_RI(sr);
Chris@42 327 V tr = twp[0], ti = twp[1];
Chris@42 328 return VFMA(tr, sr, VMUL(ti, si));
Chris@42 329 }
Chris@42 330 static inline V BYTWJ2(const R *t, V sr)
Chris@42 331 {
Chris@42 332 const V *twp = (const V *)t;
Chris@42 333 V si = FLIP_RI(sr);
Chris@42 334 V tr = twp[0], ti = twp[1];
Chris@42 335 return VFNMS(ti, si, VMUL(tr, sr));
Chris@42 336 }
Chris@42 337
Chris@42 338 /* twiddle storage #3 */
Chris@42 339 #ifdef FFTW_SINGLE
Chris@42 340 # define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}
Chris@42 341 # define TWVL3 (VL)
Chris@42 342 #else
Chris@42 343 # define VTW3(v,x) VTW1(v,x)
Chris@42 344 # define TWVL3 TWVL1
Chris@42 345 #endif
Chris@42 346
Chris@42 347 /* twiddle storage for split arrays */
Chris@42 348 #ifdef FFTW_SINGLE
Chris@42 349 # define VTWS(v,x) \
Chris@42 350 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
Chris@42 351 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}
Chris@42 352 #else
Chris@42 353 # define VTWS(v,x) \
Chris@42 354 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x}
Chris@42 355 #endif
Chris@42 356 #define TWVLS (2 * VL)
Chris@42 357
Chris@42 358 #define VLEAVE() /* nothing */
Chris@42 359
Chris@42 360 #include "simd-common.h"