diff options
author | Konstantinos Margaritis <markos@freevec.org> | 2016-04-05 06:00:51 -0400 |
---|---|---|
committer | Konstantinos Margaritis <markos@freevec.org> | 2016-04-05 06:00:51 -0400 |
commit | 2d41dc9622f9a15bcf77736ef45dc3f7e3d34bdc (patch) | |
tree | 41c1320436726e50e268e72cc160ca0b98c975d6 /Eigen/src/Core/arch | |
parent | 644d0f91d2c1ecb3ed8c64c241f1ce6429ed1ca0 (diff) |
complete int/double specialized traits for ZVector
Diffstat (limited to 'Eigen/src/Core/arch')
-rwxr-xr-x | Eigen/src/Core/arch/ZVector/PacketMath.h | 512 |
1 files changed, 93 insertions, 419 deletions
diff --git a/Eigen/src/Core/arch/ZVector/PacketMath.h b/Eigen/src/Core/arch/ZVector/PacketMath.h index c786aeec0..3586f87af 100755 --- a/Eigen/src/Core/arch/ZVector/PacketMath.h +++ b/Eigen/src/Core/arch/ZVector/PacketMath.h @@ -10,6 +10,8 @@ #ifndef EIGEN_PACKET_MATH_ZVECTOR_H #define EIGEN_PACKET_MATH_ZVECTOR_H +#include <stdint.h> + namespace Eigen { namespace internal { @@ -31,7 +33,6 @@ namespace internal { #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 #endif -typedef __vector float Packet4f; typedef __vector int Packet4i; typedef __vector unsigned int Packet4ui; typedef __vector __bool int Packet4bi; @@ -42,20 +43,21 @@ typedef __vector unsigned long long Packet2ul; typedef __vector long long Packet2l; typedef union { - float f[4]; - double d[2]; - int i[4]; - Packet4f v4f; - Packet4i v4i; - Packet2d v2d; + int32_t i[4]; + uint32_t ui[4]; + int64_t l[2]; + uint64_t ul[2]; + double d[2]; + Packet4i v4i; + Packet4ui v4ui; + Packet2l v2l; + Packet2ul v2ul; + Packet2d v2d; } Packet; // We don't want to write the same code all the time, but we need to reuse the constants // and it doesn't really work to declare them global, so we define macros instead -#define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \ - Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X)) - #define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \ Packet4i p4i_##NAME = reinterpret_cast<Packet4i>(vec_splat_s32(X)) @@ -65,9 +67,6 @@ typedef union { #define _EIGEN_DECLARE_CONST_FAST_Packet2l(NAME,X) \ Packet2l p2l_##NAME = reinterpret_cast<Packet2l>(vec_splat_s64(X)) -#define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ - Packet4f p4f_##NAME = pset1<Packet4f>(X) - #define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ Packet4i p4i_##NAME = pset1<Packet4i>(X) @@ -77,18 +76,14 @@ typedef union { #define _EIGEN_DECLARE_CONST_Packet2l(NAME,X) \ Packet2l p2l_##NAME = pset1<Packet2l>(X) -#define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ - const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X)) - // These constants are endian-agnostic -static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0} -static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,} +//static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,} static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE, 1); //{ 1, 1, 1, 1} static _EIGEN_DECLARE_CONST_FAST_Packet2d(ZERO, 0); static _EIGEN_DECLARE_CONST_FAST_Packet2l(ZERO, 0); +static _EIGEN_DECLARE_CONST_FAST_Packet2l(ONE, 1); -static Packet4f p4f_ONE = { 1.0, 1.0, 1.0, 1.0 }; static Packet2d p2d_ONE = { 1.0, 1.0 }; static Packet2d p2d_ZERO_ = { -0.0, -0.0 }; @@ -98,7 +93,6 @@ static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS16,-16); //{ -16, -16, -16, -16} static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1} static Packet4f p4f_ZERO_ = (Packet4f) vec_sl((Packet4ui)p4i_MINUS1, (Packet4ui)p4i_MINUS1); //{ 0x80000000, 0x80000000, 0x80000000, 0x80000000} */ -static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 }; static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 }; static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet16uc>(p2d_ZERO), reinterpret_cast<Packet16uc>(p2d_ONE), 8)); @@ -112,23 +106,23 @@ static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 }; // Handle endianness properly while loading constants // Define global static constants: -/* -static Packet16uc p16uc_FORWARD = vec_lvsl(0, (float*)0);*/ + +static Packet16uc p16uc_FORWARD = { 0,1,2,3, 4,5,6,7, 8,9,10,11, 12,13,14,15 }; static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 }; static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; -/* + static Packet16uc p16uc_PSET32_WODD = 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_PSET32_WEVEN = vec_sld(p16uc_DUPLICATE32_HI, (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_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16}; +/*static Packet16uc p16uc_HALF64_0_16 = vec_sld((Packet16uc)p4i_ZERO, vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 3), 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16}; -static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 }; +static Packet16uc p16uc_PSET64_HI = (Packet16uc) vec_mergeh((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 0,1,2,3, 4,5,6,7, 0,1,2,3, 4,5,6,7 };*/ static Packet16uc p16uc_PSET64_LO = (Packet16uc) vec_mergel((Packet4ui)p16uc_PSET32_WODD, (Packet4ui)p16uc_PSET32_WEVEN); //{ 8,9,10,11, 12,13,14,15, 8,9,10,11, 12,13,14,15 }; -static Packet16uc p16uc_TRANSPOSE64_HI = vec_add(p16uc_PSET64_HI, p16uc_HALF64_0_16); //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; +/*static Packet16uc p16uc_TRANSPOSE64_HI = vec_add(p16uc_PSET64_HI, p16uc_HALF64_0_16); //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; static Packet16uc p16uc_TRANSPOSE64_LO = vec_add(p16uc_PSET64_LO, p16uc_HALF64_0_16); //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31};*/ static Packet16uc p16uc_TRANSPOSE64_HI = { 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; static Packet16uc p16uc_TRANSPOSE64_LO = { 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31}; -static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 }; +//static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32, 8); //{ 4,5,6,7, 0,1,2,3, 12,13,14,15, 8,9,10,11 }; //static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_FORWARD, p16uc_FORWARD, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; @@ -139,29 +133,6 @@ static Packet16uc p16uc_COMPLEX32_REV = vec_sld(p16uc_REVERSE32, p16uc_REVERSE32 #define EIGEN_ZVECTOR_PREFETCH(ADDR) asm( " pfd [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" ); #endif -template<> struct packet_traits<float> : default_packet_traits -{ - typedef Packet4f type; - typedef Packet4f half; - enum { - Vectorizable = 1, - AlignedOnScalar = 1, - size = 4, - HasHalfPacket = 0, - - // FIXME check the Has* - HasAdd = 1, - HasSub = 1, - HasMul = 1, - HasDiv = 1, - HasSin = 0, - HasCos = 0, - HasLog = 1, - HasExp = 1, - HasSqrt = 0 - }; -}; - template<> struct packet_traits<int> : default_packet_traits { typedef Packet4i type; @@ -178,11 +149,7 @@ template<> struct packet_traits<int> : default_packet_traits HasSub = 1, HasMul = 1, HasDiv = 1, - HasSin = 0, - HasCos = 0, - HasLog = 1, - HasExp = 1, - HasSqrt = 0 + HasBlend = 1 }; }; @@ -203,89 +170,61 @@ template<> struct packet_traits<double> : default_packet_traits HasDiv = 1, HasSin = 0, HasCos = 0, - HasLog = 1, + HasLog = 0, HasExp = 1, - HasSqrt = 1 + HasSqrt = 1, + HasRsqrt = 1, + HasBlend = 1, + HasRound = 1, + HasFloor = 1, + HasCeil = 1 }; }; -template<> struct unpacket_traits<Packet4f> { typedef float type; enum {size=4, alignment=Aligned16}; typedef Packet4f half; }; template<> struct unpacket_traits<Packet4i> { typedef int type; enum {size=4, alignment=Aligned16}; typedef Packet4i half; }; template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16}; typedef Packet2d half; }; -inline std::ostream & operator <<(std::ostream & s, const Packet16uc & v) +inline std::ostream & operator <<(std::ostream & s, const Packet4i & v) { - union { - Packet16uc v; - unsigned char n[16]; - } vt; - vt.v = v; - for (int i=0; i< 16; i++) - s << (int)vt.n[i] << ", "; + Packet vt; + vt.v4i = v; + s << vt.i[0] << ", " << vt.i[1] << ", " << vt.i[2] << ", " << vt.i[3]; return s; } -inline std::ostream & operator <<(std::ostream & s, const Packet4f & v) +inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v) { - union { - Packet4f v; - float n[4]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; + Packet vt; + vt.v4ui = v; + s << vt.ui[0] << ", " << vt.ui[1] << ", " << vt.ui[2] << ", " << vt.ui[3]; return s; } -inline std::ostream & operator <<(std::ostream & s, const Packet4i & v) +inline std::ostream & operator <<(std::ostream & s, const Packet2l & v) { - union { - Packet4i v; - int n[4]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; + Packet vt; + vt.v2l = v; + s << vt.l[0] << ", " << vt.l[1]; return s; } -inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v) +inline std::ostream & operator <<(std::ostream & s, const Packet2ul & v) { - union { - Packet4ui v; - unsigned int n[4]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; + Packet vt; + vt.v2ul = v; + s << vt.ul[0] << ", " << vt.ul[1] ; return s; } inline std::ostream & operator <<(std::ostream & s, const Packet2d & v) { - union { - Packet2d v; - double n[2]; - } vt; - vt.v = v; - s << vt.n[0] << ", " << vt.n[1]; + Packet vt; + vt.v2d = v; + s << vt.d[0] << ", " << vt.d[1]; return s; } template<int Offset> -struct palign_impl<Offset,Packet4f> -{ - static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) - { - switch (Offset % 4) { - case 1: - first = reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(first), reinterpret_cast<Packet4i>(second), 4)); break; - case 2: - first = reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(first), reinterpret_cast<Packet4i>(second), 8)); break; - case 3: - first = reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(first), reinterpret_cast<Packet4i>(second), 12)); break; - } - } -}; - -template<int Offset> struct palign_impl<Offset,Packet4i> { static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second) @@ -311,16 +250,6 @@ struct palign_impl<Offset,Packet2d> } }; -// Need to define them first or we get specialization after instantiation errors -template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_LOAD - Packet *vfrom; - vfrom = (Packet *) from; - return vfrom->v4f; -} - template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) { // FIXME: No intrinsic yet @@ -338,15 +267,6 @@ template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) return vfrom->v2d; } -template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) -{ - // FIXME: No intrinsic yet - EIGEN_DEBUG_ALIGNED_STORE - Packet *vto; - vto = (Packet *) to; - vto->v4f = from; -} - template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) { // FIXME: No intrinsic yet @@ -365,15 +285,6 @@ template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& vto->v2d = from; } -template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) -{ - // FIXME: Check if proper intrinsic exists - Packet res; - res.f[0] = from; - res.v4f = reinterpret_cast<Packet4f>(vec_splats(res.i[0])); - return res.v4f; -} - template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { return vec_splats(from); @@ -386,17 +297,6 @@ template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { } template<> EIGEN_STRONG_INLINE void -pbroadcast4<Packet4f>(const float *a, - Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) -{ - a3 = pload<Packet4f>(a); - a0 = reinterpret_cast<Packet4f>(vec_splat(reinterpret_cast<Packet4i>(a3), 0)); - a1 = reinterpret_cast<Packet4f>(vec_splat(reinterpret_cast<Packet4i>(a3), 1)); - a2 = reinterpret_cast<Packet4f>(vec_splat(reinterpret_cast<Packet4i>(a3), 2)); - a3 = reinterpret_cast<Packet4f>(vec_splat(reinterpret_cast<Packet4i>(a3), 3)); -} - -template<> EIGEN_STRONG_INLINE void pbroadcast4<Packet4i>(const int *a, Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3) { @@ -419,16 +319,6 @@ pbroadcast4<Packet2d>(const double *a, a3 = vec_splat(a3, 1); } -template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) -{ - float EIGEN_ALIGN16 af[4]; - af[0] = from[0*stride]; - af[1] = from[1*stride]; - af[2] = from[2*stride]; - af[3] = from[3*stride]; - return pload<Packet4f>(af); -} - template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride) { int EIGEN_ALIGN16 ai[4]; @@ -447,16 +337,6 @@ template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const dou return pload<Packet2d>(af); } -template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) -{ - float EIGEN_ALIGN16 af[4]; - pstore<float>(af, from); - to[0*stride] = af[0]; - to[1*stride] = af[1]; - to[2*stride] = af[2]; - to[3*stride] = af[3]; -} - template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride) { int EIGEN_ALIGN16 ai[4]; @@ -475,159 +355,52 @@ template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, to[1*stride] = af[1]; } -/* -template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_sub(a,b); } -template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_sub(a,b); } -template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_sub(a,b); } - -template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return psub<Packet4f>(p4f_ZERO, a); } -template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return psub<Packet4i>(p4i_ZERO, a); } -template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return psub<Packet2d>(p2d_ZERO, a); } -*/ -template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } - -template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) -{ - return a; -} - -template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) -{ - return reinterpret_cast<Packet4i>(__builtin_s390_vmalf(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(b), reinterpret_cast<Packet4ui>(c))); -} +template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a + b); } +template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a + b); } -template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) -{ - return vec_madd(a, b, c); -} +template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a - b); } +template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a - b); } -template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - return pmadd<Packet4f>(a,b,p4f_ZERO); -} - -template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) -{ - return pmadd<Packet4i>(a,b,p4i_ZERO); -} - -template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - return pmadd<Packet2d>(a,b,p2d_ZERO); -} - -/*template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) -{ -#ifndef __VSX__ // VSX actually provides a div instruction - Packet4f t, y_0, y_1; +template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a * b); } +template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a * b); } - // Altivec does not offer a divide instruction, we have to do a reciprocal approximation - y_0 = vec_re(b); +template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) { return (a / b); } +template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return (a / b); } - // Do one Newton-Raphson iteration to get the needed accuracy - t = vec_nmsub(y_0, b, p4f_ONE); - y_1 = vec_madd(y_0, t, y_0); +template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return (-a); } +template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return (-a); } - return vec_madd(a, y_1, p4f_ZERO); -#else - return vec_div(a, b); -#endif -} - -template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& a, const Packet4i& b) -{ eigen_assert(false && "packet integer division are not supported by AltiVec"); - return pset1<Packet4i>(0); -} -template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_div(a,b); } -*/ +template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } +template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } -template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return pmadd<Packet4f>(a, p4f_ONE, b); } -template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return pmadd<Packet4i>(a, p4i_ONE, b); } -template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return pmadd<Packet2d>(a, p2d_ONE, b); } +template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd<Packet4i>(pmul<Packet4i>(a, b), c); } +template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); } -template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { return padd<Packet4f>(pset1<Packet4f>(a), p4f_COUNTDOWN); } template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return padd<Packet4i>(pset1<Packet4i>(a), p4i_COUNTDOWN); } template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return padd<Packet2d>(pset1<Packet2d>(a), p2d_COUNTDOWN); } - -template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { return a; /*vec_min(a, b);*/ } template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); } template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_min(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { return a; /*vec_max(a, b);*/ } template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); } template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_max(a, b); } -template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - return reinterpret_cast<Packet4f>(vec_and(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(b))); -} - -template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) -{ - return vec_and(a, b); -} - -template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - return vec_and(a, b); -} - -template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - return reinterpret_cast<Packet4f>(vec_or(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(b))); -} - -template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) -{ - return vec_or(a, b); -} - -template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - return vec_or(a, b); -} - -template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - return reinterpret_cast<Packet4f>(vec_xor(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(b))); -} - -template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) -{ - return vec_xor(a, b); -} +template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); } +template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - return vec_and(a, vec_nor(b, b)); -} +template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); } +template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); } -template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) -{ - return vec_xor(a, b); -} +template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); } +template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); } -template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) -{ - return pand<Packet4f>(a, reinterpret_cast<Packet4f>(vec_nor(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b)))); -} +template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); } +template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return pand<Packet4i>(a, vec_nor(b, b)); } -template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) -{ - return pand<Packet4i>(a, vec_nor(b, b)); -} - -template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) -{ - EIGEN_DEBUG_UNALIGNED_LOAD - Packet *vfrom; - vfrom = (Packet *) from; - return vfrom->v4f; -} +template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { return vec_round(a); } +template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); } +template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); } template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) { @@ -645,14 +418,6 @@ template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) return vfrom->v2d; } -template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) -{ - Packet4f p; - if((ptrdiff_t(from) % 16) == 0) p = pload<Packet4f>(from); - else p = ploadu<Packet4f>(from); - return (Packet4f) vec_perm((Packet16uc)(p), (Packet16uc)(p), p16uc_DUPLICATE32_HI); -} - template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from) { Packet4i p; @@ -669,14 +434,6 @@ template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) return vec_perm(p, p, p16uc_PSET64_HI); } -template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) -{ - EIGEN_DEBUG_UNALIGNED_STORE - Packet *vto; - vto = (Packet *) to; - vto->v4f = from; -} - template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_UNALIGNED_STORE @@ -693,30 +450,12 @@ template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& vto->v2d = from; } -template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) -{ - EIGEN_ZVECTOR_PREFETCH(addr); -} - -template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) -{ - EIGEN_ZVECTOR_PREFETCH(addr); -} +template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_ZVECTOR_PREFETCH(addr); } +template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_ZVECTOR_PREFETCH(addr); } -template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) -{ - EIGEN_ZVECTOR_PREFETCH(addr); -} - -template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x[4]; pstore(x, a); return x[0]; } template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int EIGEN_ALIGN16 x[4]; pstore(x, a); return x[0]; } template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double EIGEN_ALIGN16 x[2]; pstore(x, a); return x[0]; } -template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) -{ - return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); -} - template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) { return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); @@ -727,20 +466,9 @@ template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64)); } -template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return a; /*vec_abs(a);*/ } template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vec_abs(a); } template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { return vec_abs(a); } -template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) -{ - Packet4f b, sum; - b = reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8)); - sum = padd<Packet4f>(a, b); - b = reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(sum), reinterpret_cast<Packet4i>(sum), 4)); - sum = padd<Packet4f>(sum, b); - return pfirst(sum); -} - template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) { Packet4i b, sum; @@ -760,34 +488,6 @@ template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) } -template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) -{ - Packet4f v[4], sum[4]; - - // It's easier and faster to transpose then add as columns - // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation - // Do the transpose, first set of moves - v[0] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(vecs[0]), reinterpret_cast<Packet4i>(vecs[2]))); - v[1] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(vecs[0]), reinterpret_cast<Packet4i>(vecs[2]))); - v[2] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(vecs[1]), reinterpret_cast<Packet4i>(vecs[3]))); - v[3] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(vecs[1]), reinterpret_cast<Packet4i>(vecs[3]))); - // Get the resulting vectors - sum[0] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(v[0]), reinterpret_cast<Packet4i>(v[2]))); - sum[1] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(v[0]), reinterpret_cast<Packet4i>(v[2]))); - sum[2] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(v[1]), reinterpret_cast<Packet4i>(v[3]))); - sum[3] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(v[1]), reinterpret_cast<Packet4i>(v[3]))); - - // Now do the summation: - // Lines 0+1 - sum[0] = padd<Packet4f>(sum[0], sum[1]); - // Lines 2+3 - sum[1] = padd<Packet4f>(sum[2], sum[3]); - // Add the results - sum[0] = padd<Packet4f>(sum[0], sum[1]); - - return sum[0]; -} - template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) { Packet4i v[4], sum[4]; @@ -829,13 +529,6 @@ template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) // Other reduction functions: // mul -template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) -{ - Packet4f prod; - prod = pmul(a, reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))); - return pfirst(pmul(prod, reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(prod), reinterpret_cast<Packet4i>(prod), 4)))); -} - template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a) { EIGEN_ALIGN16 int aux[4]; @@ -849,14 +542,6 @@ template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) } // min -template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) -{ - Packet4f b, res; - b = pmin<Packet4f>(a, reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))); - res = pmin<Packet4f>(b, reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 4))); - return pfirst(res); -} - template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a) { Packet4i b, res; @@ -871,14 +556,6 @@ template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) } // max -template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) -{ - Packet4f b, res; - b = pmax<Packet4f>(a, reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(a), reinterpret_cast<Packet4i>(a), 8))); - res = pmax<Packet4f>(b, reinterpret_cast<Packet4f>(vec_sld(reinterpret_cast<Packet4i>(b), reinterpret_cast<Packet4i>(b), 4))); - return pfirst(res); -} - template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a) { Packet4i b, res; @@ -894,25 +571,11 @@ template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) } EIGEN_DEVICE_FUNC inline void -ptranspose(PacketBlock<Packet4f,4>& kernel) { - Packet4f t0, t1, t2, t3; - t0 = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(kernel.packet[0]), reinterpret_cast<Packet4i>(kernel.packet[2]))); - t1 = reinterpret_cast<Packet4f>(vec_mergel(reinterpret_cast<Packet4i>(kernel.packet[0]), reinterpret_cast<Packet4i>(kernel.packet[2]))); - t2 = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(kernel.packet[1]), reinterpret_cast<Packet4i>(kernel.packet[3]))); - t3 = reinterpret_cast<Packet4f>(vec_mergel(reinterpret_cast<Packet4i>(kernel.packet[1]), reinterpret_cast<Packet4i>(kernel.packet[3]))); - kernel.packet[0] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(t0), reinterpret_cast<Packet4i>(t2))); - kernel.packet[1] = reinterpret_cast<Packet4f>(vec_mergel(reinterpret_cast<Packet4i>(t0), reinterpret_cast<Packet4i>(t2))); - kernel.packet[2] = reinterpret_cast<Packet4f>(vec_mergeh(reinterpret_cast<Packet4i>(t1), reinterpret_cast<Packet4i>(t3))); - kernel.packet[3] = reinterpret_cast<Packet4f>(vec_mergel(reinterpret_cast<Packet4i>(t1), reinterpret_cast<Packet4i>(t3))); -} - -EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4i,4>& kernel) { - Packet4i t0, t1, t2, t3; - t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); - t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); - t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); - t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); + Packet4i t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); + Packet4i t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); + Packet4i t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); + Packet4i t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); kernel.packet[0] = vec_mergeh(t0, t2); kernel.packet[1] = vec_mergel(t0, t2); kernel.packet[2] = vec_mergeh(t1, t3); @@ -921,13 +584,24 @@ ptranspose(PacketBlock<Packet4i,4>& kernel) { EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet2d,2>& kernel) { - Packet2d t0, t1; - t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI); - t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO); + Packet2d t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI); + Packet2d t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO); kernel.packet[0] = t0; kernel.packet[1] = t1; } +template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) { + Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; + Packet4ui mask = vec_cmpeq(select, reinterpret_cast<Packet4ui>(p4i_ONE)); + return vec_sel(elsePacket, thenPacket, mask); +} + +template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) { + Packet2ul select = { ifPacket.select[0], ifPacket.select[1] }; + Packet2ul mask = vec_cmpeq(select, reinterpret_cast<Packet2ul>(p2l_ONE)); + return vec_sel(elsePacket, thenPacket, mask); +} + } // end namespace internal } // end namespace Eigen |