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)
71 float32x2_t a_lo, a_hi;
74 v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0));
76 v2 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 1), vdup_lane_f32(vget_high_f32(a.v), 1));
78 v1 = vmulq_f32(v1, b.v);
80 v2 = vmulq_f32(v2, b.v);
82 v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR));
84 a_lo = vrev64_f32(vget_low_f32(v2));
85 a_hi = vrev64_f32(vget_high_f32(v2));
86 v2 = vcombine_f32(a_lo, a_hi);
88 return Packet2cf(vaddq_f32(v1, v2));
91 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
93 return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
95 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
97 return Packet2cf(vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
99 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
101 return Packet2cf(vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
103 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
105 return Packet2cf(vreinterpretq_f32_u32(vbicq_u32(vreinterpretq_u32_f32(a.v),vreinterpretq_u32_f32(b.v))));
108 template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet2cf(pload<Packet4f>((
const float*)from)); }
109 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet2cf(ploadu<Packet4f>((
const float*)from)); }
111 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
return pset1<Packet2cf>(*from); }
113 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); }
114 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); }
116 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float> * addr) { __pld((
float *)addr); }
118 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a)
120 std::complex<float> EIGEN_ALIGN16 x[2];
121 vst1q_f32((
float *)x, a.v);
125 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
127 float32x2_t a_lo, a_hi;
130 a_lo = vget_low_f32(a.v);
131 a_hi = vget_high_f32(a.v);
132 a_r128 = vcombine_f32(a_hi, a_lo);
134 return Packet2cf(a_r128);
137 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& a)
139 return Packet2cf(vrev64q_f32(a.v));
142 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
145 std::complex<float> s;
147 a1 = vget_low_f32(a.v);
148 a2 = vget_high_f32(a.v);
149 a2 = vadd_f32(a1, a2);
150 vst1_f32((
float *)&s, a2);
155 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(
const Packet2cf* vecs)
157 Packet4f sum1, sum2, sum;
160 sum1 = vcombine_f32(vget_low_f32(vecs[0].v), vget_low_f32(vecs[1].v));
161 sum2 = vcombine_f32(vget_high_f32(vecs[0].v), vget_high_f32(vecs[1].v));
162 sum = vaddq_f32(sum1, sum2);
164 return Packet2cf(sum);
167 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
169 float32x2_t a1, a2, v1, v2, prod;
170 std::complex<float> s;
172 a1 = vget_low_f32(a.v);
173 a2 = vget_high_f32(a.v);
175 v1 = vdup_lane_f32(a1, 0);
177 v2 = vdup_lane_f32(a1, 1);
179 v1 = vmul_f32(v1, a2);
181 v2 = vmul_f32(v2, a2);
183 v2 = vreinterpret_f32_u32(veor_u32(vreinterpret_u32_f32(v2), p2ui_CONJ_XOR));
187 prod = vadd_f32(v1, v2);
189 vst1_f32((
float *)&s, prod);
195 struct palign_impl<Offset,Packet2cf>
197 EIGEN_STRONG_INLINE
static void run(Packet2cf& first,
const Packet2cf& second)
201 first.v = vextq_f32(first.v, second.v, 2);
206 template<>
struct conj_helper<Packet2cf, Packet2cf, false,true>
208 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const
209 {
return padd(pmul(x,y),c); }
211 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const
213 return internal::pmul(a, pconj(b));
217 template<>
struct conj_helper<Packet2cf, Packet2cf, true,false>
219 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const
220 {
return padd(pmul(x,y),c); }
222 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const
224 return internal::pmul(pconj(a), b);
228 template<>
struct conj_helper<Packet2cf, Packet2cf, true,true>
230 EIGEN_STRONG_INLINE Packet2cf pmadd(
const Packet2cf& x,
const Packet2cf& y,
const Packet2cf& c)
const
231 {
return padd(pmul(x,y),c); }
233 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b)
const
235 return pconj(internal::pmul(a, b));
239 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
242 Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
244 float32x2_t a_lo, a_hi;
247 s = vmulq_f32(b.v, b.v);
248 a_lo = vrev64_f32(vget_low_f32(s));
249 a_hi = vrev64_f32(vget_high_f32(s));
250 rev_s = vcombine_f32(a_lo, a_hi);
252 return Packet2cf(pdiv(res.v, vaddq_f32(s,rev_s)));
259 #endif // EIGEN_COMPLEX_NEON_H