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

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