11 #ifndef EIGEN_COMPLEX32_ALTIVEC_H
12 #define EIGEN_COMPLEX32_ALTIVEC_H
18 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
19 static Packet4ui p4ui_CONJ_XOR = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
22 static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_ZERO_, (Packet4ui) p2l_ZERO, 8);
23 static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_ZERO_, 8);
27 EIGEN_STRONG_INLINE Packet1cd() {}
28 EIGEN_STRONG_INLINE
explicit Packet1cd(
const Packet2d& a) : v(a) {}
34 EIGEN_STRONG_INLINE Packet2cf() {}
35 EIGEN_STRONG_INLINE
explicit Packet2cf(
const Packet4f& a) : v(a) {}
36 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
46 template<>
struct packet_traits<std::complex<float> > : default_packet_traits
48 typedef Packet2cf type;
49 typedef Packet2cf half;
71 template<>
struct packet_traits<std::complex<double> > : default_packet_traits
73 typedef Packet1cd type;
74 typedef Packet1cd half;
94 template<>
struct unpacket_traits<Packet2cf> {
95 typedef std::complex<float> type;
96 enum {size=2, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
97 typedef Packet2cf half;
98 typedef Packet4f as_real;
100 template<>
struct unpacket_traits<Packet1cd> {
101 typedef std::complex<double> type;
102 enum {size=1, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
103 typedef Packet1cd half;
104 typedef Packet2d as_real;
108 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel);
111 template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(
const std::complex<double>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet1cd(pload<Packet2d>((
const double*)from)); }
112 template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(
const std::complex<double>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet1cd(ploadu<Packet2d>((
const double*)from)); }
113 template<> EIGEN_STRONG_INLINE
void pstore <std::complex<double> >(std::complex<double> * to,
const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((
double*)to, from.v); }
114 template<> EIGEN_STRONG_INLINE
void pstoreu<std::complex<double> >(std::complex<double> * to,
const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((
double*)to, from.v); }
116 template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(
const std::complex<double>& from)
117 {
return ploadu<Packet1cd>(&from); }
119 template<> EIGEN_DEVICE_FUNC
inline Packet1cd pgather<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index stride EIGEN_UNUSED)
121 return pload<Packet1cd>(from);
123 template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to,
const Packet1cd& from,
Index stride EIGEN_UNUSED)
125 pstore<std::complex<double> >(to, from);
127 template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(a.v + b.v); }
128 template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(a.v - b.v); }
129 template<> EIGEN_STRONG_INLINE Packet1cd pnegate(
const Packet1cd& a) {
return Packet1cd(pnegate(Packet2d(a.v))); }
130 template<> EIGEN_STRONG_INLINE Packet1cd pconj(
const Packet1cd& a) {
return Packet1cd((Packet2d)vec_xor((Packet2d)a.v, (Packet2d)p2ul_CONJ_XOR2)); }
131 template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
133 Packet2d a_re, a_im, v1, v2;
136 a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
138 a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
140 v1 = vec_madd(a_re, b.v, p2d_ZERO);
142 v2 = vec_madd(a_im, b.v, p2d_ZERO);
143 v2 = (Packet2d) vec_sld((Packet4ui)v2, (Packet4ui)v2, 8);
144 v2 = (Packet2d) vec_xor((Packet2d)v2, (Packet2d) p2ul_CONJ_XOR1);
146 return Packet1cd(v1 + v2);
148 template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_and(a.v,b.v)); }
149 template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_or(a.v,b.v)); }
150 template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_xor(a.v,b.v)); }
151 template<> EIGEN_STRONG_INLINE Packet1cd pandnot <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_and(a.v, vec_nor(b.v,b.v))); }
152 template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(
const std::complex<double>* from) {
return pset1<Packet1cd>(*from); }
153 template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(
const Packet1cd& a,
const Packet1cd& b) {
154 Packet2d eq = vec_cmpeq (a.v, b.v);
155 Packet2d tmp = { eq[1], eq[0] };
156 return (Packet1cd)pand<Packet2d>(eq, tmp);
159 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<double> >(
const std::complex<double> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
161 template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(
const Packet1cd& a)
163 EIGEN_ALIGN16 std::complex<double> res;
164 pstore<std::complex<double> >(&res, a);
169 template<> EIGEN_STRONG_INLINE Packet1cd preverse(
const Packet1cd& a) {
return a; }
170 template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(
const Packet1cd& a)
174 template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(
const Packet1cd& a)
178 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
180 template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
183 Packet1cd res = pmul(a,pconj(b));
184 Packet2d s = vec_madd(b.v, b.v, p2d_ZERO_);
185 return Packet1cd(pdiv(res.v, s + vec_perm(s, s, p16uc_REVERSE64)));
188 EIGEN_STRONG_INLINE Packet1cd pcplxflip(
const Packet1cd& x)
190 return Packet1cd(preverse(Packet2d(x.v)));
193 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet1cd,2>& kernel)
195 Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
196 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
197 kernel.packet[0].v = tmp;
201 template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet2cf(pload<Packet4f>((
const float*)from)); }
202 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet2cf(ploadu<Packet4f>((
const float*)from)); }
203 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); }
204 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); }
206 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a)
208 EIGEN_ALIGN16 std::complex<float> res[2];
209 pstore<std::complex<float> >(res, a);
215 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
216 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
219 res.cd[0] = Packet1cd(vec_ld2f((
const float *)&from));
220 res.cd[1] = res.cd[0];
224 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
227 if((std::ptrdiff_t(&from) % 16) == 0)
228 res.v = pload<Packet4f>((
const float *)&from);
230 res.v = ploadu<Packet4f>((
const float *)&from);
231 res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
236 template<> EIGEN_DEVICE_FUNC
inline Packet2cf pgather<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
Index stride)
238 EIGEN_ALIGN16 std::complex<float> af[2];
239 af[0] = from[0*stride];
240 af[1] = from[1*stride];
241 return pload<Packet2cf>(af);
243 template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
const Packet2cf& from,
Index stride)
245 EIGEN_ALIGN16 std::complex<float> af[2];
246 pstore<std::complex<float> >((std::complex<float> *) af, from);
247 to[0*stride] = af[0];
248 to[1*stride] = af[1];
251 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(padd<Packet4f>(a.v, b.v)); }
252 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(psub<Packet4f>(a.v, b.v)); }
253 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a) {
return Packet2cf(pnegate(Packet4f(a.v))); }
255 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pand<Packet4f>(a.v,b.v)); }
256 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(por<Packet4f>(a.v,b.v)); }
257 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pxor<Packet4f>(a.v,b.v)); }
258 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pandnot<Packet4f>(a.v,b.v)); }
260 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
return pset1<Packet2cf>(*from); }
262 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
265 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
267 template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
268 Packet4f eq = pcmp_eq<Packet4f> (a.v, b.v);
270 Packet2d tmp1 = { eq.v4f[0][1], eq.v4f[0][0] };
271 Packet2d tmp2 = { eq.v4f[1][1], eq.v4f[1][0] };
272 res.v.v4f[0] = pand<Packet2d>(eq.v4f[0], tmp1);
273 res.v.v4f[1] = pand<Packet2d>(eq.v4f[1], tmp2);
277 template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a)
280 res.v.v4f[0] = pconj(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[0]))).v;
281 res.v.v4f[1] = pconj(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[1]))).v;
285 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
288 res.v.v4f[0] = pmul(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[0])), Packet1cd(
reinterpret_cast<Packet2d
>(b.v.v4f[0]))).v;
289 res.v.v4f[1] = pmul(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[1])), Packet1cd(
reinterpret_cast<Packet2d
>(b.v.v4f[1]))).v;
293 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
301 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
303 std::complex<float> res;
304 Packet1cd b = padd<Packet1cd>(a.cd[0], a.cd[1]);
305 vec_st2f(b.v, (
float*)&res);
309 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
311 std::complex<float> res;
312 Packet1cd b = pmul<Packet1cd>(a.cd[0], a.cd[1]);
313 vec_st2f(b.v, (
float*)&res);
317 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
319 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
323 res.cd[0] = pdiv<Packet1cd>(a.cd[0], b.cd[0]);
324 res.cd[1] = pdiv<Packet1cd>(a.cd[1], b.cd[1]);
328 EIGEN_STRONG_INLINE Packet2cf pcplxflip(
const Packet2cf& x)
331 res.cd[0] = pcplxflip(x.cd[0]);
332 res.cd[1] = pcplxflip(x.cd[1]);
336 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel)
338 Packet1cd tmp = kernel.packet[0].cd[1];
339 kernel.packet[0].cd[1] = kernel.packet[1].cd[0];
340 kernel.packet[1].cd[0] = tmp;
343 template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
345 const Selector<4> ifPacket4 = { ifPacket.select[0], ifPacket.select[0], ifPacket.select[1], ifPacket.select[1] };
346 result.v = pblend<Packet4f>(ifPacket4, thenPacket.v, elsePacket.v);
350 template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
351 Packet4f eq = vec_cmpeq (a.v, b.v);
352 Packet4f tmp = { eq[1], eq[0], eq[3], eq[2] };
353 return (Packet2cf)pand<Packet4f>(eq, tmp);
355 template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a) {
return Packet2cf(pxor<Packet4f>(a.v,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR))); }
356 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
358 Packet4f a_re, a_im, prod, prod_im;
361 a_re = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
364 a_im = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
367 prod_im = a_im * b.v;
368 prod_im = pxor<Packet4f>(prod_im,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR));
370 prod_im = vec_perm(prod_im, prod_im, p16uc_COMPLEX32_REV);
373 prod = pmadd<Packet4f>(a_re, b.v, prod_im);
375 return Packet2cf(prod);
378 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
381 rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2);
382 return Packet2cf(rev_a);
385 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
388 b = vec_sld(a.v, a.v, 8);
389 b = padd<Packet4f>(a.v, b);
390 return pfirst<Packet2cf>(Packet2cf(b));
393 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
397 b = vec_sld(a.v, a.v, 8);
398 prod = pmul<Packet2cf>(a, Packet2cf(b));
400 return pfirst<Packet2cf>(prod);
403 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
405 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
408 Packet2cf res = pmul(a, pconj(b));
409 Packet4f s = pmul<Packet4f>(b.v, b.v);
410 return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV))));
413 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& x)
415 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
418 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel)
420 Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
421 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
422 kernel.packet[0].v = tmp;
425 template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
427 result.v =
reinterpret_cast<Packet4f
>(pblend<Packet2d>(ifPacket,
reinterpret_cast<Packet2d
>(thenPacket.v),
reinterpret_cast<Packet2d
>(elsePacket.v)));
@ Aligned16
Definition: Constants.h:235
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74