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