annotate src/fftw-3.3.5/simd-support/simd-altivec.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-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 #ifndef FFTW_SINGLE
cannam@127 22 #error "ALTIVEC only works in single precision"
cannam@127 23 #endif
cannam@127 24
cannam@127 25 /* define these unconditionally, because they are used by
cannam@127 26 taint.c which is compiled without altivec */
cannam@127 27 #define SIMD_SUFFIX _altivec /* for renaming */
cannam@127 28 #define VL 2 /* SIMD complex vector length */
cannam@127 29 #define SIMD_VSTRIDE_OKA(x) ((x) == 2)
cannam@127 30 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OKA
cannam@127 31
cannam@127 32 #if !defined(__VEC__) && !defined(FAKE__VEC__)
cannam@127 33 # error "compiling simd-altivec.h requires -maltivec or equivalent"
cannam@127 34 #endif
cannam@127 35
cannam@127 36 #ifdef HAVE_ALTIVEC_H
cannam@127 37 # include <altivec.h>
cannam@127 38 #endif
cannam@127 39
cannam@127 40 typedef vector float V;
cannam@127 41 #define VLIT(x0, x1, x2, x3) {x0, x1, x2, x3}
cannam@127 42 #define LDK(x) x
cannam@127 43 #define DVK(var, val) const V var = VLIT(val, val, val, val)
cannam@127 44
cannam@127 45 static inline V VADD(V a, V b) { return vec_add(a, b); }
cannam@127 46 static inline V VSUB(V a, V b) { return vec_sub(a, b); }
cannam@127 47 static inline V VFMA(V a, V b, V c) { return vec_madd(a, b, c); }
cannam@127 48 static inline V VFNMS(V a, V b, V c) { return vec_nmsub(a, b, c); }
cannam@127 49
cannam@127 50 static inline V VMUL(V a, V b)
cannam@127 51 {
cannam@127 52 DVK(zero, -0.0);
cannam@127 53 return VFMA(a, b, zero);
cannam@127 54 }
cannam@127 55
cannam@127 56 static inline V VFMS(V a, V b, V c) { return VSUB(VMUL(a, b), c); }
cannam@127 57
cannam@127 58 static inline V LDA(const R *x, INT ivs, const R *aligned_like)
cannam@127 59 {
cannam@127 60 UNUSED(ivs);
cannam@127 61 UNUSED(aligned_like);
cannam@127 62 return vec_ld(0, x);
cannam@127 63 }
cannam@127 64
cannam@127 65 static inline V LD(const R *x, INT ivs, const R *aligned_like)
cannam@127 66 {
cannam@127 67 /* common subexpressions */
cannam@127 68 const INT fivs = sizeof(R) * ivs;
cannam@127 69 /* you are not expected to understand this: */
cannam@127 70 const vector unsigned int perm = VLIT(0, 0, 0xFFFFFFFF, 0xFFFFFFFF);
cannam@127 71 vector unsigned char ml = vec_lvsr(fivs + 8, aligned_like);
cannam@127 72 vector unsigned char mh = vec_lvsl(0, aligned_like);
cannam@127 73 vector unsigned char msk =
cannam@127 74 (vector unsigned char)vec_sel((V)mh, (V)ml, perm);
cannam@127 75 /* end of common subexpressions */
cannam@127 76
cannam@127 77 return vec_perm(vec_ld(0, x), vec_ld(fivs, x), msk);
cannam@127 78 }
cannam@127 79
cannam@127 80 /* store lower half */
cannam@127 81 static inline void STH(R *x, V v, R *aligned_like)
cannam@127 82 {
cannam@127 83 v = vec_perm(v, v, vec_lvsr(0, aligned_like));
cannam@127 84 vec_ste(v, 0, x);
cannam@127 85 vec_ste(v, sizeof(R), x);
cannam@127 86 }
cannam@127 87
cannam@127 88 static inline void STL(R *x, V v, INT ovs, R *aligned_like)
cannam@127 89 {
cannam@127 90 const INT fovs = sizeof(R) * ovs;
cannam@127 91 v = vec_perm(v, v, vec_lvsr(fovs + 8, aligned_like));
cannam@127 92 vec_ste(v, fovs, x);
cannam@127 93 vec_ste(v, sizeof(R) + fovs, x);
cannam@127 94 }
cannam@127 95
cannam@127 96 static inline void STA(R *x, V v, INT ovs, R *aligned_like)
cannam@127 97 {
cannam@127 98 UNUSED(ovs);
cannam@127 99 UNUSED(aligned_like);
cannam@127 100 vec_st(v, 0, x);
cannam@127 101 }
cannam@127 102
cannam@127 103 static inline void ST(R *x, V v, INT ovs, R *aligned_like)
cannam@127 104 {
cannam@127 105 /* WARNING: the extra_iter hack depends upon STH occurring after
cannam@127 106 STL */
cannam@127 107 STL(x, v, ovs, aligned_like);
cannam@127 108 STH(x, v, aligned_like);
cannam@127 109 }
cannam@127 110
cannam@127 111 #define STM2(x, v, ovs, aligned_like) /* no-op */
cannam@127 112
cannam@127 113 static inline void STN2(R *x, V v0, V v1, INT ovs)
cannam@127 114 {
cannam@127 115 const INT fovs = sizeof(R) * ovs;
cannam@127 116 const vector unsigned int even =
cannam@127 117 VLIT(0x00010203, 0x04050607, 0x10111213, 0x14151617);
cannam@127 118 const vector unsigned int odd =
cannam@127 119 VLIT(0x08090a0b, 0x0c0d0e0f, 0x18191a1b, 0x1c1d1e1f);
cannam@127 120 vec_st(vec_perm(v0, v1, (vector unsigned char)even), 0, x);
cannam@127 121 vec_st(vec_perm(v0, v1, (vector unsigned char)odd), fovs, x);
cannam@127 122 }
cannam@127 123
cannam@127 124 #define STM4(x, v, ovs, aligned_like) /* no-op */
cannam@127 125
cannam@127 126 static inline void STN4(R *x, V v0, V v1, V v2, V v3, INT ovs)
cannam@127 127 {
cannam@127 128 const INT fovs = sizeof(R) * ovs;
cannam@127 129 V x0 = vec_mergeh(v0, v2);
cannam@127 130 V x1 = vec_mergel(v0, v2);
cannam@127 131 V x2 = vec_mergeh(v1, v3);
cannam@127 132 V x3 = vec_mergel(v1, v3);
cannam@127 133 V y0 = vec_mergeh(x0, x2);
cannam@127 134 V y1 = vec_mergel(x0, x2);
cannam@127 135 V y2 = vec_mergeh(x1, x3);
cannam@127 136 V y3 = vec_mergel(x1, x3);
cannam@127 137 vec_st(y0, 0, x);
cannam@127 138 vec_st(y1, fovs, x);
cannam@127 139 vec_st(y2, 2 * fovs, x);
cannam@127 140 vec_st(y3, 3 * fovs, x);
cannam@127 141 }
cannam@127 142
cannam@127 143 static inline V FLIP_RI(V x)
cannam@127 144 {
cannam@127 145 const vector unsigned int perm =
cannam@127 146 VLIT(0x04050607, 0x00010203, 0x0c0d0e0f, 0x08090a0b);
cannam@127 147 return vec_perm(x, x, (vector unsigned char)perm);
cannam@127 148 }
cannam@127 149
cannam@127 150 static inline V VCONJ(V x)
cannam@127 151 {
cannam@127 152 const V pmpm = VLIT(0.0, -0.0, 0.0, -0.0);
cannam@127 153 return vec_xor(x, pmpm);
cannam@127 154 }
cannam@127 155
cannam@127 156 static inline V VBYI(V x)
cannam@127 157 {
cannam@127 158 return FLIP_RI(VCONJ(x));
cannam@127 159 }
cannam@127 160
cannam@127 161 static inline V VFMAI(V b, V c)
cannam@127 162 {
cannam@127 163 const V mpmp = VLIT(-1.0, 1.0, -1.0, 1.0);
cannam@127 164 return VFMA(FLIP_RI(b), mpmp, c);
cannam@127 165 }
cannam@127 166
cannam@127 167 static inline V VFNMSI(V b, V c)
cannam@127 168 {
cannam@127 169 const V mpmp = VLIT(-1.0, 1.0, -1.0, 1.0);
cannam@127 170 return VFNMS(FLIP_RI(b), mpmp, c);
cannam@127 171 }
cannam@127 172
cannam@127 173 static inline V VFMACONJ(V b, V c)
cannam@127 174 {
cannam@127 175 const V pmpm = VLIT(1.0, -1.0, 1.0, -1.0);
cannam@127 176 return VFMA(b, pmpm, c);
cannam@127 177 }
cannam@127 178
cannam@127 179 static inline V VFNMSCONJ(V b, V c)
cannam@127 180 {
cannam@127 181 const V pmpm = VLIT(1.0, -1.0, 1.0, -1.0);
cannam@127 182 return VFNMS(b, pmpm, c);
cannam@127 183 }
cannam@127 184
cannam@127 185 static inline V VFMSCONJ(V b, V c)
cannam@127 186 {
cannam@127 187 return VSUB(VCONJ(b), c);
cannam@127 188 }
cannam@127 189
cannam@127 190 static inline V VZMUL(V tx, V sr)
cannam@127 191 {
cannam@127 192 const vector unsigned int real =
cannam@127 193 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b);
cannam@127 194 const vector unsigned int imag =
cannam@127 195 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f);
cannam@127 196 V si = VBYI(sr);
cannam@127 197 V tr = vec_perm(tx, tx, (vector unsigned char)real);
cannam@127 198 V ti = vec_perm(tx, tx, (vector unsigned char)imag);
cannam@127 199 return VFMA(ti, si, VMUL(tr, sr));
cannam@127 200 }
cannam@127 201
cannam@127 202 static inline V VZMULJ(V tx, V sr)
cannam@127 203 {
cannam@127 204 const vector unsigned int real =
cannam@127 205 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b);
cannam@127 206 const vector unsigned int imag =
cannam@127 207 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f);
cannam@127 208 V si = VBYI(sr);
cannam@127 209 V tr = vec_perm(tx, tx, (vector unsigned char)real);
cannam@127 210 V ti = vec_perm(tx, tx, (vector unsigned char)imag);
cannam@127 211 return VFNMS(ti, si, VMUL(tr, sr));
cannam@127 212 }
cannam@127 213
cannam@127 214 static inline V VZMULI(V tx, V si)
cannam@127 215 {
cannam@127 216 const vector unsigned int real =
cannam@127 217 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b);
cannam@127 218 const vector unsigned int imag =
cannam@127 219 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f);
cannam@127 220 V sr = VBYI(si);
cannam@127 221 V tr = vec_perm(tx, tx, (vector unsigned char)real);
cannam@127 222 V ti = vec_perm(tx, tx, (vector unsigned char)imag);
cannam@127 223 return VFNMS(ti, si, VMUL(tr, sr));
cannam@127 224 }
cannam@127 225
cannam@127 226 static inline V VZMULIJ(V tx, V si)
cannam@127 227 {
cannam@127 228 const vector unsigned int real =
cannam@127 229 VLIT(0x00010203, 0x00010203, 0x08090a0b, 0x08090a0b);
cannam@127 230 const vector unsigned int imag =
cannam@127 231 VLIT(0x04050607, 0x04050607, 0x0c0d0e0f, 0x0c0d0e0f);
cannam@127 232 V sr = VBYI(si);
cannam@127 233 V tr = vec_perm(tx, tx, (vector unsigned char)real);
cannam@127 234 V ti = vec_perm(tx, tx, (vector unsigned char)imag);
cannam@127 235 return VFMA(ti, si, VMUL(tr, sr));
cannam@127 236 }
cannam@127 237
cannam@127 238 /* twiddle storage #1: compact, slower */
cannam@127 239 #define VTW1(v,x) \
cannam@127 240 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x}
cannam@127 241 #define TWVL1 (VL)
cannam@127 242
cannam@127 243 static inline V BYTW1(const R *t, V sr)
cannam@127 244 {
cannam@127 245 const V *twp = (const V *)t;
cannam@127 246 V si = VBYI(sr);
cannam@127 247 V tx = twp[0];
cannam@127 248 V tr = vec_mergeh(tx, tx);
cannam@127 249 V ti = vec_mergel(tx, tx);
cannam@127 250 return VFMA(ti, si, VMUL(tr, sr));
cannam@127 251 }
cannam@127 252
cannam@127 253 static inline V BYTWJ1(const R *t, V sr)
cannam@127 254 {
cannam@127 255 const V *twp = (const V *)t;
cannam@127 256 V si = VBYI(sr);
cannam@127 257 V tx = twp[0];
cannam@127 258 V tr = vec_mergeh(tx, tx);
cannam@127 259 V ti = vec_mergel(tx, tx);
cannam@127 260 return VFNMS(ti, si, VMUL(tr, sr));
cannam@127 261 }
cannam@127 262
cannam@127 263 /* twiddle storage #2: twice the space, faster (when in cache) */
cannam@127 264 #define VTW2(v,x) \
cannam@127 265 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
cannam@127 266 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}
cannam@127 267 #define TWVL2 (2 * VL)
cannam@127 268
cannam@127 269 static inline V BYTW2(const R *t, V sr)
cannam@127 270 {
cannam@127 271 const V *twp = (const V *)t;
cannam@127 272 V si = FLIP_RI(sr);
cannam@127 273 V tr = twp[0], ti = twp[1];
cannam@127 274 return VFMA(ti, si, VMUL(tr, sr));
cannam@127 275 }
cannam@127 276
cannam@127 277 static inline V BYTWJ2(const R *t, V sr)
cannam@127 278 {
cannam@127 279 const V *twp = (const V *)t;
cannam@127 280 V si = FLIP_RI(sr);
cannam@127 281 V tr = twp[0], ti = twp[1];
cannam@127 282 return VFNMS(ti, si, VMUL(tr, sr));
cannam@127 283 }
cannam@127 284
cannam@127 285 /* twiddle storage #3 */
cannam@127 286 #define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}
cannam@127 287 #define TWVL3 (VL)
cannam@127 288
cannam@127 289 /* twiddle storage for split arrays */
cannam@127 290 #define VTWS(v,x) \
cannam@127 291 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
cannam@127 292 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}
cannam@127 293 #define TWVLS (2 * VL)
cannam@127 294
cannam@127 295 #define VLEAVE() /* nothing */
cannam@127 296
cannam@127 297 #include "simd-common.h"