annotate src/fftw-3.3.8/simd-support/simd-neon.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 * Double-precision support added by Romain Dolbeau.
cannam@167 6 * Romain Dolbeau hereby places his modifications in the public domain.
cannam@167 7 *
cannam@167 8 * This program is free software; you can redistribute it and/or modify
cannam@167 9 * it under the terms of the GNU General Public License as published by
cannam@167 10 * the Free Software Foundation; either version 2 of the License, or
cannam@167 11 * (at your option) any later version.
cannam@167 12 *
cannam@167 13 * This program is distributed in the hope that it will be useful,
cannam@167 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 16 * GNU General Public License for more details.
cannam@167 17 *
cannam@167 18 * You should have received a copy of the GNU General Public License
cannam@167 19 * along with this program; if not, write to the Free Software
cannam@167 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 21 *
cannam@167 22 */
cannam@167 23
cannam@167 24 #if !defined(FFTW_SINGLE) && !defined( __aarch64__)
cannam@167 25 #error "NEON only works in single precision on 32 bits ARM"
cannam@167 26 #endif
cannam@167 27 #if defined(FFTW_LDOUBLE) || defined(FFTW_QUAD)
cannam@167 28 #error "NEON only works in single or double precision"
cannam@167 29 #endif
cannam@167 30
cannam@167 31 #ifdef FFTW_SINGLE
cannam@167 32 # define DS(d,s) s /* single-precision option */
cannam@167 33 # define SUFF(name) name ## _f32
cannam@167 34 #else
cannam@167 35 # define DS(d,s) d /* double-precision option */
cannam@167 36 # define SUFF(name) name ## _f64
cannam@167 37 #endif
cannam@167 38
cannam@167 39 /* define these unconditionally, because they are used by
cannam@167 40 taint.c which is compiled without neon */
cannam@167 41 #define SIMD_SUFFIX _neon /* for renaming */
cannam@167 42 #define VL DS(1,2) /* SIMD complex vector length */
cannam@167 43 #define SIMD_VSTRIDE_OKA(x) DS(1,((x) == 2))
cannam@167 44 #define SIMD_STRIDE_OKPAIR SIMD_STRIDE_OK
cannam@167 45
cannam@167 46 #if defined(__GNUC__) && !defined(__ARM_NEON__) && !defined(__ARM_NEON)
cannam@167 47 #error "compiling simd-neon.h requires -mfpu=neon or equivalent"
cannam@167 48 #endif
cannam@167 49
cannam@167 50 #include <arm_neon.h>
cannam@167 51
cannam@167 52 /* FIXME: I am not sure whether this code assumes little-endian
cannam@167 53 ordering. VLIT may or may not be wrong for big-endian systems. */
cannam@167 54 typedef DS(float64x2_t, float32x4_t) V;
cannam@167 55
cannam@167 56 #ifdef FFTW_SINGLE
cannam@167 57 # define VLIT(x0, x1) {x0, x1, x0, x1}
cannam@167 58 #else
cannam@167 59 # define VLIT(x0, x1) {x0, x1}
cannam@167 60 #endif
cannam@167 61 #define LDK(x) x
cannam@167 62 #define DVK(var, val) const V var = VLIT(val, val)
cannam@167 63
cannam@167 64 /* NEON has FMA, but a three-operand FMA is not too useful
cannam@167 65 for FFT purposes. We normally compute
cannam@167 66
cannam@167 67 t0=a+b*c
cannam@167 68 t1=a-b*c
cannam@167 69
cannam@167 70 In a three-operand instruction set this translates into
cannam@167 71
cannam@167 72 t0=a
cannam@167 73 t0+=b*c
cannam@167 74 t1=a
cannam@167 75 t1-=b*c
cannam@167 76
cannam@167 77 At least one move must be implemented, negating the advantage of
cannam@167 78 the FMA in the first place. At least some versions of gcc generate
cannam@167 79 both moves. So we are better off generating t=b*c;t0=a+t;t1=a-t;*/
cannam@167 80 #if ARCH_PREFERS_FMA
cannam@167 81 #warning "--enable-fma on NEON is probably a bad idea (see source code)"
cannam@167 82 #endif
cannam@167 83
cannam@167 84 #define VADD(a, b) SUFF(vaddq)(a, b)
cannam@167 85 #define VSUB(a, b) SUFF(vsubq)(a, b)
cannam@167 86 #define VMUL(a, b) SUFF(vmulq)(a, b)
cannam@167 87 #define VFMA(a, b, c) SUFF(vmlaq)(c, a, b) /* a*b+c */
cannam@167 88 #define VFNMS(a, b, c) SUFF(vmlsq)(c, a, b) /* FNMS=-(a*b-c) in powerpc terminology; MLS=c-a*b
cannam@167 89 in ARM terminology */
cannam@167 90 #define VFMS(a, b, c) VSUB(VMUL(a, b), c) /* FMS=a*b-c in powerpc terminology; no equivalent
cannam@167 91 arm instruction (?) */
cannam@167 92
cannam@167 93 #define STOREH(a, v) SUFF(vst1)((a), SUFF(vget_high)(v))
cannam@167 94 #define STOREL(a, v) SUFF(vst1)((a), SUFF(vget_low)(v))
cannam@167 95
cannam@167 96 static inline V LDA(const R *x, INT ivs, const R *aligned_like)
cannam@167 97 {
cannam@167 98 (void) aligned_like; /* UNUSED */
cannam@167 99 return SUFF(vld1q)(x);
cannam@167 100 }
cannam@167 101 static inline void STA(R *x, V v, INT ovs, const R *aligned_like)
cannam@167 102 {
cannam@167 103 (void) aligned_like; /* UNUSED */
cannam@167 104 SUFF(vst1q)(x, v);
cannam@167 105 }
cannam@167 106
cannam@167 107
cannam@167 108 #ifdef FFTW_SINGLE
cannam@167 109 static inline V LD(const R *x, INT ivs, const R *aligned_like)
cannam@167 110 {
cannam@167 111 (void) aligned_like; /* UNUSED */
cannam@167 112 return SUFF(vcombine)(SUFF(vld1)(x), SUFF(vld1)((x + ivs)));
cannam@167 113 }
cannam@167 114 static inline void ST(R *x, V v, INT ovs, const R *aligned_like)
cannam@167 115 {
cannam@167 116 (void) aligned_like; /* UNUSED */
cannam@167 117 /* WARNING: the extra_iter hack depends upon store-low occurring
cannam@167 118 after store-high */
cannam@167 119 STOREH(x + ovs, v);
cannam@167 120 STOREL(x,v);
cannam@167 121 }
cannam@167 122 #else /* !FFTW_SINGLE */
cannam@167 123 # define LD LDA
cannam@167 124 # define ST STA
cannam@167 125 #endif
cannam@167 126
cannam@167 127 /* 2x2 complex transpose and store */
cannam@167 128 #define STM2 DS(STA,ST)
cannam@167 129 #define STN2(x, v0, v1, ovs) /* nop */
cannam@167 130
cannam@167 131 #ifdef FFTW_SINGLE
cannam@167 132 /* store and 4x4 real transpose */
cannam@167 133 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like)
cannam@167 134 {
cannam@167 135 (void) aligned_like; /* UNUSED */
cannam@167 136 SUFF(vst1_lane)((x) , SUFF(vget_low)(v), 0);
cannam@167 137 SUFF(vst1_lane)((x + ovs), SUFF(vget_low)(v), 1);
cannam@167 138 SUFF(vst1_lane)((x + 2 * ovs), SUFF(vget_high)(v), 0);
cannam@167 139 SUFF(vst1_lane)((x + 3 * ovs), SUFF(vget_high)(v), 1);
cannam@167 140 }
cannam@167 141 #define STN4(x, v0, v1, v2, v3, ovs) /* use STM4 */
cannam@167 142 #else /* !FFTW_SINGLE */
cannam@167 143 static inline void STM4(R *x, V v, INT ovs, const R *aligned_like)
cannam@167 144 {
cannam@167 145 (void)aligned_like; /* UNUSED */
cannam@167 146 STOREL(x, v);
cannam@167 147 STOREH(x + ovs, v);
cannam@167 148 }
cannam@167 149 # define STN4(x, v0, v1, v2, v3, ovs) /* nothing */
cannam@167 150 #endif
cannam@167 151
cannam@167 152 #ifdef FFTW_SINGLE
cannam@167 153 #define FLIP_RI(x) SUFF(vrev64q)(x)
cannam@167 154 #else
cannam@167 155 /* FIXME */
cannam@167 156 #define FLIP_RI(x) SUFF(vcombine)(SUFF(vget_high)(x), SUFF(vget_low)(x))
cannam@167 157 #endif
cannam@167 158
cannam@167 159 static inline V VCONJ(V x)
cannam@167 160 {
cannam@167 161 #ifdef FFTW_SINGLE
cannam@167 162 static const uint32x4_t pm = {0, 0x80000000u, 0, 0x80000000u};
cannam@167 163 return vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(x), pm));
cannam@167 164 #else
cannam@167 165 static const uint64x2_t pm = {0, 0x8000000000000000ull};
cannam@167 166 /* Gcc-4.9.2 still does not include vreinterpretq_f64_u64, but simple
cannam@167 167 * casts generate the correct assembly.
cannam@167 168 */
cannam@167 169 return (float64x2_t)(veorq_u64((uint64x2_t)(x), (uint64x2_t)(pm)));
cannam@167 170 #endif
cannam@167 171 }
cannam@167 172
cannam@167 173 static inline V VBYI(V x)
cannam@167 174 {
cannam@167 175 return FLIP_RI(VCONJ(x));
cannam@167 176 }
cannam@167 177
cannam@167 178 static inline V VFMAI(V b, V c)
cannam@167 179 {
cannam@167 180 const V mp = VLIT(-1.0, 1.0);
cannam@167 181 return VFMA(FLIP_RI(b), mp, c);
cannam@167 182 }
cannam@167 183
cannam@167 184 static inline V VFNMSI(V b, V c)
cannam@167 185 {
cannam@167 186 const V mp = VLIT(-1.0, 1.0);
cannam@167 187 return VFNMS(FLIP_RI(b), mp, c);
cannam@167 188 }
cannam@167 189
cannam@167 190 static inline V VFMACONJ(V b, V c)
cannam@167 191 {
cannam@167 192 const V pm = VLIT(1.0, -1.0);
cannam@167 193 return VFMA(b, pm, c);
cannam@167 194 }
cannam@167 195
cannam@167 196 static inline V VFNMSCONJ(V b, V c)
cannam@167 197 {
cannam@167 198 const V pm = VLIT(1.0, -1.0);
cannam@167 199 return VFNMS(b, pm, c);
cannam@167 200 }
cannam@167 201
cannam@167 202 static inline V VFMSCONJ(V b, V c)
cannam@167 203 {
cannam@167 204 return VSUB(VCONJ(b), c);
cannam@167 205 }
cannam@167 206
cannam@167 207 #ifdef FFTW_SINGLE
cannam@167 208 #if 1
cannam@167 209 #define VEXTRACT_REIM(tr, ti, tx) \
cannam@167 210 { \
cannam@167 211 tr = SUFF(vcombine)(SUFF(vdup_lane)(SUFF(vget_low)(tx), 0), \
cannam@167 212 SUFF(vdup_lane)(SUFF(vget_high)(tx), 0)); \
cannam@167 213 ti = SUFF(vcombine)(SUFF(vdup_lane)(SUFF(vget_low)(tx), 1), \
cannam@167 214 SUFF(vdup_lane)(SUFF(vget_high)(tx), 1)); \
cannam@167 215 }
cannam@167 216 #else
cannam@167 217 /* this alternative might be faster in an ideal world, but gcc likes
cannam@167 218 to spill VVV onto the stack */
cannam@167 219 #define VEXTRACT_REIM(tr, ti, tx) \
cannam@167 220 { \
cannam@167 221 float32x4x2_t vvv = SUFF(vtrnq)(tx, tx); \
cannam@167 222 tr = vvv.val[0]; \
cannam@167 223 ti = vvv.val[1]; \
cannam@167 224 }
cannam@167 225 #endif
cannam@167 226 #else
cannam@167 227 #define VEXTRACT_REIM(tr, ti, tx) \
cannam@167 228 { \
cannam@167 229 tr = SUFF(vtrn1q)(tx, tx); \
cannam@167 230 ti = SUFF(vtrn2q)(tx, tx); \
cannam@167 231 }
cannam@167 232 #endif
cannam@167 233
cannam@167 234 static inline V VZMUL(V tx, V sr)
cannam@167 235 {
cannam@167 236 V tr, ti;
cannam@167 237 VEXTRACT_REIM(tr, ti, tx);
cannam@167 238 tr = VMUL(sr, tr);
cannam@167 239 sr = VBYI(sr);
cannam@167 240 return VFMA(ti, sr, tr);
cannam@167 241 }
cannam@167 242
cannam@167 243 static inline V VZMULJ(V tx, V sr)
cannam@167 244 {
cannam@167 245 V tr, ti;
cannam@167 246 VEXTRACT_REIM(tr, ti, tx);
cannam@167 247 tr = VMUL(sr, tr);
cannam@167 248 sr = VBYI(sr);
cannam@167 249 return VFNMS(ti, sr, tr);
cannam@167 250 }
cannam@167 251
cannam@167 252 static inline V VZMULI(V tx, V sr)
cannam@167 253 {
cannam@167 254 V tr, ti;
cannam@167 255 VEXTRACT_REIM(tr, ti, tx);
cannam@167 256 ti = VMUL(ti, sr);
cannam@167 257 sr = VBYI(sr);
cannam@167 258 return VFMS(tr, sr, ti);
cannam@167 259 }
cannam@167 260
cannam@167 261 static inline V VZMULIJ(V tx, V sr)
cannam@167 262 {
cannam@167 263 V tr, ti;
cannam@167 264 VEXTRACT_REIM(tr, ti, tx);
cannam@167 265 ti = VMUL(ti, sr);
cannam@167 266 sr = VBYI(sr);
cannam@167 267 return VFMA(tr, sr, ti);
cannam@167 268 }
cannam@167 269
cannam@167 270 /* twiddle storage #1: compact, slower */
cannam@167 271 #ifdef FFTW_SINGLE
cannam@167 272 #define VTW1(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}
cannam@167 273 #else
cannam@167 274 #define VTW1(v,x) {TW_CEXP, v, x}
cannam@167 275 #endif
cannam@167 276 #define TWVL1 VL
cannam@167 277 static inline V BYTW1(const R *t, V sr)
cannam@167 278 {
cannam@167 279 V tx = LDA(t, 2, 0);
cannam@167 280 return VZMUL(tx, sr);
cannam@167 281 }
cannam@167 282
cannam@167 283 static inline V BYTWJ1(const R *t, V sr)
cannam@167 284 {
cannam@167 285 V tx = LDA(t, 2, 0);
cannam@167 286 return VZMULJ(tx, sr);
cannam@167 287 }
cannam@167 288
cannam@167 289 /* twiddle storage #2: twice the space, faster (when in cache) */
cannam@167 290 #ifdef FFTW_SINGLE
cannam@167 291 # define VTW2(v,x) \
cannam@167 292 {TW_COS, v, x}, {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+1, x}, \
cannam@167 293 {TW_SIN, v, -x}, {TW_SIN, v, x}, {TW_SIN, v+1, -x}, {TW_SIN, v+1, x}
cannam@167 294 #else
cannam@167 295 # define VTW2(v,x) \
cannam@167 296 {TW_COS, v, x}, {TW_COS, v, x}, {TW_SIN, v, -x}, {TW_SIN, v, x}
cannam@167 297 #endif
cannam@167 298 #define TWVL2 (2 * VL)
cannam@167 299
cannam@167 300 static inline V BYTW2(const R *t, V sr)
cannam@167 301 {
cannam@167 302 V si = FLIP_RI(sr);
cannam@167 303 V tr = LDA(t, 2, 0), ti = LDA(t+2*VL, 2, 0);
cannam@167 304 return VFMA(ti, si, VMUL(tr, sr));
cannam@167 305 }
cannam@167 306
cannam@167 307 static inline V BYTWJ2(const R *t, V sr)
cannam@167 308 {
cannam@167 309 V si = FLIP_RI(sr);
cannam@167 310 V tr = LDA(t, 2, 0), ti = LDA(t+2*VL, 2, 0);
cannam@167 311 return VFNMS(ti, si, VMUL(tr, sr));
cannam@167 312 }
cannam@167 313
cannam@167 314 /* twiddle storage #3 */
cannam@167 315 #ifdef FFTW_SINGLE
cannam@167 316 # define VTW3(v,x) {TW_CEXP, v, x}, {TW_CEXP, v+1, x}
cannam@167 317 #else
cannam@167 318 # define VTW3(v,x) {TW_CEXP, v, x}
cannam@167 319 #endif
cannam@167 320 # define TWVL3 (VL)
cannam@167 321
cannam@167 322 /* twiddle storage for split arrays */
cannam@167 323 #ifdef FFTW_SINGLE
cannam@167 324 # define VTWS(v,x) \
cannam@167 325 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_COS, v+2, x}, {TW_COS, v+3, x}, \
cannam@167 326 {TW_SIN, v, x}, {TW_SIN, v+1, x}, {TW_SIN, v+2, x}, {TW_SIN, v+3, x}
cannam@167 327 #else
cannam@167 328 # define VTWS(v,x) \
cannam@167 329 {TW_COS, v, x}, {TW_COS, v+1, x}, {TW_SIN, v, x}, {TW_SIN, v+1, x}
cannam@167 330 #endif
cannam@167 331 #define TWVLS (2 * VL)
cannam@167 332
cannam@167 333 #define VLEAVE() /* nothing */
cannam@167 334
cannam@167 335 #include "simd-common.h"