1 2 /* Copyright (c) 2013 Julien Pommier ( pommier@modartt.com ) 3 4 Redistribution and use of the Software in source and binary forms, 5 with or without modification, is permitted provided that the 6 following conditions are met: 7 8 - Neither the names of NCAR's Computational and Information Systems 9 Laboratory, the University Corporation for Atmospheric Research, 10 nor the names of its sponsors or contributors may be used to 11 endorse or promote products derived from this Software without 12 specific prior written permission. 13 14 - Redistributions of source code must retain the above copyright 15 notices, this list of conditions, and the disclaimer below. 16 17 - Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions, and the disclaimer below in the 19 documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT 26 HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL, 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 30 SOFTWARE. 31 */ 32 33 #ifndef PF_NEON_FLT_H 34 #define PF_NEON_FLT_H 35 36 /* 37 ARM NEON support macros 38 */ 39 #if !defined(PFFFT_SIMD_DISABLE) && defined(PFFFT_ENABLE_NEON) && (defined(__arm__) || defined(__aarch64__) || defined(__arm64__)) 40 #pragma message( __FILE__ ": ARM NEON macros are defined" ) 41 42 # include <arm_neon.h> 43 typedef float32x4_t v4sf; 44 45 # define SIMD_SZ 4 46 47 typedef union v4sf_union { 48 v4sf v; 49 float f[SIMD_SZ]; 50 } v4sf_union; 51 52 # define VARCH "NEON" 53 # define VREQUIRES_ALIGN 0 /* usually no alignment required */ 54 # define VZERO() vdupq_n_f32(0) 55 # define VMUL(a,b) vmulq_f32(a,b) 56 # define VADD(a,b) vaddq_f32(a,b) 57 # define VMADD(a,b,c) vmlaq_f32(c,a,b) 58 # define VSUB(a,b) vsubq_f32(a,b) 59 # define LD_PS1(p) vld1q_dup_f32(&(p)) 60 # define VLOAD_UNALIGNED(ptr) (*((v4sf*)(ptr))) 61 # define VLOAD_ALIGNED(ptr) (*((v4sf*)(ptr))) 62 # define INTERLEAVE2(in1, in2, out1, out2) { float32x4x2_t tmp__ = vzipq_f32(in1,in2); out1=tmp__.val[0]; out2=tmp__.val[1]; } 63 # define UNINTERLEAVE2(in1, in2, out1, out2) { float32x4x2_t tmp__ = vuzpq_f32(in1,in2); out1=tmp__.val[0]; out2=tmp__.val[1]; } 64 # define VTRANSPOSE4(x0,x1,x2,x3) { \ 65 float32x4x2_t t0_ = vzipq_f32(x0, x2); \ 66 float32x4x2_t t1_ = vzipq_f32(x1, x3); \ 67 float32x4x2_t u0_ = vzipq_f32(t0_.val[0], t1_.val[0]); \ 68 float32x4x2_t u1_ = vzipq_f32(t0_.val[1], t1_.val[1]); \ 69 x0 = u0_.val[0]; x1 = u0_.val[1]; x2 = u1_.val[0]; x3 = u1_.val[1]; \ 70 } 71 // marginally faster version 72 //# define VTRANSPOSE4(x0,x1,x2,x3) { asm("vtrn.32 %q0, %q1;\n vtrn.32 %q2,%q3\n vswp %f0,%e2\n vswp %f1,%e3" : "+w"(x0), "+w"(x1), "+w"(x2), "+w"(x3)::); } 73 # define VSWAPHL(a,b) vcombine_f32(vget_low_f32(b), vget_high_f32(a)) 74 75 /* reverse/flip all floats */ 76 # define VREV_S(a) vcombine_f32(vrev64_f32(vget_high_f32(a)), vrev64_f32(vget_low_f32(a))) 77 /* reverse/flip complex floats */ 78 # define VREV_C(a) vextq_f32(a, a, 2) 79 80 # define VALIGNED(ptr) ((((uintptr_t)(ptr)) & 0x3) == 0) 81 82 #else 83 /* #pragma message( __FILE__ ": ARM NEON macros are not defined" ) */ 84 #endif 85 86 #endif /* PF_NEON_FLT_H */ 87 88