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> {
typedef std::complex<float> type;
enum {size=2, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
typedef Packet2cf half; };
95 template<>
struct unpacket_traits<Packet1cd> {
typedef std::complex<double> type;
enum {size=1, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
typedef Packet1cd half; };
98 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel);
101 template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(
const std::complex<double>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet1cd(pload<Packet2d>((
const double*)from)); }
102 template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(
const std::complex<double>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet1cd(ploadu<Packet2d>((
const double*)from)); }
103 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); }
104 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); }
106 template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(
const std::complex<double>& from)
107 {
return ploadu<Packet1cd>(&from); }
109 template<> EIGEN_DEVICE_FUNC
inline Packet1cd pgather<std::complex<double>, Packet1cd>(
const std::complex<double>* from,
Index stride EIGEN_UNUSED)
111 return pload<Packet1cd>(from);
113 template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to,
const Packet1cd& from,
Index stride EIGEN_UNUSED)
115 pstore<std::complex<double> >(to, from);
117 template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(a.v + b.v); }
118 template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(a.v - b.v); }
119 template<> EIGEN_STRONG_INLINE Packet1cd pnegate(
const Packet1cd& a) {
return Packet1cd(pnegate(Packet2d(a.v))); }
120 template<> EIGEN_STRONG_INLINE Packet1cd pconj(
const Packet1cd& a) {
return Packet1cd((Packet2d)vec_xor((Packet2d)a.v, (Packet2d)p2ul_CONJ_XOR2)); }
121 template<> EIGEN_STRONG_INLINE Packet1cd pmul<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
123 Packet2d a_re, a_im, v1, v2;
126 a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
128 a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
130 v1 = vec_madd(a_re, b.v, p2d_ZERO);
132 v2 = vec_madd(a_im, b.v, p2d_ZERO);
133 v2 = (Packet2d) vec_sld((Packet4ui)v2, (Packet4ui)v2, 8);
134 v2 = (Packet2d) vec_xor((Packet2d)v2, (Packet2d) p2ul_CONJ_XOR1);
136 return Packet1cd(v1 + v2);
138 template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_and(a.v,b.v)); }
139 template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_or(a.v,b.v)); }
140 template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(
const Packet1cd& a,
const Packet1cd& b) {
return Packet1cd(vec_xor(a.v,b.v)); }
141 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))); }
142 template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(
const std::complex<double>* from) {
return pset1<Packet1cd>(*from); }
143 template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(
const Packet1cd& a,
const Packet1cd& b) {
144 Packet2d eq = vec_cmpeq (a.v, b.v);
145 Packet2d tmp = { eq[1], eq[0] };
146 return (Packet1cd)pand<Packet2d>(eq, tmp);
149 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<double> >(
const std::complex<double> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
151 template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(
const Packet1cd& a)
153 std::complex<double> EIGEN_ALIGN16 res;
154 pstore<std::complex<double> >(&res, a);
159 template<> EIGEN_STRONG_INLINE Packet1cd preverse(
const Packet1cd& a) {
return a; }
160 template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(
const Packet1cd& a)
164 template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(
const Packet1cd& a)
168 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
170 template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(
const Packet1cd& a,
const Packet1cd& b)
173 Packet1cd res = pmul(a,pconj(b));
174 Packet2d s = vec_madd(b.v, b.v, p2d_ZERO_);
175 return Packet1cd(pdiv(res.v, s + vec_perm(s, s, p16uc_REVERSE64)));
178 EIGEN_STRONG_INLINE Packet1cd pcplxflip(
const Packet1cd& x)
180 return Packet1cd(preverse(Packet2d(x.v)));
183 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet1cd,2>& kernel)
185 Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
186 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
187 kernel.packet[0].v = tmp;
191 template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD
return Packet2cf(pload<Packet4f>((
const float*)from)); }
192 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(
const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return Packet2cf(ploadu<Packet4f>((
const float*)from)); }
193 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); }
194 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); }
196 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(
const Packet2cf& a)
198 std::complex<float> EIGEN_ALIGN16 res[2];
199 pstore<std::complex<float> >(res, a);
205 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12) 206 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
209 res.cd[0] = Packet1cd(vec_ld2f((
const float *)&from));
210 res.cd[1] = res.cd[0];
214 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(
const std::complex<float>& from)
217 if((std::ptrdiff_t(&from) % 16) == 0)
218 res.v = pload<Packet4f>((
const float *)&from);
220 res.v = ploadu<Packet4f>((
const float *)&from);
221 res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
226 template<> EIGEN_DEVICE_FUNC
inline Packet2cf pgather<std::complex<float>, Packet2cf>(
const std::complex<float>* from,
Index stride)
228 std::complex<float> EIGEN_ALIGN16 af[2];
229 af[0] = from[0*stride];
230 af[1] = from[1*stride];
231 return pload<Packet2cf>(af);
233 template<> EIGEN_DEVICE_FUNC
inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to,
const Packet2cf& from,
Index stride)
235 std::complex<float> EIGEN_ALIGN16 af[2];
236 pstore<std::complex<float> >((std::complex<float> *) af, from);
237 to[0*stride] = af[0];
238 to[1*stride] = af[1];
241 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(padd<Packet4f>(a.v, b.v)); }
242 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(psub<Packet4f>(a.v, b.v)); }
243 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(
const Packet2cf& a) {
return Packet2cf(pnegate(Packet4f(a.v))); }
245 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pand<Packet4f>(a.v,b.v)); }
246 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(por<Packet4f>(a.v,b.v)); }
247 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pxor<Packet4f>(a.v,b.v)); }
248 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b) {
return Packet2cf(pandnot<Packet4f>(a.v,b.v)); }
250 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(
const std::complex<float>* from) {
return pset1<Packet2cf>(*from); }
252 template<> EIGEN_STRONG_INLINE
void prefetch<std::complex<float> >(
const std::complex<float> * addr) { EIGEN_ZVECTOR_PREFETCH(addr); }
255 #if !defined(__ARCH__) || (defined(__ARCH__) && __ARCH__ < 12) 257 template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
258 Packet4f eq = pcmp_eq<Packet4f> (a.v, b.v);
260 Packet2d tmp1 = { eq.v4f[0][1], eq.v4f[0][0] };
261 Packet2d tmp2 = { eq.v4f[1][1], eq.v4f[1][0] };
262 res.v.v4f[0] = pand<Packet2d>(eq.v4f[0], tmp1);
263 res.v.v4f[1] = pand<Packet2d>(eq.v4f[1], tmp2);
267 template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a)
270 res.v.v4f[0] = pconj(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[0]))).v;
271 res.v.v4f[1] = pconj(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[1]))).v;
275 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
278 res.v.v4f[0] = pmul(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[0])), Packet1cd(reinterpret_cast<Packet2d>(b.v.v4f[0]))).v;
279 res.v.v4f[1] = pmul(Packet1cd(reinterpret_cast<Packet2d>(a.v.v4f[1])), Packet1cd(reinterpret_cast<Packet2d>(b.v.v4f[1]))).v;
283 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
291 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
293 std::complex<float> res;
294 Packet1cd b = padd<Packet1cd>(a.cd[0], a.cd[1]);
295 vec_st2f(b.v, (
float*)&res);
299 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
301 std::complex<float> res;
302 Packet1cd b = pmul<Packet1cd>(a.cd[0], a.cd[1]);
303 vec_st2f(b.v, (
float*)&res);
307 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
309 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
313 res.cd[0] = pdiv<Packet1cd>(a.cd[0], b.cd[0]);
314 res.cd[1] = pdiv<Packet1cd>(a.cd[1], b.cd[1]);
318 EIGEN_STRONG_INLINE Packet2cf pcplxflip(
const Packet2cf& x)
321 res.cd[0] = pcplxflip(x.cd[0]);
322 res.cd[1] = pcplxflip(x.cd[1]);
326 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel)
328 Packet1cd tmp = kernel.packet[0].cd[1];
329 kernel.packet[0].cd[1] = kernel.packet[1].cd[0];
330 kernel.packet[1].cd[0] = tmp;
333 template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
335 const Selector<4> ifPacket4 = { ifPacket.select[0], ifPacket.select[0], ifPacket.select[1], ifPacket.select[1] };
336 result.v = pblend<Packet4f>(ifPacket4, thenPacket.v, elsePacket.v);
340 template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(
const Packet2cf& a,
const Packet2cf& b) {
341 Packet4f eq = vec_cmpeq (a.v, b.v);
342 Packet4f tmp = { eq[1], eq[0], eq[3], eq[2] };
343 return (Packet2cf)pand<Packet4f>(eq, tmp);
345 template<> EIGEN_STRONG_INLINE Packet2cf pconj(
const Packet2cf& a) {
return Packet2cf(pxor<Packet4f>(a.v, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); }
346 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
348 Packet4f a_re, a_im, prod, prod_im;
351 a_re = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
354 a_im = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
357 prod_im = a_im * b.v;
358 prod_im = pxor<Packet4f>(prod_im,
reinterpret_cast<Packet4f
>(p4ui_CONJ_XOR));
360 prod_im = vec_perm(prod_im, prod_im, p16uc_COMPLEX32_REV);
363 prod = pmadd<Packet4f>(a_re, b.v, prod_im);
365 return Packet2cf(prod);
368 template<> EIGEN_STRONG_INLINE Packet2cf preverse(
const Packet2cf& a)
371 rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2);
372 return Packet2cf(rev_a);
375 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(
const Packet2cf& a)
378 b = vec_sld(a.v, a.v, 8);
379 b = padd<Packet4f>(a.v, b);
380 return pfirst<Packet2cf>(Packet2cf(b));
383 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(
const Packet2cf& a)
387 b = vec_sld(a.v, a.v, 8);
388 prod = pmul<Packet2cf>(a, Packet2cf(b));
390 return pfirst<Packet2cf>(prod);
393 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
395 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(
const Packet2cf& a,
const Packet2cf& b)
398 Packet2cf res = pmul(a, pconj(b));
399 Packet4f s = pmul<Packet4f>(b.v, b.v);
400 return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV))));
403 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(
const Packet2cf& x)
405 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
408 EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2cf,2>& kernel)
410 Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
411 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
412 kernel.packet[0].v = tmp;
415 template<> EIGEN_STRONG_INLINE Packet2cf pblend(
const Selector<2>& ifPacket,
const Packet2cf& thenPacket,
const Packet2cf& elsePacket) {
417 result.v =
reinterpret_cast<Packet4f
>(pblend<Packet2d>(ifPacket,
reinterpret_cast<Packet2d
>(thenPacket.v), reinterpret_cast<Packet2d>(elsePacket.v)));
426 #endif // EIGEN_COMPLEX32_ALTIVEC_H Definition: Constants.h:235
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Definition: BFloat16.h:88
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50