11#ifndef EIGEN_COMPLEX32_ALTIVEC_H
12#define EIGEN_COMPLEX32_ALTIVEC_H
15#include "../../InternalHeaderCheck.h"
21inline Packet4ui p4ui_CONJ_XOR() {
22 return vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO);
24#ifdef EIGEN_VECTORIZE_VSX
25#if defined(_BIG_ENDIAN)
26inline Packet2ul p2ul_CONJ_XOR1() {
27 return (Packet2ul)vec_sld((Packet4ui)p2d_MZERO, (Packet4ui)p2l_ZERO,
30inline Packet2ul p2ul_CONJ_XOR2() {
31 return (Packet2ul)vec_sld((Packet4ui)p2l_ZERO, (Packet4ui)p2d_MZERO,
35inline Packet2ul p2ul_CONJ_XOR1() {
36 return (Packet2ul)vec_sld((Packet4ui)p2l_ZERO, (Packet4ui)p2d_MZERO,
39inline Packet2ul p2ul_CONJ_XOR2() {
40 return (Packet2ul)vec_sld((Packet4ui)p2d_MZERO, (Packet4ui)p2l_ZERO,
48 EIGEN_STRONG_INLINE
explicit Packet2cf() {}
49 EIGEN_STRONG_INLINE
explicit Packet2cf(
const Packet4f& a) : v(a) {}
51 EIGEN_STRONG_INLINE Packet2cf pmul(
const Packet2cf& a,
const Packet2cf& b) {
55 v1 = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
57 v2 = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
59 v1 = vec_madd(v1, b.v, p4f_ZERO);
61 v2 = vec_madd(v2, b.v, p4f_ZERO);
62 v2 =
reinterpret_cast<Packet4f
>(pxor(v2,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR())));
64 v2 = vec_perm(v2, v2, p16uc_COMPLEX32_REV);
66 return Packet2cf(padd<Packet4f>(v1, v2));
69 EIGEN_STRONG_INLINE Packet2cf& operator*=(
const Packet2cf& b) {
70 v = pmul(Packet2cf(*
this), b).v;
73 EIGEN_STRONG_INLINE Packet2cf operator*(
const Packet2cf& b)
const {
return Packet2cf(*
this) *= b; }
75 EIGEN_STRONG_INLINE Packet2cf& operator+=(
const Packet2cf& b) {
79 EIGEN_STRONG_INLINE Packet2cf operator+(
const Packet2cf& b)
const {
return Packet2cf(*
this) += b; }
80 EIGEN_STRONG_INLINE Packet2cf& operator-=(
const Packet2cf& b) {
84 EIGEN_STRONG_INLINE Packet2cf operator-(
const Packet2cf& b)
const {
return Packet2cf(*
this) -= b; }
85 EIGEN_STRONG_INLINE Packet2cf operator-(
void)
const {
return Packet2cf(-v); }
91struct packet_traits<std::complex<float> > : default_packet_traits {
92 typedef Packet2cf type;
93 typedef Packet2cf half;
94 typedef Packet4f as_real;
117struct unpacket_traits<Packet2cf> {
118 typedef std::complex<float> type;
123 masked_load_available =
false,
124 masked_store_available =
false
126 typedef Packet2cf half;
127 typedef Packet4f as_real;
131EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from) {
133#ifdef EIGEN_VECTORIZE_VSX
138 __asm__(
"lxvdsx %x0,%y1" :
"=wa"(res.v) :
"Z"(from));
140 if ((std::ptrdiff_t(&from) % 16) == 0)
141 res.v = pload<Packet4f>((
const float*)&from);
143 res.v = ploadu<Packet4f>((
const float*)&from);
144 res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
150EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(
const std::complex<float>* from) {
151 return Packet2cf(pload<Packet4f>((
const float*)from));
154EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) {
155 return Packet2cf(ploadu<Packet4f>((
const float*)from));
158EIGEN_ALWAYS_INLINE Packet2cf pload_partial<Packet2cf>(
const std::complex<float>* from,
const Index n,
159 const Index offset) {
160 return Packet2cf(pload_partial<Packet4f>((
const float*)from, n * 2, offset * 2));
163EIGEN_ALWAYS_INLINE Packet2cf ploadu_partial<Packet2cf>(
const std::complex<float>* from,
const Index n,
164 const Index offset) {
165 return Packet2cf(ploadu_partial<Packet4f>((
const float*)from, n * 2, offset * 2));
168EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
169 return pset1<Packet2cf>(*from);
173EIGEN_STRONG_INLINE
void pstore<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from) {
174 pstore((
float*)to, from.v);
177EIGEN_STRONG_INLINE
void pstoreu<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from) {
178 pstoreu((
float*)to, from.v);
181EIGEN_ALWAYS_INLINE
void pstore_partial<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from,
183 pstore_partial((
float*)to, from.v, n * 2, offset * 2);
186EIGEN_ALWAYS_INLINE
void pstoreu_partial<std::complex<float> >(std::complex<float>* to,
const Packet2cf& from,
188 pstoreu_partial((
float*)to, from.v, n * 2, offset * 2);
191EIGEN_STRONG_INLINE Packet2cf pload2(
const std::complex<float>& from0,
const std::complex<float>& from1) {
193#ifdef EIGEN_VECTORIZE_VSX
195 __asm__(
"lxsdx %x0,%y1" :
"=wa"(res0) :
"Z"(from0));
196 __asm__(
"lxsdx %x0,%y1" :
"=wa"(res1) :
"Z"(from1));
198 __asm__(
"xxpermdi %x0, %x1, %x2, 0" :
"=wa"(res0) :
"wa"(res0),
"wa"(res1));
200 __asm__(
"xxpermdi %x0, %x2, %x1, 0" :
"=wa"(res0) :
"wa"(res0),
"wa"(res1));
203 *
reinterpret_cast<std::complex<float>*
>(&res0) = from0;
204 *
reinterpret_cast<std::complex<float>*
>(&res1) = from1;
205 res0 = vec_perm(res0, res1, p16uc_TRANSPOSE64_HI);
207 return Packet2cf(res0);
211EIGEN_ALWAYS_INLINE Packet2cf pload_ignore<Packet2cf>(
const std::complex<float>* from) {
213 res.v = pload_ignore<Packet4f>(
reinterpret_cast<const float*
>(from));
217template <
typename Scalar,
typename Packet>
218EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pgather_complex_size2(
const Scalar* from,
Index stride,
220 eigen_internal_assert(n <= unpacket_traits<Packet>::size &&
"number of elements will gather past end of packet");
221 EIGEN_ALIGN16 Scalar af[2];
222 for (
Index i = 0; i < n; i++) {
223 af[i] = from[i * stride];
225 return pload_ignore<Packet>(af);
228EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet2cf pgather<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
230 return pgather_complex_size2<std::complex<float>, Packet2cf>(from, stride);
233EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet2cf
234pgather_partial<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
Index stride,
const Index n) {
235 return pgather_complex_size2<std::complex<float>, Packet2cf>(from, stride, n);
237template <
typename Scalar,
typename Packet>
238EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter_complex_size2(Scalar* to,
const Packet& from,
Index stride,
240 eigen_internal_assert(n <= unpacket_traits<Packet>::size &&
"number of elements will scatter past end of packet");
241 EIGEN_ALIGN16 Scalar af[2];
242 pstore<Scalar>((Scalar*)af, from);
243 for (
Index i = 0; i < n; i++) {
244 to[i * stride] = af[i];
248EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
249 const Packet2cf& from,
251 pscatter_complex_size2<std::complex<float>, Packet2cf>(to, from, stride);
254EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter_partial<std::complex<float>, Packet2cf>(std::complex<float>* to,
255 const Packet2cf& from,
258 pscatter_complex_size2<std::complex<float>, Packet2cf>(to, from, stride, n);
262EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
263 return Packet2cf(a.v + b.v);
266EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
267 return Packet2cf(a.v - b.v);
270EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a) {
271 return Packet2cf(pnegate(a.v));
274EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a) {
275 return Packet2cf(pxor<Packet4f>(a.v,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR())));
279EIGEN_STRONG_INLINE Packet2cf pand<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
280 return Packet2cf(pand<Packet4f>(a.v, b.v));
283EIGEN_STRONG_INLINE Packet2cf por<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
284 return Packet2cf(por<Packet4f>(a.v, b.v));
287EIGEN_STRONG_INLINE Packet2cf pxor<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
288 return Packet2cf(pxor<Packet4f>(a.v, b.v));
291EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
292 return Packet2cf(pandnot<Packet4f>(a.v, b.v));
296EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float>* addr) {
297 EIGEN_PPC_PREFETCH(addr);
301EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a) {
302 EIGEN_ALIGN16 std::complex<float> res[2];
303 pstore((
float*)&res, a.v);
309EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a) {
311 rev_a = vec_sld(a.v, a.v, 8);
312 return Packet2cf(rev_a);
316EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a) {
318 b = vec_sld(a.v, a.v, 8);
319 b = padd<Packet4f>(a.v, b);
320 return pfirst<Packet2cf>(Packet2cf(b));
324EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a) {
327 b = vec_sld(a.v, a.v, 8);
328 prod = pmul<Packet2cf>(a, Packet2cf(b));
330 return pfirst<Packet2cf>(prod);
333EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf, Packet4f)
336EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
337 return pdiv_complex(a, b);
341EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& x) {
342 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
345EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf, 2>& kernel) {
346#ifdef EIGEN_VECTORIZE_VSX
347 Packet4f tmp =
reinterpret_cast<Packet4f
>(
348 vec_mergeh(
reinterpret_cast<Packet2d
>(kernel.packet[0].v),
reinterpret_cast<Packet2d
>(kernel.packet[1].v)));
349 kernel.packet[1].v =
reinterpret_cast<Packet4f
>(
350 vec_mergel(
reinterpret_cast<Packet2d
>(kernel.packet[0].v),
reinterpret_cast<Packet2d
>(kernel.packet[1].v)));
352 Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
353 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
355 kernel.packet[0].v = tmp;
359EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
360 Packet4f eq =
reinterpret_cast<Packet4f
>(vec_cmpeq(a.v, b.v));
361 return Packet2cf(vec_and(eq, vec_perm(eq, eq, p16uc_COMPLEX32_REV)));
365EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(
const Packet2cf& a) {
366 return psqrt_complex<Packet2cf>(a);
370EIGEN_STRONG_INLINE Packet2cf plog<Packet2cf>(
const Packet2cf& a) {
371 return plog_complex<Packet2cf>(a);
375EIGEN_STRONG_INLINE Packet2cf pexp<Packet2cf>(
const Packet2cf& a) {
376 return pexp_complex<Packet2cf>(a);
380#ifdef EIGEN_VECTORIZE_VSX
382 EIGEN_STRONG_INLINE Packet1cd() {}
383 EIGEN_STRONG_INLINE
explicit Packet1cd(
const Packet2d& a) : v(a) {}
385 EIGEN_STRONG_INLINE Packet1cd pmul(
const Packet1cd& a,
const Packet1cd& b) {
386 Packet2d a_re, a_im, v1, v2;
389 a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
391 a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
393 v1 = vec_madd(a_re, b.v, p2d_ZERO);
395 v2 = vec_madd(a_im, b.v, p2d_ZERO);
396 v2 =
reinterpret_cast<Packet2d
>(vec_sld(
reinterpret_cast<Packet4ui
>(v2),
reinterpret_cast<Packet4ui
>(v2), 8));
397 v2 = pxor(v2,
reinterpret_cast<Packet2d
>(p2ul_CONJ_XOR1()));
399 return Packet1cd(padd<Packet2d>(v1, v2));
402 EIGEN_STRONG_INLINE Packet1cd& operator*=(
const Packet1cd& b) {
403 v = pmul(Packet1cd(*
this), b).v;
406 EIGEN_STRONG_INLINE Packet1cd operator*(
const Packet1cd& b)
const {
return Packet1cd(*
this) *= b; }
408 EIGEN_STRONG_INLINE Packet1cd& operator+=(
const Packet1cd& b) {
412 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-(
void)
const {
return Packet1cd(-v); }
424struct packet_traits<std::complex<double> > : default_packet_traits {
425 typedef Packet1cd type;
426 typedef Packet1cd half;
427 typedef Packet2d as_real;
449struct unpacket_traits<Packet1cd> {
450 typedef std::complex<double> type;
455 masked_load_available =
false,
456 masked_store_available =
false
458 typedef Packet1cd half;
459 typedef Packet2d as_real;
463EIGEN_STRONG_INLINE Packet1cd pload<Packet1cd>(
const std::complex<double>* from) {
464 return Packet1cd(pload<Packet2d>((
const double*)from));
467EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(
const std::complex<double>* from) {
468 return Packet1cd(ploadu<Packet2d>((
const double*)from));
471EIGEN_ALWAYS_INLINE Packet1cd pload_partial<Packet1cd>(
const std::complex<double>* from,
const Index n,
472 const Index offset) {
473 return Packet1cd(pload_partial<Packet2d>((
const double*)from, n * 2, offset * 2));
476EIGEN_ALWAYS_INLINE Packet1cd ploadu_partial<Packet1cd>(
const std::complex<double>* from,
const Index n,
477 const Index offset) {
478 return Packet1cd(ploadu_partial<Packet2d>((
const double*)from, n * 2, offset * 2));
481EIGEN_STRONG_INLINE
void pstore<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from) {
482 pstore((
double*)to, from.v);
485EIGEN_STRONG_INLINE
void pstoreu<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from) {
486 pstoreu((
double*)to, from.v);
489EIGEN_ALWAYS_INLINE
void pstore_partial<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from,
491 pstore_partial((
double*)to, from.v, n * 2, offset * 2);
494EIGEN_ALWAYS_INLINE
void pstoreu_partial<std::complex<double> >(std::complex<double>* to,
const Packet1cd& from,
496 pstoreu_partial((
double*)to, from.v, n * 2, offset * 2);
500EIGEN_STRONG_INLINE Packet1cd
501pset1<Packet1cd>(
const std::complex<double>& from) {
502 return ploadu<Packet1cd>(&from);
506EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet1cd
507pgather<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index) {
508 return pload<Packet1cd>(from);
511EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet1cd
512pgather_partial<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index,
const Index) {
513 return pload<Packet1cd>(from);
516EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to,
517 const Packet1cd& from,
Index) {
518 pstore<std::complex<double> >(to, from);
521EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
void pscatter_partial<std::complex<double>, Packet1cd>(std::complex<double>* to,
522 const Packet1cd& from,
524 pstore<std::complex<double> >(to, from);
528EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
529 return Packet1cd(a.v + b.v);
532EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
533 return Packet1cd(a.v - b.v);
536EIGEN_STRONG_INLINE Packet1cd pnegate(
const Packet1cd& a) {
537 return Packet1cd(pnegate(Packet2d(a.v)));
540EIGEN_STRONG_INLINE Packet1cd pconj(
const Packet1cd& a) {
541 return Packet1cd(pxor(a.v,
reinterpret_cast<Packet2d
>(p2ul_CONJ_XOR2())));
545EIGEN_STRONG_INLINE Packet1cd pand<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
546 return Packet1cd(pand(a.v, b.v));
549EIGEN_STRONG_INLINE Packet1cd por<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
550 return Packet1cd(por(a.v, b.v));
553EIGEN_STRONG_INLINE Packet1cd pxor<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
554 return Packet1cd(pxor(a.v, b.v));
557EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
558 return Packet1cd(pandnot(a.v, b.v));
562EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(
const std::complex<double>* from) {
563 return pset1<Packet1cd>(*from);
567EIGEN_STRONG_INLINE
void prefetch<std::complex<double> >(
const std::complex<double>* addr) {
568 EIGEN_PPC_PREFETCH(addr);
572EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(
const Packet1cd& a) {
573 EIGEN_ALIGN16 std::complex<double> res[1];
574 pstore<std::complex<double> >(res, a);
580EIGEN_STRONG_INLINE Packet1cd preverse(
const Packet1cd& a) {
585EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(
const Packet1cd& a) {
590EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(
const Packet1cd& a) {
594EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd, Packet2d)
597EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
598 return pdiv_complex(a, b);
601EIGEN_STRONG_INLINE Packet1cd pcplxflip (
const Packet1cd& x) {
602 return Packet1cd(preverse(Packet2d(x.v)));
605EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet1cd, 2>& kernel) {
606 Packet2d tmp = vec_mergeh(kernel.packet[0].v, kernel.packet[1].v);
607 kernel.packet[1].v = vec_mergel(kernel.packet[0].v, kernel.packet[1].v);
608 kernel.packet[0].v = tmp;
612EIGEN_STRONG_INLINE Packet1cd pcmp_eq(
const Packet1cd& a,
const Packet1cd& b) {
615 Packet2d eq =
reinterpret_cast<Packet2d
>(vec_cmpeq(a.v, b.v));
618 Packet2d eq_swapped =
619 reinterpret_cast<Packet2d
>(vec_sld(
reinterpret_cast<Packet4ui
>(eq),
reinterpret_cast<Packet4ui
>(eq), 8));
621 return Packet1cd(vec_and(eq, eq_swapped));
625EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(
const Packet1cd& a) {
626 return psqrt_complex<Packet1cd>(a);
630EIGEN_STRONG_INLINE Packet1cd plog<Packet1cd>(
const Packet1cd& a) {
631 return plog_complex<Packet1cd>(a);
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82