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