00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_COMPLEX_ALTIVEC_H
00026 #define EIGEN_COMPLEX_ALTIVEC_H
00027
00028 namespace internal {
00029
00030 static Packet4ui p4ui_CONJ_XOR = vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_ZERO_);
00031 static Packet16uc p16uc_COMPLEX_RE = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);
00032 static Packet16uc p16uc_COMPLEX_IM = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 1), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);
00033 static Packet16uc p16uc_COMPLEX_REV = vec_sld(p16uc_REVERSE, p16uc_REVERSE, 8);
00034 static Packet16uc p16uc_COMPLEX_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8);
00035 static Packet16uc p16uc_PSET_HI = (Packet16uc) vec_mergeh((Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 1));
00036 static Packet16uc p16uc_PSET_LO = (Packet16uc) vec_mergeh((Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 2), (Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 3));
00037
00038
00039 struct Packet2cf
00040 {
00041 EIGEN_STRONG_INLINE Packet2cf() {}
00042 EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
00043 Packet4f v;
00044 };
00045
00046 template<> struct packet_traits<std::complex<float> > : default_packet_traits
00047 {
00048 typedef Packet2cf type;
00049 enum {
00050 Vectorizable = 1,
00051 AlignedOnScalar = 1,
00052 size = 2,
00053
00054 HasAdd = 1,
00055 HasSub = 1,
00056 HasMul = 1,
00057 HasDiv = 1,
00058 HasNegate = 1,
00059 HasAbs = 0,
00060 HasAbs2 = 0,
00061 HasMin = 0,
00062 HasMax = 0,
00063 HasSetLinear = 0
00064 };
00065 };
00066
00067 template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2}; };
00068
00069 template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
00070 {
00071 Packet2cf res;
00072
00073 if((ptrdiff_t(&from) % 16) == 0)
00074 res.v = pload<Packet4f>((const float *)&from);
00075 else
00076 res.v = ploadu<Packet4f>((const float *)&from);
00077 res.v = vec_perm(res.v, res.v, p16uc_PSET_HI);
00078 return res;
00079 }
00080
00081 template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_add(a.v,b.v)); }
00082 template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_sub(a.v,b.v)); }
00083 template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(a.v)); }
00084 template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf((Packet4f)vec_xor((Packet4ui)a.v, p4ui_CONJ_XOR)); }
00085
00086 template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00087 {
00088 Packet4f v1, v2;
00089
00090
00091 v1 = vec_perm(a.v, a.v, p16uc_COMPLEX_RE);
00092
00093 v2 = vec_perm(a.v, a.v, p16uc_COMPLEX_IM);
00094
00095 v1 = vec_madd(v1, b.v, p4f_ZERO);
00096
00097 v2 = vec_madd(v2, b.v, p4f_ZERO);
00098 v2 = (Packet4f) vec_xor((Packet4ui)v2, p4ui_CONJ_XOR);
00099
00100 v2 = vec_perm(v2, v2, p16uc_COMPLEX_REV);
00101
00102 return Packet2cf(vec_add(v1, v2));
00103 }
00104
00105 template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_and(a.v,b.v)); }
00106 template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_or(a.v,b.v)); }
00107 template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_xor(a.v,b.v)); }
00108 template<> EIGEN_STRONG_INLINE Packet2cf pandnot<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_and(a.v, vec_nor(b.v,b.v))); }
00109
00110 template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from)); }
00111 template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from)); }
00112
00113 template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from)
00114 {
00115 return pset1<Packet2cf>(*from);
00116 }
00117
00118 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); }
00119 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); }
00120
00121 template<> EIGEN_STRONG_INLINE void prefetch<std::complex<float> >(const std::complex<float> * addr) { vec_dstt((float *)addr, DST_CTRL(2,2,32), DST_CHAN); }
00122
00123 template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
00124 {
00125 std::complex<float> EIGEN_ALIGN16 res[2];
00126 pstore((float *)&res, a.v);
00127
00128 return res[0];
00129 }
00130
00131 template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
00132 {
00133 Packet4f rev_a;
00134 rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX_REV2);
00135 return Packet2cf(rev_a);
00136 }
00137
00138 template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
00139 {
00140 Packet4f b;
00141 b = (Packet4f) vec_sld(a.v, a.v, 8);
00142 b = padd(a.v, b);
00143 return pfirst(Packet2cf(b));
00144 }
00145
00146 template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs)
00147 {
00148 Packet4f b1, b2;
00149
00150 b1 = (Packet4f) vec_sld(vecs[0].v, vecs[1].v, 8);
00151 b2 = (Packet4f) vec_sld(vecs[1].v, vecs[0].v, 8);
00152 b2 = (Packet4f) vec_sld(b2, b2, 8);
00153 b2 = padd(b1, b2);
00154
00155 return Packet2cf(b2);
00156 }
00157
00158 template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
00159 {
00160 Packet4f b;
00161 Packet2cf prod;
00162 b = (Packet4f) vec_sld(a.v, a.v, 8);
00163 prod = pmul(a, Packet2cf(b));
00164
00165 return pfirst(prod);
00166 }
00167
00168 template<int Offset>
00169 struct palign_impl<Offset,Packet2cf>
00170 {
00171 EIGEN_STRONG_INLINE static void run(Packet2cf& first, const Packet2cf& second)
00172 {
00173 if (Offset==1)
00174 {
00175 first.v = vec_sld(first.v, second.v, 8);
00176 }
00177 }
00178 };
00179
00180 template<> struct conj_helper<Packet2cf, Packet2cf, false,true>
00181 {
00182 EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00183 { return padd(pmul(x,y),c); }
00184
00185 EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00186 {
00187 return internal::pmul(a, pconj(b));
00188 }
00189 };
00190
00191 template<> struct conj_helper<Packet2cf, Packet2cf, true,false>
00192 {
00193 EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00194 { return padd(pmul(x,y),c); }
00195
00196 EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00197 {
00198 return internal::pmul(pconj(a), b);
00199 }
00200 };
00201
00202 template<> struct conj_helper<Packet2cf, Packet2cf, true,true>
00203 {
00204 EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
00205 { return padd(pmul(x,y),c); }
00206
00207 EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
00208 {
00209 return pconj(internal::pmul(a, b));
00210 }
00211 };
00212
00213 template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
00214 {
00215
00216 Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
00217 Packet4f s = vec_madd(b.v, b.v, p4f_ZERO);
00218 return Packet2cf(pdiv(res.v, vec_add(s,vec_perm(s, s, p16uc_COMPLEX_REV))));
00219 }
00220
00221 template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x)
00222 {
00223 return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX_REV));
00224 }
00225
00226 }
00227
00228 #endif // EIGEN_COMPLEX_ALTIVEC_H