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