/* ARM NEON acceleration Copyright 2018 Ahmet Inan */ #ifndef NEON_HH #define NEON_HH #include #include #include "simd.h" namespace ldpctool { template <> union SIMD { static const int SIZE = 4; typedef float value_type; typedef uint32_t uint_type; float32x4_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 16; typedef int8_t value_type; typedef uint8_t uint_type; int8x16_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 8; typedef int16_t value_type; typedef uint16_t uint_type; int16x8_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 4; typedef int32_t value_type; typedef uint32_t uint_type; int32x4_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 2; typedef int64_t value_type; typedef uint64_t uint_type; int64x2_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 16; typedef uint8_t value_type; typedef uint8_t uint_type; uint8x16_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 8; typedef uint16_t value_type; typedef uint16_t uint_type; uint16x8_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 4; typedef uint32_t value_type; typedef uint32_t uint_type; uint32x4_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> union SIMD { static const int SIZE = 2; typedef uint64_t value_type; typedef uint64_t uint_type; uint64x2_t m; value_type v[SIZE]; uint_type u[SIZE]; }; template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (float32x4_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (uint32x4_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (int8x16_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (uint8x16_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (int16x8_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (uint16x8_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (int32x4_t)a.m; return tmp; } template <> inline SIMD vreinterpret(SIMD a) { SIMD tmp; tmp.m = (uint32x4_t)a.m; return tmp; } template <> inline SIMD vdup(float a) { SIMD tmp; tmp.m = vdupq_n_f32(a); return tmp; } template <> inline SIMD vdup(int8_t a) { SIMD tmp; tmp.m = vdupq_n_s8(a); return tmp; } template <> inline SIMD vdup(int16_t a) { SIMD tmp; tmp.m = vdupq_n_s16(a); return tmp; } template <> inline SIMD vdup(int32_t a) { SIMD tmp; tmp.m = vdupq_n_s32(a); return tmp; } template <> inline SIMD vdup(int64_t a) { SIMD tmp; tmp.m = vdupq_n_s64(a); return tmp; } template <> inline SIMD vdup(uint8_t a) { SIMD tmp; tmp.m = vdupq_n_u8(a); return tmp; } template <> inline SIMD vdup(uint16_t a) { SIMD tmp; tmp.m = vdupq_n_u16(a); return tmp; } template <> inline SIMD vdup(uint32_t a) { SIMD tmp; tmp.m = vdupq_n_u32(a); return tmp; } template <> inline SIMD vdup(uint64_t a) { SIMD tmp; tmp.m = vdupq_n_u64(a); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = (float32x4_t)veorq_u32((uint32x4_t)tmp.m, (uint32x4_t)tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_s8(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_s16(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_s32(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_s64(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_u8(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_u16(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_u32(tmp.m, tmp.m); return tmp; } template <> inline SIMD vzero() { SIMD tmp; tmp.m = veorq_u64(tmp.m, tmp.m); return tmp; } template <> inline SIMD vadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vaddq_f32(a.m, b.m); return tmp; } template <> inline SIMD vadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vaddq_s8(a.m, b.m); return tmp; } template <> inline SIMD vadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vaddq_s16(a.m, b.m); return tmp; } template <> inline SIMD vadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vaddq_s32(a.m, b.m); return tmp; } template <> inline SIMD vadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vaddq_s64(a.m, b.m); return tmp; } template <> inline SIMD vqadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vqaddq_s8(a.m, b.m); return tmp; } template <> inline SIMD vqadd(SIMD a, SIMD b) { SIMD tmp; tmp.m = vqaddq_s16(a.m, b.m); return tmp; } template <> inline SIMD vsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vsubq_f32(a.m, b.m); return tmp; } template <> inline SIMD vsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vsubq_s8(a.m, b.m); return tmp; } template <> inline SIMD vsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vsubq_s16(a.m, b.m); return tmp; } template <> inline SIMD vsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vsubq_s32(a.m, b.m); return tmp; } template <> inline SIMD vsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vsubq_s64(a.m, b.m); return tmp; } template <> inline SIMD vqsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vqsubq_s8(a.m, b.m); return tmp; } template <> inline SIMD vqsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vqsubq_s16(a.m, b.m); return tmp; } template <> inline SIMD vqsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vqsubq_u8(a.m, b.m); return tmp; } template <> inline SIMD vqsub(SIMD a, SIMD b) { SIMD tmp; tmp.m = vqsubq_u16(a.m, b.m); return tmp; } template <> inline SIMD vabs(SIMD a) { SIMD tmp; tmp.m = vabsq_f32(a.m); return tmp; } template <> inline SIMD vqabs(SIMD a) { SIMD tmp; tmp.m = vqabsq_s8(a.m); return tmp; } template <> inline SIMD vqabs(SIMD a) { SIMD tmp; tmp.m = vqabsq_s16(a.m); return tmp; } template <> inline SIMD vsign(SIMD a, SIMD b) { SIMD tmp; tmp.m = (float32x4_t)vbicq_u32( veorq_u32((uint32x4_t)a.m, vandq_u32((uint32x4_t)vdupq_n_f32(-0.f), (uint32x4_t)b.m)), vceqq_f32(b.m, vdupq_n_f32(0.f))); return tmp; } template <> inline SIMD vsign(SIMD a, SIMD b) { SIMD tmp; tmp.m = (int8x16_t)vorrq_u8( vandq_u8(vcgtq_s8(vdupq_n_s8(0), b.m), (uint8x16_t)vnegq_s8(a.m)), vandq_u8(vcgtq_s8(b.m, vdupq_n_s8(0)), (uint8x16_t)a.m)); return tmp; } template <> inline SIMD vorr(SIMD a, SIMD b) { SIMD tmp; tmp.m = vorrq_u8(a.m, b.m); return tmp; } template <> inline SIMD vorr(SIMD a, SIMD b) { SIMD tmp; tmp.m = vorrq_u16(a.m, b.m); return tmp; } template <> inline SIMD vorr(SIMD a, SIMD b) { SIMD tmp; tmp.m = vorrq_u32(a.m, b.m); return tmp; } template <> inline SIMD vorr(SIMD a, SIMD b) { SIMD tmp; tmp.m = vorrq_u64(a.m, b.m); return tmp; } template <> inline SIMD vand(SIMD a, SIMD b) { SIMD tmp; tmp.m = vandq_u8(a.m, b.m); return tmp; } template <> inline SIMD vand(SIMD a, SIMD b) { SIMD tmp; tmp.m = vandq_u16(a.m, b.m); return tmp; } template <> inline SIMD vand(SIMD a, SIMD b) { SIMD tmp; tmp.m = vandq_u32(a.m, b.m); return tmp; } template <> inline SIMD vand(SIMD a, SIMD b) { SIMD tmp; tmp.m = vandq_u64(a.m, b.m); return tmp; } template <> inline SIMD veor(SIMD a, SIMD b) { SIMD tmp; tmp.m = veorq_u8(a.m, b.m); return tmp; } template <> inline SIMD veor(SIMD a, SIMD b) { SIMD tmp; tmp.m = veorq_u16(a.m, b.m); return tmp; } template <> inline SIMD veor(SIMD a, SIMD b) { SIMD tmp; tmp.m = veorq_u32(a.m, b.m); return tmp; } template <> inline SIMD veor(SIMD a, SIMD b) { SIMD tmp; tmp.m = veorq_u64(a.m, b.m); return tmp; } template <> inline SIMD vbic(SIMD a, SIMD b) { SIMD tmp; tmp.m = vbicq_u8(a.m, b.m); return tmp; } template <> inline SIMD vbic(SIMD a, SIMD b) { SIMD tmp; tmp.m = vbicq_u16(a.m, b.m); return tmp; } template <> inline SIMD vbic(SIMD a, SIMD b) { SIMD tmp; tmp.m = vbicq_u32(a.m, b.m); return tmp; } template <> inline SIMD vbic(SIMD a, SIMD b) { SIMD tmp; tmp.m = vbicq_u64(a.m, b.m); return tmp; } template <> inline SIMD vbsl(SIMD a, SIMD b, SIMD c) { SIMD tmp; tmp.m = vbslq_u8(a.m, b.m, c.m); return tmp; } template <> inline SIMD vbsl(SIMD a, SIMD b, SIMD c) { SIMD tmp; tmp.m = vbslq_u16(a.m, b.m, c.m); return tmp; } template <> inline SIMD vbsl(SIMD a, SIMD b, SIMD c) { SIMD tmp; tmp.m = vbslq_u32(a.m, b.m, c.m); return tmp; } template <> inline SIMD vbsl(SIMD a, SIMD b, SIMD c) { SIMD tmp; tmp.m = vbslq_u64(a.m, b.m, c.m); return tmp; } template <> inline SIMD vceqz(SIMD a) { SIMD tmp; tmp.m = vceqq_f32(a.m, vdupq_n_f32(0.f)); return tmp; } template <> inline SIMD vceqz(SIMD a) { SIMD tmp; tmp.m = vceqq_s8(a.m, vdupq_n_s8(0)); return tmp; } template <> inline SIMD vceqz(SIMD a) { SIMD tmp; tmp.m = vceqq_s16(a.m, vdupq_n_s16(0)); return tmp; } template <> inline SIMD vceqz(SIMD a) { SIMD tmp; tmp.m = vceqq_s32(a.m, vdupq_n_s32(0)); return tmp; } template <> inline SIMD vceq(SIMD a, SIMD b) { SIMD tmp; tmp.m = vceqq_f32(a.m, b.m); return tmp; } template <> inline SIMD vceq(SIMD a, SIMD b) { SIMD tmp; tmp.m = vceqq_s8(a.m, b.m); return tmp; } template <> inline SIMD vceq(SIMD a, SIMD b) { SIMD tmp; tmp.m = vceqq_s16(a.m, b.m); return tmp; } template <> inline SIMD vceq(SIMD a, SIMD b) { SIMD tmp; tmp.m = vceqq_s32(a.m, b.m); return tmp; } template <> inline SIMD vcgtz(SIMD a) { SIMD tmp; tmp.m = vcgtq_f32(a.m, vdupq_n_f32(0.f)); return tmp; } template <> inline SIMD vcgtz(SIMD a) { SIMD tmp; tmp.m = vcgtq_s8(a.m, vdupq_n_s8(0)); return tmp; } template <> inline SIMD vcgtz(SIMD a) { SIMD tmp; tmp.m = vcgtq_s16(a.m, vdupq_n_s16(0)); return tmp; } template <> inline SIMD vcgtz(SIMD a) { SIMD tmp; tmp.m = vcgtq_s32(a.m, vdupq_n_s32(0)); return tmp; } template <> inline SIMD vcltz(SIMD a) { SIMD tmp; tmp.m = vcltq_f32(a.m, vdupq_n_f32(0.f)); return tmp; } template <> inline SIMD vcltz(SIMD a) { SIMD tmp; tmp.m = vcltq_s8(a.m, vdupq_n_s8(0)); return tmp; } template <> inline SIMD vcltz(SIMD a) { SIMD tmp; tmp.m = vcltq_s16(a.m, vdupq_n_s16(0)); return tmp; } template <> inline SIMD vcltz(SIMD a) { SIMD tmp; tmp.m = vcltq_s32(a.m, vdupq_n_s32(0)); return tmp; } template <> inline SIMD vmin(SIMD a, SIMD b) { SIMD tmp; tmp.m = vminq_f32(a.m, b.m); return tmp; } template <> inline SIMD vmin(SIMD a, SIMD b) { SIMD tmp; tmp.m = vminq_s8(a.m, b.m); return tmp; } template <> inline SIMD vmin(SIMD a, SIMD b) { SIMD tmp; tmp.m = vminq_s16(a.m, b.m); return tmp; } template <> inline SIMD vmin(SIMD a, SIMD b) { SIMD tmp; tmp.m = vminq_s32(a.m, b.m); return tmp; } template <> inline SIMD vmax(SIMD a, SIMD b) { SIMD tmp; tmp.m = vmaxq_f32(a.m, b.m); return tmp; } template <> inline SIMD vmax(SIMD a, SIMD b) { SIMD tmp; tmp.m = vmaxq_s8(a.m, b.m); return tmp; } template <> inline SIMD vmax(SIMD a, SIMD b) { SIMD tmp; tmp.m = vmaxq_s16(a.m, b.m); return tmp; } template <> inline SIMD vmax(SIMD a, SIMD b) { SIMD tmp; tmp.m = vmaxq_s32(a.m, b.m); return tmp; } } // namespace ldpctool #endif