Warning, file /include/Rivet/Math/eigen3/src/Core/arch/AltiVec/Complex.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_COMPLEX32_ALTIVEC_H
0012 #define EIGEN_COMPLEX32_ALTIVEC_H
0013
0014 namespace RivetEigen {
0015
0016 namespace internal {
0017
0018 static Packet4ui p4ui_CONJ_XOR = vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_MZERO);
0019 #ifdef __VSX__
0020 #if defined(_BIG_ENDIAN)
0021 static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2d_MZERO, (Packet4ui) p2l_ZERO, 8);
0022 static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_MZERO, 8);
0023 #else
0024 static Packet2ul p2ul_CONJ_XOR1 = (Packet2ul) vec_sld((Packet4ui) p2l_ZERO, (Packet4ui) p2d_MZERO, 8);
0025 static Packet2ul p2ul_CONJ_XOR2 = (Packet2ul) vec_sld((Packet4ui) p2d_MZERO, (Packet4ui) p2l_ZERO, 8);
0026 #endif
0027 #endif
0028
0029
0030 struct Packet2cf
0031 {
0032 EIGEN_STRONG_INLINE explicit Packet2cf() {}
0033 EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
0034
0035 EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b)
0036 {
0037 Packet4f v1, v2;
0038
0039
0040 v1 = vec_perm(a.v, a.v, p16uc_PSET32_WODD);
0041
0042 v2 = vec_perm(a.v, a.v, p16uc_PSET32_WEVEN);
0043
0044 v1 = vec_madd(v1, b.v, p4f_ZERO);
0045
0046 v2 = vec_madd(v2, b.v, p4f_ZERO);
0047 v2 = reinterpret_cast<Packet4f>(pxor(v2, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR)));
0048
0049 v2 = vec_perm(v2, v2, p16uc_COMPLEX32_REV);
0050
0051 return Packet2cf(padd<Packet4f>(v1, v2));
0052 }
0053
0054 EIGEN_STRONG_INLINE Packet2cf& operator*=(const Packet2cf& b) {
0055 v = pmul(Packet2cf(*this), b).v;
0056 return *this;
0057 }
0058 EIGEN_STRONG_INLINE Packet2cf operator*(const Packet2cf& b) const {
0059 return Packet2cf(*this) *= b;
0060 }
0061
0062 EIGEN_STRONG_INLINE Packet2cf& operator+=(const Packet2cf& b) {
0063 v = padd(v, b.v);
0064 return *this;
0065 }
0066 EIGEN_STRONG_INLINE Packet2cf operator+(const Packet2cf& b) const {
0067 return Packet2cf(*this) += b;
0068 }
0069 EIGEN_STRONG_INLINE Packet2cf& operator-=(const Packet2cf& b) {
0070 v = psub(v, b.v);
0071 return *this;
0072 }
0073 EIGEN_STRONG_INLINE Packet2cf operator-(const Packet2cf& b) const {
0074 return Packet2cf(*this) -= b;
0075 }
0076 EIGEN_STRONG_INLINE Packet2cf operator-(void) const {
0077 return Packet2cf(-v);
0078 }
0079
0080 Packet4f v;
0081 };
0082
0083 template<> struct packet_traits<std::complex<float> > : default_packet_traits
0084 {
0085 typedef Packet2cf type;
0086 typedef Packet2cf half;
0087 typedef Packet4f as_real;
0088 enum {
0089 Vectorizable = 1,
0090 AlignedOnScalar = 1,
0091 size = 2,
0092 HasHalfPacket = 0,
0093
0094 HasAdd = 1,
0095 HasSub = 1,
0096 HasMul = 1,
0097 HasDiv = 1,
0098 HasNegate = 1,
0099 HasAbs = 0,
0100 HasAbs2 = 0,
0101 HasMin = 0,
0102 HasMax = 0,
0103 #ifdef __VSX__
0104 HasBlend = 1,
0105 #endif
0106 HasSetLinear = 0
0107 };
0108 };
0109
0110 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; typedef Packet4f as_real; };
0111
0112 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
0113 {
0114 Packet2cf res;
0115 if((std::ptrdiff_t(&from) % 16) == 0)
0116 res.v = pload<Packet4f>((const float *)&from);
0117 else
0118 res.v = ploadu<Packet4f>((const float *)&from);
0119 res.v = vec_perm(res.v, res.v, p16uc_PSET64_HI);
0120 return res;
0121 }
0122
0123 template<> EIGEN_STRONG_INLINE Packet2cf pload<Packet2cf>(const std::complex<float>* from) { return Packet2cf(pload<Packet4f>((const float *) from)); }
0124 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { return Packet2cf(ploadu<Packet4f>((const float*) from)); }
0125 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from) { return pset1<Packet2cf>(*from); }
0126
0127 template<> EIGEN_STRONG_INLINE void pstore <std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { pstore((float*)to, from.v); }
0128 template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<float> >(std::complex<float> * to, const Packet2cf& from) { pstoreu((float*)to, from.v); }
0129
0130 EIGEN_STRONG_INLINE Packet2cf pload2(const std::complex<float>* from0, const std::complex<float>* from1)
0131 {
0132 Packet4f res0, res1;
0133 #ifdef __VSX__
0134 __asm__ ("lxsdx %x0,%y1" : "=wa" (res0) : "Z" (*from0));
0135 __asm__ ("lxsdx %x0,%y1" : "=wa" (res1) : "Z" (*from1));
0136 #ifdef _BIG_ENDIAN
0137 __asm__ ("xxpermdi %x0, %x1, %x2, 0" : "=wa" (res0) : "wa" (res0), "wa" (res1));
0138 #else
0139 __asm__ ("xxpermdi %x0, %x2, %x1, 0" : "=wa" (res0) : "wa" (res0), "wa" (res1));
0140 #endif
0141 #else
0142 *reinterpret_cast<std::complex<float> *>(&res0) = *from0;
0143 *reinterpret_cast<std::complex<float> *>(&res1) = *from1;
0144 res0 = vec_perm(res0, res1, p16uc_TRANSPOSE64_HI);
0145 #endif
0146 return Packet2cf(res0);
0147 }
0148
0149 template<> EIGEN_DEVICE_FUNC inline Packet2cf pgather<std::complex<float>, Packet2cf>(const std::complex<float>* from, Index stride)
0150 {
0151 EIGEN_ALIGN16 std::complex<float> af[2];
0152 af[0] = from[0*stride];
0153 af[1] = from[1*stride];
0154 return pload<Packet2cf>(af);
0155 }
0156 template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<float>, Packet2cf>(std::complex<float>* to, const Packet2cf& from, Index stride)
0157 {
0158 EIGEN_ALIGN16 std::complex<float> af[2];
0159 pstore<std::complex<float> >((std::complex<float> *) af, from);
0160 to[0*stride] = af[0];
0161 to[1*stride] = af[1];
0162 }
0163
0164 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(a.v + b.v); }
0165 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(a.v - b.v); }
0166 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(a.v)); }
0167 template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf(pxor<Packet4f>(a.v, reinterpret_cast<Packet4f>(p4ui_CONJ_XOR))); }
0168
0169 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pand<Packet4f>(a.v, b.v)); }
0170 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(por<Packet4f>(a.v, b.v)); }
0171 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pxor<Packet4f>(a.v, b.v)); }
0172 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(pandnot<Packet4f>(a.v, b.v)); }
0173
0174 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { EIGEN_PPC_PREFETCH(addr); }
0175
0176 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
0177 {
0178 EIGEN_ALIGN16 std::complex<float> res[2];
0179 pstore((float *)&res, a.v);
0180
0181 return res[0];
0182 }
0183
0184 template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
0185 {
0186 Packet4f rev_a;
0187 rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX32_REV2);
0188 return Packet2cf(rev_a);
0189 }
0190
0191 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
0192 {
0193 Packet4f b;
0194 b = vec_sld(a.v, a.v, 8);
0195 b = padd<Packet4f>(a.v, b);
0196 return pfirst<Packet2cf>(Packet2cf(b));
0197 }
0198
0199 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
0200 {
0201 Packet4f b;
0202 Packet2cf prod;
0203 b = vec_sld(a.v, a.v, 8);
0204 prod = pmul<Packet2cf>(a, Packet2cf(b));
0205
0206 return pfirst<Packet2cf>(prod);
0207 }
0208
0209 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet2cf,Packet4f)
0210
0211 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
0212 {
0213
0214 Packet2cf res = pmul(a, pconj(b));
0215 Packet4f s = pmul<Packet4f>(b.v, b.v);
0216 return Packet2cf(pdiv(res.v, padd<Packet4f>(s, vec_perm(s, s, p16uc_COMPLEX32_REV))));
0217 }
0218
0219 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x)
0220 {
0221 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX32_REV));
0222 }
0223
0224 EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet2cf,2>& kernel)
0225 {
0226 Packet4f tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
0227 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
0228 kernel.packet[0].v = tmp;
0229 }
0230
0231 template<> EIGEN_STRONG_INLINE Packet2cf pcmp_eq(const Packet2cf& a, const Packet2cf& b) {
0232 Packet4f eq = reinterpret_cast<Packet4f>(vec_cmpeq(a.v,b.v));
0233 return Packet2cf(vec_and(eq, vec_perm(eq, eq, p16uc_COMPLEX32_REV)));
0234 }
0235
0236 #ifdef __VSX__
0237 template<> EIGEN_STRONG_INLINE Packet2cf pblend(const Selector<2>& ifPacket, const Packet2cf& thenPacket, const Packet2cf& elsePacket) {
0238 Packet2cf result;
0239 result.v = reinterpret_cast<Packet4f>(pblend<Packet2d>(ifPacket, reinterpret_cast<Packet2d>(thenPacket.v), reinterpret_cast<Packet2d>(elsePacket.v)));
0240 return result;
0241 }
0242 #endif
0243
0244 template<> EIGEN_STRONG_INLINE Packet2cf psqrt<Packet2cf>(const Packet2cf& a)
0245 {
0246 return psqrt_complex<Packet2cf>(a);
0247 }
0248
0249
0250 #ifdef __VSX__
0251 struct Packet1cd
0252 {
0253 EIGEN_STRONG_INLINE Packet1cd() {}
0254 EIGEN_STRONG_INLINE explicit Packet1cd(const Packet2d& a) : v(a) {}
0255
0256 EIGEN_STRONG_INLINE Packet1cd pmul(const Packet1cd& a, const Packet1cd& b)
0257 {
0258 Packet2d a_re, a_im, v1, v2;
0259
0260
0261 a_re = vec_perm(a.v, a.v, p16uc_PSET64_HI);
0262
0263 a_im = vec_perm(a.v, a.v, p16uc_PSET64_LO);
0264
0265 v1 = vec_madd(a_re, b.v, p2d_ZERO);
0266
0267 v2 = vec_madd(a_im, b.v, p2d_ZERO);
0268 v2 = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(v2), reinterpret_cast<Packet4ui>(v2), 8));
0269 v2 = pxor(v2, reinterpret_cast<Packet2d>(p2ul_CONJ_XOR1));
0270
0271 return Packet1cd(padd<Packet2d>(v1, v2));
0272 }
0273
0274 EIGEN_STRONG_INLINE Packet1cd& operator*=(const Packet1cd& b) {
0275 v = pmul(Packet1cd(*this), b).v;
0276 return *this;
0277 }
0278 EIGEN_STRONG_INLINE Packet1cd operator*(const Packet1cd& b) const {
0279 return Packet1cd(*this) *= b;
0280 }
0281
0282 EIGEN_STRONG_INLINE Packet1cd& operator+=(const Packet1cd& b) {
0283 v = padd(v, b.v);
0284 return *this;
0285 }
0286 EIGEN_STRONG_INLINE Packet1cd operator+(const Packet1cd& b) const {
0287 return Packet1cd(*this) += b;
0288 }
0289 EIGEN_STRONG_INLINE Packet1cd& operator-=(const Packet1cd& b) {
0290 v = psub(v, b.v);
0291 return *this;
0292 }
0293 EIGEN_STRONG_INLINE Packet1cd operator-(const Packet1cd& b) const {
0294 return Packet1cd(*this) -= b;
0295 }
0296 EIGEN_STRONG_INLINE Packet1cd operator-(void) const {
0297 return Packet1cd(-v);
0298 }
0299
0300 Packet2d v;
0301 };
0302
0303 template<> struct packet_traits<std::complex<double> > : default_packet_traits
0304 {
0305 typedef Packet1cd type;
0306 typedef Packet1cd half;
0307 typedef Packet2d as_real;
0308 enum {
0309 Vectorizable = 1,
0310 AlignedOnScalar = 0,
0311 size = 1,
0312 HasHalfPacket = 0,
0313
0314 HasAdd = 1,
0315 HasSub = 1,
0316 HasMul = 1,
0317 HasDiv = 1,
0318 HasNegate = 1,
0319 HasAbs = 0,
0320 HasAbs2 = 0,
0321 HasMin = 0,
0322 HasMax = 0,
0323 HasSetLinear = 0
0324 };
0325 };
0326
0327 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; typedef Packet2d as_real; };
0328
0329 template<> EIGEN_STRONG_INLINE Packet1cd pload <Packet1cd>(const std::complex<double>* from) { return Packet1cd(pload<Packet2d>((const double*)from)); }
0330 template<> EIGEN_STRONG_INLINE Packet1cd ploadu<Packet1cd>(const std::complex<double>* from) { return Packet1cd(ploadu<Packet2d>((const double*)from)); }
0331 template<> EIGEN_STRONG_INLINE void pstore <std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { pstore((double*)to, from.v); }
0332 template<> EIGEN_STRONG_INLINE void pstoreu<std::complex<double> >(std::complex<double> * to, const Packet1cd& from) { pstoreu((double*)to, from.v); }
0333
0334 template<> EIGEN_STRONG_INLINE Packet1cd pset1<Packet1cd>(const std::complex<double>& from)
0335 { return ploadu<Packet1cd>(&from); }
0336
0337 template<> EIGEN_DEVICE_FUNC inline Packet1cd pgather<std::complex<double>, Packet1cd>(const std::complex<double>* from, Index)
0338 {
0339 return pload<Packet1cd>(from);
0340 }
0341 template<> EIGEN_DEVICE_FUNC inline void pscatter<std::complex<double>, Packet1cd>(std::complex<double>* to, const Packet1cd& from, Index)
0342 {
0343 pstore<std::complex<double> >(to, from);
0344 }
0345
0346 template<> EIGEN_STRONG_INLINE Packet1cd padd<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v + b.v); }
0347 template<> EIGEN_STRONG_INLINE Packet1cd psub<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(a.v - b.v); }
0348 template<> EIGEN_STRONG_INLINE Packet1cd pnegate(const Packet1cd& a) { return Packet1cd(pnegate(Packet2d(a.v))); }
0349 template<> EIGEN_STRONG_INLINE Packet1cd pconj(const Packet1cd& a) { return Packet1cd(pxor(a.v, reinterpret_cast<Packet2d>(p2ul_CONJ_XOR2))); }
0350
0351 template<> EIGEN_STRONG_INLINE Packet1cd pand <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pand(a.v,b.v)); }
0352 template<> EIGEN_STRONG_INLINE Packet1cd por <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(por(a.v,b.v)); }
0353 template<> EIGEN_STRONG_INLINE Packet1cd pxor <Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pxor(a.v,b.v)); }
0354 template<> EIGEN_STRONG_INLINE Packet1cd pandnot<Packet1cd>(const Packet1cd& a, const Packet1cd& b) { return Packet1cd(pandnot(a.v, b.v)); }
0355
0356 template<> EIGEN_STRONG_INLINE Packet1cd ploaddup<Packet1cd>(const std::complex<double>* from) { return pset1<Packet1cd>(*from); }
0357
0358 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<double> >(const std::complex<double> * addr) { EIGEN_PPC_PREFETCH(addr); }
0359
0360 template<> EIGEN_STRONG_INLINE std::complex<double> pfirst<Packet1cd>(const Packet1cd& a)
0361 {
0362 EIGEN_ALIGN16 std::complex<double> res[2];
0363 pstore<std::complex<double> >(res, a);
0364
0365 return res[0];
0366 }
0367
0368 template<> EIGEN_STRONG_INLINE Packet1cd preverse(const Packet1cd& a) { return a; }
0369
0370 template<> EIGEN_STRONG_INLINE std::complex<double> predux<Packet1cd>(const Packet1cd& a) { return pfirst(a); }
0371
0372 template<> EIGEN_STRONG_INLINE std::complex<double> predux_mul<Packet1cd>(const Packet1cd& a) { return pfirst(a); }
0373
0374 EIGEN_MAKE_CONJ_HELPER_CPLX_REAL(Packet1cd,Packet2d)
0375
0376 template<> EIGEN_STRONG_INLINE Packet1cd pdiv<Packet1cd>(const Packet1cd& a, const Packet1cd& b)
0377 {
0378
0379 Packet1cd res = pmul(a,pconj(b));
0380 Packet2d s = pmul<Packet2d>(b.v, b.v);
0381 return Packet1cd(pdiv(res.v, padd<Packet2d>(s, vec_perm(s, s, p16uc_REVERSE64))));
0382 }
0383
0384 EIGEN_STRONG_INLINE Packet1cd pcplxflip(const Packet1cd& x)
0385 {
0386 return Packet1cd(preverse(Packet2d(x.v)));
0387 }
0388
0389 EIGEN_STRONG_INLINE void ptranspose(PacketBlock<Packet1cd,2>& kernel)
0390 {
0391 Packet2d tmp = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_HI);
0392 kernel.packet[1].v = vec_perm(kernel.packet[0].v, kernel.packet[1].v, p16uc_TRANSPOSE64_LO);
0393 kernel.packet[0].v = tmp;
0394 }
0395
0396 template<> EIGEN_STRONG_INLINE Packet1cd pcmp_eq(const Packet1cd& a, const Packet1cd& b) {
0397
0398
0399 Packet2d eq = reinterpret_cast<Packet2d>(vec_cmpeq(a.v,b.v));
0400
0401
0402 Packet2d eq_swapped = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(eq), reinterpret_cast<Packet4ui>(eq), 8));
0403
0404 return Packet1cd(vec_and(eq, eq_swapped));
0405 }
0406
0407 template<> EIGEN_STRONG_INLINE Packet1cd psqrt<Packet1cd>(const Packet1cd& a)
0408 {
0409 return psqrt_complex<Packet1cd>(a);
0410 }
0411
0412 #endif
0413 }
0414
0415 }
0416
0417 #endif