10 #ifndef EIGEN_COMPLEX_NEON_H
11 #define EIGEN_COMPLEX_NEON_H
17 static uint32x4_t p4ui_CONJ_XOR = EIGEN_INIT_NEON_PACKET4(0x00000000, 0x80000000, 0x00000000, 0x80000000);
18 static uint32x2_t p2ui_CONJ_XOR = EIGEN_INIT_NEON_PACKET2(0x00000000, 0x80000000);
23 EIGEN_STRONG_INLINE Packet2cf() {}
24 EIGEN_STRONG_INLINE
explicit Packet2cf(
const Packet4f& a) : v(a) {}
28 template<>
struct packet_traits<std::complex<float> > : default_packet_traits
30 typedef Packet2cf type;
49 template<>
struct unpacket_traits<Packet2cf> {
typedef std::complex<float> type;
enum {size=2}; };
51 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
54 r64 = vld1_f32((
float *)&from);
56 return Packet2cf(vcombine_f32(r64, r64));
59 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(padd<Packet4f>(a.v,b.v)); }
60 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(psub<Packet4f>(a.v,b.v)); }
61 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a) {
return Packet2cf(pnegate<Packet4f>(a.v)); }
62 template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a)
64 Packet4ui b = vreinterpretq_u32_f32(a.v);
65 return Packet2cf(vreinterpretq_f32_u32(veorq_u32(b, p4ui_CONJ_XOR)));
68 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
73 v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0));
75 v2 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 1), vdup_lane_f32(vget_high_f32(a.v), 1));
77 v1 = vmulq_f32(v1, b.v);
79 v2 = vmulq_f32(v2, b.v);
81 v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR));
85 return Packet2cf(vaddq_f32(v1, v2));
88 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
90 return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
92 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
94 return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
96 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
98 return Packet2cf(vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
100 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
102 return Packet2cf(vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
105 template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet2cf(pload<Packet4f>((
const float*)from)); }
106 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet2cf(ploadu<Packet4f>((
const float*)from)); }
108 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
return pset1<Packet2cf>(*from); }
110 template<> EIGEN_STRONG_INLINE
void pstore <std::complex<float> >(std::complex<float> * to,
const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((
float*)to, from.v); }
111 template<> EIGEN_STRONG_INLINE
void pstoreu<std::complex<float> >(std::complex<float> * to,
const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((
float*)to, from.v); }
113 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float> * addr) { EIGEN_ARM_PREFETCH((
float *)addr); }
115 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a)
117 std::complex<float> EIGEN_ALIGN16 x[2];
118 vst1q_f32((
float *)x, a.v);
122 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
124 float32x2_t a_lo, a_hi;
127 a_lo = vget_low_f32(a.v);
128 a_hi = vget_high_f32(a.v);
129 a_r128 = vcombine_f32(a_hi, a_lo);
131 return Packet2cf(a_r128);
134 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& a)
136 return Packet2cf(vrev64q_f32(a.v));
139 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
142 std::complex<float> s;
144 a1 = vget_low_f32(a.v);
145 a2 = vget_high_f32(a.v);
146 a2 = vadd_f32(a1, a2);
147 vst1_f32((
float *)&s, a2);
152 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(
const Packet2cf* vecs)
154 Packet4f sum1, sum2, sum;
157 sum1 = vcombine_f32(vget_low_f32(vecs[0].v), vget_low_f32(vecs[1].v));
158 sum2 = vcombine_f32(vget_high_f32(vecs[0].v), vget_high_f32(vecs[1].v));
159 sum = vaddq_f32(sum1, sum2);
161 return Packet2cf(sum);
164 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
166 float32x2_t a1, a2, v1, v2, prod;
167 std::complex<float> s;
169 a1 = vget_low_f32(a.v);
170 a2 = vget_high_f32(a.v);
172 v1 = vdup_lane_f32(a1, 0);
174 v2 = vdup_lane_f32(a1, 1);
176 v1 = vmul_f32(v1, a2);
178 v2 = vmul_f32(v2, a2);
180 v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR));
184 prod = vadd_f32(v1, v2);
186 vst1_f32((
float *)&s, prod);
192 struct palign_impl<Offset,Packet2cf>
194 EIGEN_STRONG_INLINE
static void run(Packet2cf& first,
const Packet2cf& second)
198 first.v = vextq_f32(first.v, second.v, 2);
203 template<>
struct conj_helper<Packet2cf, Packet2cf, false,true>
205 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const
206 {
return padd(pmul(x,y),c); }
208 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const
210 return internal::pmul(a, pconj(b));
214 template<>
struct conj_helper<Packet2cf, Packet2cf, true,false>
216 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const
217 {
return padd(pmul(x,y),c); }
219 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const
221 return internal::pmul(pconj(a), b);
225 template<>
struct conj_helper<Packet2cf, Packet2cf, true,true>
227 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const
228 {
return padd(pmul(x,y),c); }
230 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const
232 return pconj(internal::pmul(a, b));
236 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
239 Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
243 s = vmulq_f32(b.v, b.v);
244 rev_s = vrev64q_f32(s);
246 return Packet2cf(pdiv(res.v, vaddq_f32(s,rev_s)));
253 #endif // EIGEN_COMPLEX_NEON_H