11#ifndef EIGEN_COMPLEX32_ALTIVEC_H
12#define EIGEN_COMPLEX32_ALTIVEC_H
15#include "../../InternalHeaderCheck.h"
21static Packet4ui p4ui_CONJ_XOR =
22 vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO);
23#ifdef EIGEN_VECTORIZE_VSX
24#if defined(_BIG_ENDIAN)
25static Packet2ul p2ul_CONJ_XOR1 =
26 (Packet2ul)vec_sld((Packet4ui)p2d_MZERO, (Packet4ui)p2l_ZERO, 8);
27static Packet2ul p2ul_CONJ_XOR2 =
28 (Packet2ul)vec_sld((Packet4ui)p2l_ZERO, (Packet4ui)p2d_MZERO, 8);
30static Packet2ul p2ul_CONJ_XOR1 =
31 (Packet2ul)vec_sld((Packet4ui)p2l_ZERO, (Packet4ui)p2d_MZERO, 8);
32static Packet2ul p2ul_CONJ_XOR2 =
33 (Packet2ul)vec_sld((Packet4ui)p2d_MZERO, (Packet4ui)p2l_ZERO, 8);
39 EIGEN_STRONG_INLINE
explicit Packet2cf() {}
40 EIGEN_STRONG_INLINE
explicit Packet2cf(
const Packet4f& a) : v(a) {}
42 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b) {
46 v1 = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
48 v2 = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
50 v1 = vec_madd(v1, b.v, p4f_ZERO);
52 v2 = vec_madd(v2, b.v, p4f_ZERO);
53 v2 =
reinterpret_cast<Packet4f
>(pxor(v2,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR)));
55 v2 = vec_perm(v2, v2, p16uc_COMPLEX32_REV);
57 return Packet2cf(padd<Packet4f>(v1, v2));
60 EIGEN_STRONG_INLINE Packet2cf& operator*=(
const Packet2cf& b) {
61 v = pmul(Packet2cf(*
this), b).v;
64 EIGEN_STRONG_INLINE Packet2cf operator*(
const Packet2cf& b)
const {
return Packet2cf(*
this) *= b; }
66 EIGEN_STRONG_INLINE Packet2cf& operator+=(
const Packet2cf& b) {
70 EIGEN_STRONG_INLINE Packet2cf operator+(
const Packet2cf& b)
const {
return Packet2cf(*
this) += b; }
71 EIGEN_STRONG_INLINE Packet2cf& operator-=(
const Packet2cf& b) {
75 EIGEN_STRONG_INLINE Packet2cf operator-(
const Packet2cf& b)
const {
return Packet2cf(*
this) -= b; }
76 EIGEN_STRONG_INLINE Packet2cf operator-(
void)
const {
return Packet2cf(-v); }
82struct packet_traits<std::complex<float> > : default_packet_traits {
83 typedef Packet2cf type;
84 typedef Packet2cf half;
85 typedef Packet4f as_real;
103#ifdef EIGEN_VECTORIZE_VSX
111struct unpacket_traits<Packet2cf> {
112 typedef std::complex<float> type;
117 masked_load_available =
false,
118 masked_store_available =
false
120 typedef Packet2cf half;
121 typedef Packet4f as_real;
125EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from) {
127#ifdef EIGEN_VECTORIZE_VSX
132 __asm__(
"lxvdsx %x0,%y1" :
"=wa"(res.v) :
"Z"(from));
134 if ((std::ptrdiff_t(&from) % 16) == 0)
135 res.v = pload<Packet4f>((
const float*)&from);
137 res.v = ploadu<Packet4f>((
const float*)&from);
138 res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
144EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(
const std::complex<float>* from) {
145 return Packet2cf(pload<Packet4f>((
const float*)from));
148EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) {
149 return Packet2cf(ploadu<Packet4f>((
const float*)from));
152EIGEN_ALWAYS_INLINE Packet2cf pload_partial<Packet2cf>(
const std::complex<float>* from,
const Index n,
153 const Index offset) {
154 return Packet2cf(pload_partial<Packet4f>((
const float*)from, n * 2, offset * 2));
157EIGEN_ALWAYS_INLINE Packet2cf ploadu_partial<Packet2cf>(
const std::complex<float>* from,
const Index n,
158 const Index offset) {
159 return Packet2cf(ploadu_partial<Packet4f>((
const float*)from, n * 2, offset * 2));
162EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
163 return pset1<Packet2cf>(*from);
167EIGEN_STRONG_INLINE
void pstore<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from) {
168 pstore((
float*)to, from.v);
171EIGEN_STRONG_INLINE
void pstoreu<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from) {
172 pstoreu((
float*)to, from.v);
175EIGEN_ALWAYS_INLINE
void pstore_partial<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from,
176 const Index n,
const Index offset) {
177 pstore_partial((
float*)to, from.v, n * 2, offset * 2);
180EIGEN_ALWAYS_INLINE
void pstoreu_partial<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from,
181 const Index n,
const Index offset) {
182 pstoreu_partial((
float*)to, from.v, n * 2, offset * 2);
185EIGEN_STRONG_INLINE Packet2cf pload2(
const std::complex<float>& from0,
const std::complex<float>& from1) {
187#ifdef EIGEN_VECTORIZE_VSX
189 __asm__(
"lxsdx %x0,%y1" :
"=wa"(res0) :
"Z"(from0));
190 __asm__(
"lxsdx %x0,%y1" :
"=wa"(res1) :
"Z"(from1));
192 __asm__(
"xxpermdi %x0, %x1, %x2, 0" :
"=wa"(res0) :
"wa"(res0),
"wa"(res1));
194 __asm__(
"xxpermdi %x0, %x2, %x1, 0" :
"=wa"(res0) :
"wa"(res0),
"wa"(res1));
197 *
reinterpret_cast<std::complex<float>*
>(&res0) = from0;
198 *
reinterpret_cast<std::complex<float>*
>(&res1) = from1;
199 res0 = vec_perm(res0, res1, p16uc_TRANSPOSE64_HI);
201 return Packet2cf(res0);
205EIGEN_ALWAYS_INLINE Packet2cf pload_ignore<Packet2cf>(
const std::complex<float>* from) {
207 res.v = pload_ignore<Packet4f>(
reinterpret_cast<const float*
>(from));
211template <
typename Scalar,
typename Packet>
212EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pgather_complex_size2(
const Scalar* from, Index stride,
214 eigen_internal_assert(n <= unpacket_traits<Packet>::size &&
"number of elements will gather past end of packet");
215 EIGEN_ALIGN16 Scalar af[2];
216 for (Index i = 0; i < n; i++) {
217 af[i] = from[i * stride];
219 return pload_ignore<Packet>(af);
222EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet2cf pgather<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
224 return pgather_complex_size2<std::complex<float>, Packet2cf>(from, stride);
227EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet2cf
228pgather_partial<std::complex<float>, Packet2cf>(
const std::complex<float>* from, Index stride,
const Index n) {
229 return pgather_complex_size2<std::complex<float>, Packet2cf>(from, stride, n);
231template <
typename Scalar,
typename Packet>
232EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter_complex_size2(Scalar* to,
const Packet& from, Index stride,
234 eigen_internal_assert(n <= unpacket_traits<Packet>::size &&
"number of elements will scatter past end of packet");
235 EIGEN_ALIGN16 Scalar af[2];
236 pstore<Scalar>((Scalar*)af, from);
237 for (Index i = 0; i < n; i++) {
238 to[i * stride] = af[i];
242EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
243 const Packet2cf& from,
245 pscatter_complex_size2<std::complex<float>, Packet2cf>(to, from, stride);
248EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter_partial<std::complex<float>, Packet2cf>(std::complex<float>* to,
249 const Packet2cf& from,
252 pscatter_complex_size2<std::complex<float>, Packet2cf>(to, from, stride, n);
256EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
257 return Packet2cf(a.v + b.v);
260EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
261 return Packet2cf(a.v - b.v);
264EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a) {
265 return Packet2cf(pnegate(a.v));
268EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a) {
269 return Packet2cf(pxor<Packet4f>(a.v,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR)));
273EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
274 return Packet2cf(pand<Packet4f>(a.v, b.v));
277EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
278 return Packet2cf(por<Packet4f>(a.v, b.v));
281EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
282 return Packet2cf(pxor<Packet4f>(a.v, b.v));
285EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
286 return Packet2cf(pandnot<Packet4f>(a.v, b.v));
290EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float>* addr) {
291 EIGEN_PPC_PREFETCH(addr);
295EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a) {
296 EIGEN_ALIGN16 std::complex<float> res[2];
297 pstore((
float*)&res, a.v);
303EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a) {
305 rev_a = vec_sld(a.v, a.v, 8);
306 return Packet2cf(rev_a);
310EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a) {
312 b = vec_sld(a.v, a.v, 8);
313 b = padd<Packet4f>(a.v, b);
314 return pfirst<Packet2cf>(Packet2cf(b));
318EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a) {
321 b = vec_sld(a.v, a.v, 8);
322 prod = pmul<Packet2cf>(a, Packet2cf(b));
324 return pfirst<Packet2cf>(prod);
327EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf, Packet4f)
330EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
331 return pdiv_complex(a, b);
335EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& x) {
336 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
339EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf, 2>& kernel) {
340#ifdef EIGEN_VECTORIZE_VSX
341 Packet4f tmp =
reinterpret_cast<Packet4f
>(
342 vec_mergeh(
reinterpret_cast<Packet2d
>(kernel.packet[0].v),
reinterpret_cast<Packet2d
>(kernel.packet[1].v)));
343 kernel.packet[1].v =
reinterpret_cast<Packet4f
>(
344 vec_mergel(
reinterpret_cast<Packet2d
>(kernel.packet[0].v),
reinterpret_cast<Packet2d
>(kernel.packet[1].v)));
346 Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
347 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
349 kernel.packet[0].v = tmp;
353EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
354 Packet4f eq =
reinterpret_cast<Packet4f
>(vec_cmpeq(a.v, b.v));
355 return Packet2cf(vec_and(eq, vec_perm(eq, eq, p16uc_COMPLEX32_REV)));
358#ifdef EIGEN_VECTORIZE_VSX
360EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
361 const Packet2cf& elsePacket) {
363 result.v =
reinterpret_cast<Packet4f
>(
364 pblend<Packet2d>(ifPacket,
reinterpret_cast<Packet2d
>(thenPacket.v),
reinterpret_cast<Packet2d
>(elsePacket.v)));
370EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(
const Packet2cf& a) {
371 return psqrt_complex<Packet2cf>(a);
375EIGEN_STRONG_INLINE Packet2cf plog<Packet2cf>(
const Packet2cf& a) {
376 return plog_complex<Packet2cf>(a);
380EIGEN_STRONG_INLINE Packet2cf pexp<Packet2cf>(
const Packet2cf& a) {
381 return pexp_complex<Packet2cf>(a);
385#ifdef EIGEN_VECTORIZE_VSX
387 EIGEN_STRONG_INLINE Packet1cd() {}
388 EIGEN_STRONG_INLINE
explicit Packet1cd(
const Packet2d& a) : v(a) {}
390 EIGEN_STRONG_INLINE Packet1cd pmul(
const Packet1cd& a,
const Packet1cd& b) {
391 Packet2d a_re, a_im, v1, v2;
394 a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
396 a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
398 v1 = vec_madd(a_re, b.v, p2d_ZERO);
400 v2 = vec_madd(a_im, b.v, p2d_ZERO);
401 v2 =
reinterpret_cast<Packet2d
>(vec_sld(
reinterpret_cast<Packet4ui
>(v2),
reinterpret_cast<Packet4ui
>(v2), 8));
402 v2 = pxor(v2,
reinterpret_cast<Packet2d
>(p2ul_CONJ_XOR1));
404 return Packet1cd(padd<Packet2d>(v1, v2));
407 EIGEN_STRONG_INLINE Packet1cd& operator*=(
const Packet1cd& b) {
408 v = pmul(Packet1cd(*
this), b).v;
411 EIGEN_STRONG_INLINE Packet1cd operator*(
const Packet1cd& b)
const {
return Packet1cd(*
this) *= b; }
413 EIGEN_STRONG_INLINE Packet1cd& operator+=(
const Packet1cd& b) {
417 EIGEN_STRONG_INLINE Packet1cd operator+(
const Packet1cd& b)
const {
return Packet1cd(*
this) += b; }
418 EIGEN_STRONG_INLINE Packet1cd& operator-=(
const Packet1cd& b) {
422 EIGEN_STRONG_INLINE Packet1cd operator-(
const Packet1cd& b)
const {
return Packet1cd(*
this) -= b; }
423 EIGEN_STRONG_INLINE Packet1cd operator-(
void)
const {
return Packet1cd(-v); }
429struct packet_traits<std::complex<double> > : default_packet_traits {
430 typedef Packet1cd type;
431 typedef Packet1cd half;
432 typedef Packet2d as_real;
454struct unpacket_traits<Packet1cd> {
455 typedef std::complex<double> type;
460 masked_load_available =
false,
461 masked_store_available =
false
463 typedef Packet1cd half;
464 typedef Packet2d as_real;
468EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(
const std::complex<double>* from) {
469 return Packet1cd(pload<Packet2d>((
const double*)from));
472EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(
const std::complex<double>* from) {
473 return Packet1cd(ploadu<Packet2d>((
const double*)from));
476EIGEN_ALWAYS_INLINE Packet1cd pload_partial<Packet1cd>(
const std::complex<double>* from,
const Index n,
477 const Index offset) {
478 return Packet1cd(pload_partial<Packet2d>((
const double*)from, n * 2, offset * 2));
481EIGEN_ALWAYS_INLINE Packet1cd ploadu_partial<Packet1cd>(
const std::complex<double>* from,
const Index n,
482 const Index offset) {
483 return Packet1cd(ploadu_partial<Packet2d>((
const double*)from, n * 2, offset * 2));
486EIGEN_STRONG_INLINE
void pstore<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from) {
487 pstore((
double*)to, from.v);
490EIGEN_STRONG_INLINE
void pstoreu<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from) {
491 pstoreu((
double*)to, from.v);
494EIGEN_ALWAYS_INLINE
void pstore_partial<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from,
495 const Index n,
const Index offset) {
496 pstore_partial((
double*)to, from.v, n * 2, offset * 2);
499EIGEN_ALWAYS_INLINE
void pstoreu_partial<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from,
500 const Index n,
const Index offset) {
501 pstoreu_partial((
double*)to, from.v, n * 2, offset * 2);
505EIGEN_STRONG_INLINE Packet1cd
506pset1<Packet1cd>(
const std::complex<double>& from) {
507 return ploadu<Packet1cd>(&from);
511EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet1cd
512pgather<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index) {
513 return pload<Packet1cd>(from);
516EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet1cd
517pgather_partial<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index,
const Index) {
518 return pload<Packet1cd>(from);
521EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to,
522 const Packet1cd& from,
Index) {
523 pstore<std::complex<double> >(to, from);
526EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter_partial<std::complex<double>, Packet1cd>(std::complex<double>* to,
527 const Packet1cd& from,
529 pstore<std::complex<double> >(to, from);
533EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
534 return Packet1cd(a.v + b.v);
537EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
538 return Packet1cd(a.v - b.v);
541EIGEN_STRONG_INLINE Packet1cd pnegate(
const Packet1cd& a) {
542 return Packet1cd(pnegate(Packet2d(a.v)));
545EIGEN_STRONG_INLINE Packet1cd pconj(
const Packet1cd& a) {
546 return Packet1cd(pxor(a.v,
reinterpret_cast<Packet2d
>(p2ul_CONJ_XOR2)));
550EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
551 return Packet1cd(pand(a.v, b.v));
554EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
555 return Packet1cd(por(a.v, b.v));
558EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
559 return Packet1cd(pxor(a.v, b.v));
562EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
563 return Packet1cd(pandnot(a.v, b.v));
567EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(
const std::complex<double>* from) {
568 return pset1<Packet1cd>(*from);
572EIGEN_STRONG_INLINE
void prefetch<std::complex<double> >(
const std::complex<double>* addr) {
573 EIGEN_PPC_PREFETCH(addr);
577EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(
const Packet1cd& a) {
578 EIGEN_ALIGN16 std::complex<double> res[1];
579 pstore<std::complex<double> >(res, a);
585EIGEN_STRONG_INLINE Packet1cd preverse(
const Packet1cd& a) {
590EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(
const Packet1cd& a) {
595EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(
const Packet1cd& a) {
599EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd, Packet2d)
602EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
603 return pdiv_complex(a, b);
606EIGEN_STRONG_INLINE Packet1cd pcplxflip (
const Packet1cd& x) {
607 return Packet1cd(preverse(Packet2d(x.v)));
610EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet1cd, 2>& kernel) {
611 Packet2d tmp = vec_mergeh(kernel.packet[0].v, kernel.packet[1].v);
612 kernel.packet[1].v = vec_mergel(kernel.packet[0].v, kernel.packet[1].v);
613 kernel.packet[0].v = tmp;
617EIGEN_STRONG_INLINE Packet1cd pcmp_eq(
const Packet1cd& a,
const Packet1cd& b) {
620 Packet2d eq =
reinterpret_cast<Packet2d
>(vec_cmpeq(a.v, b.v));
623 Packet2d eq_swapped =
624 reinterpret_cast<Packet2d
>(vec_sld(
reinterpret_cast<Packet4ui
>(eq),
reinterpret_cast<Packet4ui
>(eq), 8));
626 return Packet1cd(vec_and(eq, eq_swapped));
630EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(
const Packet1cd& a) {
631 return psqrt_complex<Packet1cd>(a);
635EIGEN_STRONG_INLINE Packet1cd plog<Packet1cd>(
const Packet1cd& a) {
636 return plog_complex<Packet1cd>(a);
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83