annotate src/fftw-3.3.5/simd-support/simd-generic256.h @ 148:b4bfdf10c4b3

Update Win64 capnp builds to v0.6
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 22 May 2017 18:56:49 +0100
parents 7867fa7e1b6b
children
rev   line source
cannam@127 1 /*
cannam@127 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
cannam@127 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
cannam@127 4 *
cannam@127 5 * Generic256d added by Romain Dolbeau, and turned into simd-generic256.h
cannam@127 6 * with single & double precision by Erik Lindahl.
cannam@127 7 * Romain Dolbeau hereby places his modifications in the public domain.
cannam@127 8 * Erik Lindahl hereby places his modifications in the public domain.
cannam@127 9 *
cannam@127 10 * This program is free software; you can redistribute it and/or modify
cannam@127 11 * it under the terms of the GNU General Public License as published by
cannam@127 12 * the Free Software Foundation; either version 2 of the License, or
cannam@127 13 * (at your option) any later version.
cannam@127 14 *
cannam@127 15 * This program is distributed in the hope that it will be useful,
cannam@127 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@127 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@127 18 * GNU General Public License for more details.
cannam@127 19 *
cannam@127 20 * You should have received a copy of the GNU General Public License
cannam@127 21 * along with this program; if not, write to the Free Software
cannam@127 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@127 23 *
cannam@127 24 */
cannam@127 25
cannam@127 26 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD)
cannam@127 27 # error "Generic simd256 only works in single or double precision"
cannam@127 28 #endif
cannam@127 29
cannam@127 30 #define SIMD_SUFFIX _generic_simd256 /* for renaming */
cannam@127 31
cannam@127 32 #ifdef FFTW_SINGLE
cannam@127 33 # define DS(d,s) s /* single-precision option */
cannam@127 34 # define VDUPL(x) {x[0],x[0],x[2],x[2],x[4],x[4],x[6],x[6]}
cannam@127 35 # define VDUPH(x) {x[1],x[1],x[3],x[3],x[5],x[5],x[7],x[7]}
cannam@127 36 # define DVK(var, val) V var = {val,val,val,val,val,val,val,val}
cannam@127 37 #else
cannam@127 38 # define DS(d,s) d /* double-precision option */
cannam@127 39 # define VDUPL(x) {x[0],x[0],x[2],x[2]}
cannam@127 40 # define VDUPH(x) {x[1],x[1],x[3],x[3]}
cannam@127 41 # define DVK(var, val) V var = {val, val, val, val}
cannam@127 42 #endif
cannam@127 43
cannam@127 44 #define VL DS(2,4) /* SIMD vector length, in term of complex numbers */
cannam@127 45 #define SIMD_VSTRIDE_OKA(x) DS(1,((x) == 2))
cannam@127 46 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK
cannam@127 47
cannam@127 48 typedef DS(double,float) V __attribute__ ((vector_size(32)));
cannam@127 49
cannam@127 50 #define VADD(a,b) ((a)+(b))
cannam@127 51 #define VSUB(a,b) ((a)-(b))
cannam@127 52 #define VMUL(a,b) ((a)*(b))
cannam@127 53
cannam@127 54 #define LDK(x) x
cannam@127 55
cannam@127 56 static inline V LDA(const R *x, INT ivs, const R *aligned_like)
cannam@127 57 {
cannam@127 58 V var;
cannam@127 59 (void)aligned_like; /* UNUSED */
cannam@127 60 return *(const V *)x;
cannam@127 61 }
cannam@127 62
cannam@127 63 static inline void STA(R *x, V v, INT ovs, const R *aligned_like)
cannam@127 64 {
cannam@127 65 (void)aligned_like; /* UNUSED */
cannam@127 66 (void)ovs; /* UNUSED */
cannam@127 67 *(V *)x = v;
cannam@127 68 }
cannam@127 69
cannam@127 70 static inline V LD(const R *x, INT ivs, const R *aligned_like)
cannam@127 71 {
cannam@127 72 V var;
cannam@127 73 (void)aligned_like; /* UNUSED */
cannam@127 74 var[0] = x[0];
cannam@127 75 var[1] = x[1];
cannam@127 76 var[2] = x[ivs];
cannam@127 77 var[3] = x[ivs+1];
cannam@127 78 #ifdef FFTW_SINGLE
cannam@127 79 var[4] = x[2*ivs];
cannam@127 80 var[5] = x[2*ivs+1];
cannam@127 81 var[6] = x[3*ivs];
cannam@127 82 var[7] = x[3*ivs+1];
cannam@127 83 #endif
cannam@127 84 return var;
cannam@127 85 }
cannam@127 86
cannam@127 87
cannam@127 88 /* ST has to be separate due to the storage hack requiring reverse order */
cannam@127 89
cannam@127 90 static inline void ST(R *x, V v, INT ovs, const R *aligned_like)
cannam@127 91 {
cannam@127 92 (void)aligned_like; /* UNUSED */
cannam@127 93 #ifdef FFTW_SINGLE
cannam@127 94 *(x + 3*ovs ) = v[6];
cannam@127 95 *(x + 3*ovs + 1) = v[7];
cannam@127 96 *(x + 2*ovs ) = v[4];
cannam@127 97 *(x + 2*ovs + 1) = v[5];
cannam@127 98 *(x + ovs ) = v[2];
cannam@127 99 *(x + ovs + 1) = v[3];
cannam@127 100 *(x ) = v[0];
cannam@127 101 *(x + 1) = v[1];
cannam@127 102 #else
cannam@127 103 *(x + ovs ) = v[2];
cannam@127 104 *(x + ovs + 1) = v[3];
cannam@127 105 *(x ) = v[0];
cannam@127 106 *(x + 1) = v[1];
cannam@127 107 #endif
cannam@127 108 }
cannam@127 109
cannam@127 110 #ifdef FFTW_SINGLE
cannam@127 111 #define STM2(x, v, ovs, a) /* no-op */
cannam@127 112 static inline void STN2(R *x, V v0, V v1, INT ovs)
cannam@127 113 {
cannam@127 114 x[ 0] = v0[0];
cannam@127 115 x[ 1] = v0[1];
cannam@127 116 x[ 2] = v1[0];
cannam@127 117 x[ 3] = v1[1];
cannam@127 118 x[ ovs ] = v0[2];
cannam@127 119 x[ ovs + 1] = v0[3];
cannam@127 120 x[ ovs + 2] = v1[2];
cannam@127 121 x[ ovs + 3] = v1[3];
cannam@127 122 x[2*ovs ] = v0[4];
cannam@127 123 x[2*ovs + 1] = v0[5];
cannam@127 124 x[2*ovs + 2] = v1[4];
cannam@127 125 x[2*ovs + 3] = v1[5];
cannam@127 126 x[3*ovs ] = v0[6];
cannam@127 127 x[3*ovs + 1] = v0[7];
cannam@127 128 x[3*ovs + 2] = v1[6];
cannam@127 129 x[3*ovs + 3] = v1[7];
cannam@127 130 }
cannam@127 131
cannam@127 132 # define STM4(x, v, ovs, aligned_like) /* no-op */
cannam@127 133 static inline void STN4(R *x, V v0, V v1, V v2, V v3, INT ovs)
cannam@127 134 {
cannam@127 135 *(x ) = v0[0];
cannam@127 136 *(x + 1) = v1[0];
cannam@127 137 *(x + 2) = v2[0];
cannam@127 138 *(x + 3) = v3[0];
cannam@127 139 *(x + ovs ) = v0[1];
cannam@127 140 *(x + ovs + 1) = v1[1];
cannam@127 141 *(x + ovs + 2) = v2[1];
cannam@127 142 *(x + ovs + 3) = v3[1];
cannam@127 143 *(x + 2 * ovs ) = v0[2];
cannam@127 144 *(x + 2 * ovs + 1) = v1[2];
cannam@127 145 *(x + 2 * ovs + 2) = v2[2];
cannam@127 146 *(x + 2 * ovs + 3) = v3[2];
cannam@127 147 *(x + 3 * ovs ) = v0[3];
cannam@127 148 *(x + 3 * ovs + 1) = v1[3];
cannam@127 149 *(x + 3 * ovs + 2) = v2[3];
cannam@127 150 *(x + 3 * ovs + 3) = v3[3];
cannam@127 151 *(x + 4 * ovs ) = v0[4];
cannam@127 152 *(x + 4 * ovs + 1) = v1[4];
cannam@127 153 *(x + 4 * ovs + 2) = v2[4];
cannam@127 154 *(x + 4 * ovs + 3) = v3[4];
cannam@127 155 *(x + 5 * ovs ) = v0[5];
cannam@127 156 *(x + 5 * ovs + 1) = v1[5];
cannam@127 157 *(x + 5 * ovs + 2) = v2[5];
cannam@127 158 *(x + 5 * ovs + 3) = v3[5];
cannam@127 159 *(x + 6 * ovs ) = v0[6];
cannam@127 160 *(x + 6 * ovs + 1) = v1[6];
cannam@127 161 *(x + 6 * ovs + 2) = v2[6];
cannam@127 162 *(x + 6 * ovs + 3) = v3[6];
cannam@127 163 *(x + 7 * ovs ) = v0[7];
cannam@127 164 *(x + 7 * ovs + 1) = v1[7];
cannam@127 165 *(x + 7 * ovs + 2) = v2[7];
cannam@127 166 *(x + 7 * ovs + 3) = v3[7];
cannam@127 167 }
cannam@127 168
cannam@127 169 #else
cannam@127 170 /* FFTW_DOUBLE */
cannam@127 171
cannam@127 172 #define STM2 ST
cannam@127 173 #define STN2(x, v0, v1, ovs) /* nop */
cannam@127 174 #define STM4(x, v, ovs, aligned_like) /* no-op */
cannam@127 175
cannam@127 176 static inline void STN4(R *x, V v0, V v1, V v2, V v3, INT ovs) {
cannam@127 177 *(x ) = v0[0];
cannam@127 178 *(x + 1) = v1[0];
cannam@127 179 *(x + 2) = v2[0];
cannam@127 180 *(x + 3) = v3[0];
cannam@127 181 *(x + ovs ) = v0[1];
cannam@127 182 *(x + ovs + 1) = v1[1];
cannam@127 183 *(x + ovs + 2) = v2[1];
cannam@127 184 *(x + ovs + 3) = v3[1];
cannam@127 185 *(x + 2 * ovs ) = v0[2];
cannam@127 186 *(x + 2 * ovs + 1) = v1[2];
cannam@127 187 *(x + 2 * ovs + 2) = v2[2];
cannam@127 188 *(x + 2 * ovs + 3) = v3[2];
cannam@127 189 *(x + 3 * ovs ) = v0[3];
cannam@127 190 *(x + 3 * ovs + 1) = v1[3];
cannam@127 191 *(x + 3 * ovs + 2) = v2[3];
cannam@127 192 *(x + 3 * ovs + 3) = v3[3];
cannam@127 193 }
cannam@127 194 #endif
cannam@127 195
cannam@127 196 static inline V FLIP_RI(V x)
cannam@127 197 {
cannam@127 198 #ifdef FFTW_SINGLE
cannam@127 199 return (V){x[1],x[0],x[3],x[2],x[5],x[4],x[7],x[6]};
cannam@127 200 #else
cannam@127 201 return (V){x[1],x[0],x[3],x[2]};
cannam@127 202 #endif
cannam@127 203 }
cannam@127 204
cannam@127 205 static inline V VCONJ(V x)
cannam@127 206 {
cannam@127 207 #ifdef FFTW_SINGLE
cannam@127 208 return (x * (V){1.0,-1.0,1.0,-1.0,1.0,-1.0,1.0,-1.0});
cannam@127 209 #else
cannam@127 210 return (x * (V){1.0,-1.0,1.0,-1.0});
cannam@127 211 #endif
cannam@127 212 }
cannam@127 213
cannam@127 214 static inline V VBYI(V x)
cannam@127 215 {
cannam@127 216 return FLIP_RI(VCONJ(x));
cannam@127 217 }
cannam@127 218
cannam@127 219 /* FMA support */
cannam@127 220 #define VFMA(a, b, c) VADD(c, VMUL(a, b))
cannam@127 221 #define VFNMS(a, b, c) VSUB(c, VMUL(a, b))
cannam@127 222 #define VFMS(a, b, c) VSUB(VMUL(a, b), c)
cannam@127 223 #define VFMAI(b, c) VADD(c, VBYI(b))
cannam@127 224 #define VFNMSI(b, c) VSUB(c, VBYI(b))
cannam@127 225 #define VFMACONJ(b,c) VADD(VCONJ(b),c)
cannam@127 226 #define VFMSCONJ(b,c) VSUB(VCONJ(b),c)
cannam@127 227 #define VFNMSCONJ(b,c) VSUB(c, VCONJ(b))
cannam@127 228
cannam@127 229 static inline V VZMUL(V tx, V sr)
cannam@127 230 {
cannam@127 231 V tr = VDUPL(tx);
cannam@127 232 V ti = VDUPH(tx);
cannam@127 233 tr = VMUL(sr, tr);
cannam@127 234 sr = VBYI(sr);
cannam@127 235 return VFMA(ti, sr, tr);
cannam@127 236 }
cannam@127 237
cannam@127 238 static inline V VZMULJ(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 VFNMS(ti, sr, tr);
cannam@127 245 }
cannam@127 246
cannam@127 247 static inline V VZMULI(V tx, V sr)
cannam@127 248 {
cannam@127 249 V tr = VDUPL(tx);
cannam@127 250 V ti = VDUPH(tx);
cannam@127 251 ti = VMUL(ti, sr);
cannam@127 252 sr = VBYI(sr);
cannam@127 253 return VFMS(tr, sr, ti);
cannam@127 254 }
cannam@127 255
cannam@127 256 static inline V VZMULIJ(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 VFMA(tr, sr, ti);
cannam@127 263 }
cannam@127 264
cannam@127 265 /* twiddle storage #1: compact, slower */
cannam@127 266 #ifdef FFTW_SINGLE
cannam@127 267 # define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}, {TW_CEXP, v+2, x}, {TW_CEXP, v+3, x}
cannam@127 268 #else
cannam@127 269 # define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}
cannam@127 270 #endif
cannam@127 271 #define TWVL1 (VL)
cannam@127 272
cannam@127 273 static inline V BYTW1(const R *t, V sr)
cannam@127 274 {
cannam@127 275 return VZMUL(LDA(t, 2, t), sr);
cannam@127 276 }
cannam@127 277
cannam@127 278 static inline V BYTWJ1(const R *t, V sr)
cannam@127 279 {
cannam@127 280 return VZMULJ(LDA(t, 2, t), sr);
cannam@127 281 }
cannam@127 282
cannam@127 283 /* twiddle storage #2: twice the space, faster (when in cache) */
cannam@127 284 #ifdef FFTW_SINGLE
cannam@127 285 # define VTW2(v,x) \
cannam@127 286 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
cannam@127 287 {TW_COS, v+2, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, {TW_COS, v+3, x}, \
cannam@127 288 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}, \
cannam@127 289 {TW_SIN, v+2, -x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, -x}, {TW_SIN, v+3, x}
cannam@127 290 #else
cannam@127 291 # define VTW2(v,x) \
cannam@127 292 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
cannam@127 293 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}
cannam@127 294 #endif
cannam@127 295 #define TWVL2 (2 * VL)
cannam@127 296
cannam@127 297 static inline V BYTW2(const R *t, V sr)
cannam@127 298 {
cannam@127 299 const V *twp = (const V *)t;
cannam@127 300 V si = FLIP_RI(sr);
cannam@127 301 V tr = twp[0], ti = twp[1];
cannam@127 302 return VFMA(tr, sr, VMUL(ti, si));
cannam@127 303 }
cannam@127 304
cannam@127 305 static inline V BYTWJ2(const R *t, V sr)
cannam@127 306 {
cannam@127 307 const V *twp = (const V *)t;
cannam@127 308 V si = FLIP_RI(sr);
cannam@127 309 V tr = twp[0], ti = twp[1];
cannam@127 310 return VFNMS(ti, si, VMUL(tr, sr));
cannam@127 311 }
cannam@127 312
cannam@127 313 /* twiddle storage #3 */
cannam@127 314 #define VTW3 VTW1
cannam@127 315 #define TWVL3 TWVL1
cannam@127 316
cannam@127 317 /* twiddle storage for split arrays */
cannam@127 318 #ifdef FFTW_SINGLE
cannam@127 319 # define VTWS(v,x) \
cannam@127 320 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
cannam@127 321 {TW_COS, v+4, x}, {TW_COS, v+5, x}, {TW_COS, v+6, x}, {TW_COS, v+7, x}, \
cannam@127 322 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}, \
cannam@127 323 {TW_SIN, v+4, x}, {TW_SIN, v+5, x}, {TW_SIN, v+6, x}, {TW_SIN, v+7, x}
cannam@127 324 #else
cannam@127 325 # define VTWS(v,x) \
cannam@127 326 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
cannam@127 327 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}
cannam@127 328 #endif
cannam@127 329 #define TWVLS (2 * VL)
cannam@127 330
cannam@127 331 #define VLEAVE() /* nothing */
cannam@127 332
cannam@127 333 #include "simd-common.h"