2010-07-09 17:54:41 +03:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
|
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_COMPLEX_ALTIVEC_H
|
|
|
|
|
#define EIGEN_COMPLEX_ALTIVEC_H
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
static Packet4ui p4ui_CONJ_XOR = vec_mergeh((Packet4ui)p4i_ZERO, (Packet4ui)p4f_ZERO_);//{ 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
|
|
|
|
|
static Packet16uc p16uc_COMPLEX_RE = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 };
|
|
|
|
|
static Packet16uc p16uc_COMPLEX_IM = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 1), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 };
|
|
|
|
|
static Packet16uc p16uc_COMPLEX_REV = vec_sld(p16uc_REVERSE, p16uc_REVERSE, 8);//{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 };
|
|
|
|
|
static Packet16uc p16uc_COMPLEX_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8);//{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 };
|
|
|
|
|
static Packet16uc p16uc_PSET_HI = (Packet16uc) vec_mergeh((Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 1));//{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };
|
|
|
|
|
static Packet16uc p16uc_PSET_LO = (Packet16uc) vec_mergeh((Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 2), (Packet4ui) vec_splat((Packet4ui)p16uc_FORWARD, 3));//{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 };
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
//---------- float ----------
|
|
|
|
|
struct Packet2cf
|
|
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf() {}
|
|
|
|
|
EIGEN_STRONG_INLINE explicit Packet2cf(const Packet4f& a) : v(a) {}
|
|
|
|
|
Packet4f v;
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct packet_traits<std::complex<float> > : default_packet_traits
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
typedef Packet2cf type;
|
|
|
|
|
enum {
|
|
|
|
|
Vectorizable = 1,
|
2011-02-22 21:25:47 +01:00
|
|
|
AlignedOnScalar = 1,
|
2010-07-09 17:54:41 +03:00
|
|
|
size = 2,
|
|
|
|
|
|
|
|
|
|
HasAdd = 1,
|
|
|
|
|
HasSub = 1,
|
|
|
|
|
HasMul = 1,
|
|
|
|
|
HasDiv = 1,
|
|
|
|
|
HasNegate = 1,
|
|
|
|
|
HasAbs = 0,
|
|
|
|
|
HasAbs2 = 0,
|
|
|
|
|
HasMin = 0,
|
|
|
|
|
HasMax = 0,
|
|
|
|
|
HasSetLinear = 0
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct unpacket_traits<Packet2cf> { typedef std::complex<float> type; enum {size=2}; };
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pset1<Packet2cf>(const std::complex<float>& from)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
Packet2cf res;
|
|
|
|
|
/* On AltiVec we cannot load 64-bit registers, so wa have to take care of alignment */
|
2011-05-05 18:48:18 +02:00
|
|
|
if((ptrdiff_t(&from) % 16) == 0)
|
2011-02-21 20:36:20 +01:00
|
|
|
res.v = pload<Packet4f>((const float *)&from);
|
2011-02-23 21:24:47 +03:00
|
|
|
else
|
2011-02-21 20:36:20 +01:00
|
|
|
res.v = ploadu<Packet4f>((const float *)&from);
|
2011-02-23 21:24:47 +03:00
|
|
|
res.v = vec_perm(res.v, res.v, p16uc_PSET_HI);
|
2010-07-09 17:54:41 +03:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf padd<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_add(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf psub<Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_sub(a.v,b.v)); }
|
2011-02-23 21:24:47 +03:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf& a) { return Packet2cf(pnegate(a.v)); }
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) { return Packet2cf((Packet4f)vec_xor((Packet4ui)a.v, p4ui_CONJ_XOR)); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pmul<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
Packet4f v1, v2;
|
|
|
|
|
|
|
|
|
|
// Permute and multiply the real parts of a and b
|
2010-10-25 10:15:22 -04:00
|
|
|
v1 = vec_perm(a.v, a.v, p16uc_COMPLEX_RE);
|
2010-07-09 17:54:41 +03:00
|
|
|
// Get the imaginary parts of a
|
2010-10-25 10:15:22 -04:00
|
|
|
v2 = vec_perm(a.v, a.v, p16uc_COMPLEX_IM);
|
2010-07-09 17:54:41 +03:00
|
|
|
// multiply a_re * b
|
2010-10-25 10:15:22 -04:00
|
|
|
v1 = vec_madd(v1, b.v, p4f_ZERO);
|
2010-07-09 17:54:41 +03:00
|
|
|
// multiply a_im * b and get the conjugate result
|
2010-10-25 10:15:22 -04:00
|
|
|
v2 = vec_madd(v2, b.v, p4f_ZERO);
|
|
|
|
|
v2 = (Packet4f) vec_xor((Packet4ui)v2, p4ui_CONJ_XOR);
|
2010-07-09 17:54:41 +03:00
|
|
|
// permute back to a proper order
|
2010-10-25 10:15:22 -04:00
|
|
|
v2 = vec_perm(v2, v2, p16uc_COMPLEX_REV);
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
return Packet2cf(vec_add(v1, v2));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pand <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_and(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf por <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_or(a.v,b.v)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pxor <Packet2cf>(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(vec_xor(a.v,b.v)); }
|
|
|
|
|
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))); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2011-02-21 20:36:20 +01:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pload <Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload<Packet4f>((const float*)from)); }
|
|
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf ploadu<Packet2cf>(const std::complex<float>* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu<Packet4f>((const float*)from)); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2011-02-23 18:20:55 +03:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf ploaddup<Packet2cf>(const std::complex<float>* from)
|
|
|
|
|
{
|
|
|
|
|
return pset1<Packet2cf>(*from);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
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); }
|
|
|
|
|
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); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
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); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<float> pfirst<Packet2cf>(const Packet2cf& a)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
std::complex<float> EIGEN_ALIGN16 res[2];
|
2010-10-25 10:15:22 -04:00
|
|
|
pstore((float *)&res, a.v);
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
return res[0];
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf& a)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
Packet4f rev_a;
|
2010-10-25 10:15:22 -04:00
|
|
|
rev_a = vec_perm(a.v, a.v, p16uc_COMPLEX_REV2);
|
2010-07-09 17:54:41 +03:00
|
|
|
return Packet2cf(rev_a);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<float> predux<Packet2cf>(const Packet2cf& a)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
Packet4f b;
|
|
|
|
|
b = (Packet4f) vec_sld(a.v, a.v, 8);
|
2010-10-25 10:15:22 -04:00
|
|
|
b = padd(a.v, b);
|
2011-02-22 15:26:28 +01:00
|
|
|
return pfirst(Packet2cf(b));
|
2010-07-09 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf preduxp<Packet2cf>(const Packet2cf* vecs)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
Packet4f b1, b2;
|
|
|
|
|
|
|
|
|
|
b1 = (Packet4f) vec_sld(vecs[0].v, vecs[1].v, 8);
|
|
|
|
|
b2 = (Packet4f) vec_sld(vecs[1].v, vecs[0].v, 8);
|
|
|
|
|
b2 = (Packet4f) vec_sld(b2, b2, 8);
|
2010-10-25 10:15:22 -04:00
|
|
|
b2 = padd(b1, b2);
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
return Packet2cf(b2);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE std::complex<float> predux_mul<Packet2cf>(const Packet2cf& a)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
Packet4f b;
|
|
|
|
|
Packet2cf prod;
|
|
|
|
|
b = (Packet4f) vec_sld(a.v, a.v, 8);
|
2010-10-25 10:15:22 -04:00
|
|
|
prod = pmul(a, Packet2cf(b));
|
2010-07-09 17:54:41 +03:00
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
return pfirst(prod);
|
2010-07-09 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int Offset>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct palign_impl<Offset,Packet2cf>
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
2012-01-31 12:58:52 +01:00
|
|
|
static EIGEN_STRONG_INLINE void run(Packet2cf& first, const Packet2cf& second)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
if (Offset==1)
|
|
|
|
|
{
|
|
|
|
|
first.v = vec_sld(first.v, second.v, 8);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet2cf, Packet2cf, false,true>
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
|
|
|
|
|
{
|
2011-02-23 09:41:02 +01:00
|
|
|
return internal::pmul(a, pconj(b));
|
2010-07-09 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet2cf, Packet2cf, true,false>
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
|
|
|
|
|
{
|
2011-02-23 09:41:02 +01:00
|
|
|
return internal::pmul(pconj(a), b);
|
2010-07-09 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> struct conj_helper<Packet2cf, Packet2cf, true,true>
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmadd(const Packet2cf& x, const Packet2cf& y, const Packet2cf& c) const
|
2010-10-25 10:15:22 -04:00
|
|
|
{ return padd(pmul(x,y),c); }
|
2010-07-09 17:54:41 +03:00
|
|
|
|
|
|
|
|
EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) const
|
|
|
|
|
{
|
2011-02-23 09:41:02 +01:00
|
|
|
return pconj(internal::pmul(a, b));
|
2010-07-09 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pdiv<Packet2cf>(const Packet2cf& a, const Packet2cf& b)
|
2010-07-09 17:54:41 +03:00
|
|
|
{
|
|
|
|
|
// TODO optimize it for AltiVec
|
2010-10-25 10:15:22 -04:00
|
|
|
Packet2cf res = conj_helper<Packet2cf,Packet2cf,false,true>().pmul(a,b);
|
|
|
|
|
Packet4f s = vec_madd(b.v, b.v, p4f_ZERO);
|
|
|
|
|
return Packet2cf(pdiv(res.v, vec_add(s,vec_perm(s, s, p16uc_COMPLEX_REV))));
|
2010-07-09 17:54:41 +03:00
|
|
|
}
|
|
|
|
|
|
2011-02-23 17:51:40 +03:00
|
|
|
template<> EIGEN_STRONG_INLINE Packet2cf pcplxflip<Packet2cf>(const Packet2cf& x)
|
2011-02-23 14:20:58 +01:00
|
|
|
{
|
2011-02-23 17:51:40 +03:00
|
|
|
return Packet2cf(vec_perm(x.v, x.v, p16uc_COMPLEX_REV));
|
2011-02-23 14:20:58 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-25 10:15:22 -04:00
|
|
|
} // end namespace internal
|
|
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2010-07-09 17:54:41 +03:00
|
|
|
#endif // EIGEN_COMPLEX_ALTIVEC_H
|