11#ifndef EIGEN_COMPLEX32_ALTIVEC_H
12#define EIGEN_COMPLEX32_ALTIVEC_H
18#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ >= 12)
19inline Packet4ui p4ui_CONJ_XOR() {
20 return { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
24static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_ZERO_, (Packet4ui) p2l_ZERO, 8);
25static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_ZERO_, 8);
29 EIGEN_STRONG_INLINE Packet1cd() {}
30 EIGEN_STRONG_INLINE
explicit Packet1cd(
const Packet2d& a) : v(a) {}
36 EIGEN_STRONG_INLINE Packet2cf() {}
37 EIGEN_STRONG_INLINE
explicit Packet2cf(
const Packet4f& a) : v(a) {}
38#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
48template<>
struct packet_traits<
std::complex<float> > : default_packet_traits
50 typedef Packet2cf type;
51 typedef Packet2cf half;
73template<>
struct packet_traits<
std::complex<double> > : default_packet_traits
75 typedef Packet1cd type;
76 typedef Packet1cd half;
96template<>
struct unpacket_traits<Packet2cf> {
97 typedef std::complex<float> type;
98 enum {size=2, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
99 typedef Packet2cf half;
100 typedef Packet4f as_real;
102template<>
struct unpacket_traits<Packet1cd> {
103 typedef std::complex<double> type;
104 enum {size=1, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
105 typedef Packet1cd half;
106 typedef Packet2d as_real;
110EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel);
113template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(
const std::complex<double>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet1cd(pload<Packet2d>((
const double*)from)); }
114template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(
const std::complex<double>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet1cd(ploadu<Packet2d>((
const double*)from)); }
115template<> EIGEN_STRONG_INLINE
void pstore <std::complex<double> >(std::complex<double> * to,
const Packet1cd& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((
double*)to, from.v); }
116template<> EIGEN_STRONG_INLINE
void pstoreu<std::complex<double> >(std::complex<double> * to,
const Packet1cd& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((
double*)to, from.v); }
118template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(
const std::complex<double>& from)
119{
return ploadu<Packet1cd>(&from); }
121template<> EIGEN_DEVICE_FUNC
inline Packet1cd pgather<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index stride EIGEN_UNUSED)
123 return pload<Packet1cd>(from);
125template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to,
const Packet1cd& from,
Index stride EIGEN_UNUSED)
127 pstore<std::complex<double> >(to, from);
129template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(a.v + b.v); }
130template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(a.v - b.v); }
131template<> EIGEN_STRONG_INLINE Packet1cd pnegate(
const Packet1cd& a) {
return Packet1cd(pnegate(Packet2d(a.v))); }
132template<> EIGEN_STRONG_INLINE Packet1cd pconj(
const Packet1cd& a) {
return Packet1cd((Packet2d)vec_xor((Packet2d)a.v, (Packet2d)p2ul_CONJ_XOR2)); }
133template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
135 Packet2d a_re, a_im, v1, v2;
138 a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
140 a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
142 v1 = vec_madd(a_re, b.v, p2d_ZERO);
144 v2 = vec_madd(a_im, b.v, p2d_ZERO);
145 v2 = (Packet2d) vec_sld((Packet4ui)v2, (Packet4ui)v2, 8);
146 v2 = (Packet2d) vec_xor((Packet2d)v2, (Packet2d) p2ul_CONJ_XOR1);
148 return Packet1cd(v1 + v2);
150template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_and(a.v,b.v)); }
151template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_or(a.v,b.v)); }
152template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_xor(a.v,b.v)); }
153template<> EIGEN_STRONG_INLINE Packet1cd pandnot <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_and(a.v, vec_nor(b.v,b.v))); }
154template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(
const std::complex<double>* from) {
return pset1<Packet1cd>(*from); }
155template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(
const Packet1cd& a,
const Packet1cd& b) {
156 Packet2d eq = vec_cmpeq (a.v, b.v);
157 Packet2d tmp = { eq[1], eq[0] };
158 return (Packet1cd)pand<Packet2d>(eq, tmp);
161template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<double> >(
const std::complex<double> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
163template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(
const Packet1cd& a)
165 EIGEN_ALIGN16 std::complex<double> res;
166 pstore<std::complex<double> >(&res, a);
171template<> EIGEN_STRONG_INLINE Packet1cd preverse(
const Packet1cd& a) {
return a; }
172template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(
const Packet1cd& a)
176template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(
const Packet1cd& a)
180EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
182template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
184 return pdiv_complex(a, b);
187EIGEN_STRONG_INLINE Packet1cd pcplxflip(
const Packet1cd& x)
189 return Packet1cd(preverse(Packet2d(x.v)));
192EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet1cd,2>& kernel)
194 Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
195 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
196 kernel.packet[0].v = tmp;
200template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet2cf(pload<Packet4f>((
const float*)from)); }
201template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet2cf(ploadu<Packet4f>((
const float*)from)); }
202template<> EIGEN_STRONG_INLINE
void pstore <std::complex<float> >(std::complex<float> * to,
const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore((
float*)to, from.v); }
203template<> EIGEN_STRONG_INLINE
void pstoreu<std::complex<float> >(std::complex<float> * to,
const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((
float*)to, from.v); }
205template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a)
207 EIGEN_ALIGN16 std::complex<float> res[2];
208 pstore<std::complex<float> >(res, a);
214#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
215template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
218 res.cd[0] = Packet1cd(vec_ld2f((
const float *)&from));
219 res.cd[1] = res.cd[0];
223template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
226 if((std::ptrdiff_t(&from) % 16) == 0)
227 res.v = pload<Packet4f>((
const float *)&from);
229 res.v = ploadu<Packet4f>((
const float *)&from);
230 res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
235template<> EIGEN_DEVICE_FUNC
inline Packet2cf pgather<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
Index stride)
237 EIGEN_ALIGN16 std::complex<float> af[2];
238 af[0] = from[0*stride];
239 af[1] = from[1*stride];
240 return pload<Packet2cf>(af);
242template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
const Packet2cf& from,
Index stride)
244 EIGEN_ALIGN16 std::complex<float> af[2];
245 pstore<std::complex<float> >((std::complex<float> *) af, from);
246 to[0*stride] = af[0];
247 to[1*stride] = af[1];
250template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(padd<Packet4f>(a.v, b.v)); }
251template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(psub<Packet4f>(a.v, b.v)); }
252template<> EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a) {
return Packet2cf(pnegate(Packet4f(a.v))); }
254template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pand<Packet4f>(a.v,b.v)); }
255template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(por<Packet4f>(a.v,b.v)); }
256template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pxor<Packet4f>(a.v,b.v)); }
257template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pandnot<Packet4f>(a.v,b.v)); }
259template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
return pset1<Packet2cf>(*from); }
261template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
264#if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12)
266template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
267 Packet4f eq = pcmp_eq<Packet4f> (a.v, b.v);
269 Packet2d tmp1 = { eq.v4f[0][1], eq.v4f[0][0] };
270 Packet2d tmp2 = { eq.v4f[1][1], eq.v4f[1][0] };
271 res.v.v4f[0] = pand<Packet2d>(eq.v4f[0], tmp1);
272 res.v.v4f[1] = pand<Packet2d>(eq.v4f[1], tmp2);
276template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a)
279 res.v.v4f[0] = pconj(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[0]))).v;
280 res.v.v4f[1] = pconj(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[1]))).v;
284template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
287 res.v.v4f[0] = pmul(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[0])), Packet1cd(
reinterpret_cast<Packet2d
>(b.v.v4f[0]))).v;
288 res.v.v4f[1] = pmul(Packet1cd(
reinterpret_cast<Packet2d
>(a.v.v4f[1])), Packet1cd(
reinterpret_cast<Packet2d
>(b.v.v4f[1]))).v;
292template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
300template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
302 std::complex<float> res;
303 Packet1cd b = padd<Packet1cd>(a.cd[0], a.cd[1]);
304 vec_st2f(b.v, (
float*)&res);
308template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
310 std::complex<float> res;
311 Packet1cd b = pmul<Packet1cd>(a.cd[0], a.cd[1]);
312 vec_st2f(b.v, (
float*)&res);
316EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
318template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
320 return pdiv_complex(a, b);
323EIGEN_STRONG_INLINE Packet2cf pcplxflip(
const Packet2cf& x)
326 res.cd[0] = pcplxflip(x.cd[0]);
327 res.cd[1] = pcplxflip(x.cd[1]);
331EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel)
333 Packet1cd tmp = kernel.packet[0].cd[1];
334 kernel.packet[0].cd[1] = kernel.packet[1].cd[0];
335 kernel.packet[1].cd[0] = tmp;
338template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
341 result.v = pblend<Packet4f>(ifPacket4, thenPacket.v, elsePacket.v);
345template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
346 Packet4f eq = vec_cmpeq (a.v, b.v);
347 Packet4f tmp = { eq[1], eq[0], eq[3], eq[2] };
348 return (Packet2cf)pand<Packet4f>(eq, tmp);
350template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a) {
return Packet2cf(pxor<Packet4f>(a.v,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR()))); }
351template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
353 Packet4f a_re, a_im, prod, prod_im;
356 a_re = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
359 a_im = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
362 prod_im = a_im * b.v;
363 prod_im = pxor<Packet4f>(prod_im,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR()));
365 prod_im = vec_perm(prod_im, prod_im, p16uc_COMPLEX32_REV);
368 prod = pmadd<Packet4f>(a_re, b.v, prod_im);
370 return Packet2cf(prod);
373template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
376 rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2);
377 return Packet2cf(rev_a);
380template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
383 b = vec_sld(a.v, a.v, 8);
384 b = padd<Packet4f>(a.v, b);
385 return pfirst<Packet2cf>(Packet2cf(b));
388template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
392 b = vec_sld(a.v, a.v, 8);
393 prod = pmul<Packet2cf>(a, Packet2cf(b));
395 return pfirst<Packet2cf>(prod);
398EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
400template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
402 return pdiv_complex(a, b);
405template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& x)
407 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
410EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel)
412 Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
413 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
414 kernel.packet[0].v = tmp;
417template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
419 result.v =
reinterpret_cast<Packet4f
>(pblend<Packet2d>(ifPacket,
reinterpret_cast<Packet2d
>(thenPacket.v),
reinterpret_cast<Packet2d
>(elsePacket.v)));
EIGEN_DEVICE_FUNC const Select< Derived, ThenDerived, ElseDerived > select(const DenseBase< ThenDerived > &thenMatrix, const DenseBase< ElseDerived > &elseMatrix) const
Definition Select.h:126
@ Aligned16
Data pointer is aligned on a 16 bytes boundary.
Definition Constants.h:235
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74