![]() |
Eigen
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2008-2016 Konstantinos Margaritis <markos@freevec.org> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_PACKET_MATH_ALTIVEC_H 00011 #define EIGEN_PACKET_MATH_ALTIVEC_H 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 00017 #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 00018 #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 4 00019 #endif 00020 00021 #ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD 00022 #define EIGEN_HAS_SINGLE_INSTRUCTION_MADD 00023 #endif 00024 00025 #ifndef EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD 00026 #define EIGEN_HAS_SINGLE_INSTRUCTION_CJMADD 00027 #endif 00028 00029 // NOTE Altivec has 32 registers, but Eigen only accepts a value of 8 or 16 00030 #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 00031 #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 32 00032 #endif 00033 00034 typedef __vector float Packet4f; 00035 typedef __vector int Packet4i; 00036 typedef __vector unsigned int Packet4ui; 00037 typedef __vector __bool int Packet4bi; 00038 typedef __vector short int Packet8i; 00039 typedef __vector unsigned char Packet16uc; 00040 00041 // We don't want to write the same code all the time, but we need to reuse the constants 00042 // and it doesn't really work to declare them global, so we define macros instead 00043 00044 #define _EIGEN_DECLARE_CONST_FAST_Packet4f(NAME,X) \ 00045 Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(vec_splat_s32(X)) 00046 00047 #define _EIGEN_DECLARE_CONST_FAST_Packet4i(NAME,X) \ 00048 Packet4i p4i_##NAME = vec_splat_s32(X) 00049 00050 #define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ 00051 Packet4f p4f_##NAME = pset1<Packet4f>(X) 00052 00053 #define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ 00054 Packet4i p4i_##NAME = pset1<Packet4i>(X) 00055 00056 #define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \ 00057 Packet2d p2d_##NAME = pset1<Packet2d>(X) 00058 00059 #define _EIGEN_DECLARE_CONST_Packet2l(NAME,X) \ 00060 Packet2l p2l_##NAME = pset1<Packet2l>(X) 00061 00062 #define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ 00063 const Packet4f p4f_##NAME = reinterpret_cast<Packet4f>(pset1<Packet4i>(X)) 00064 00065 #define DST_CHAN 1 00066 #define DST_CTRL(size, count, stride) (((size) << 24) | ((count) << 16) | (stride)) 00067 00068 00069 // These constants are endian-agnostic 00070 static _EIGEN_DECLARE_CONST_FAST_Packet4f(ZERO, 0); //{ 0.0, 0.0, 0.0, 0.0} 00071 static _EIGEN_DECLARE_CONST_FAST_Packet4i(ZERO, 0); //{ 0, 0, 0, 0,} 00072 static _EIGEN_DECLARE_CONST_FAST_Packet4i(ONE,1); //{ 1, 1, 1, 1} 00073 static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS16,-16); //{ -16, -16, -16, -16} 00074 static _EIGEN_DECLARE_CONST_FAST_Packet4i(MINUS1,-1); //{ -1, -1, -1, -1} 00075 static Packet4f p4f_MZERO = (Packet4f) vec_sl((Packet4ui)p4i_MINUS1, (Packet4ui)p4i_MINUS1); //{ 0x80000000, 0x80000000, 0x80000000, 0x80000000} 00076 #ifndef __VSX__ 00077 static Packet4f p4f_ONE = vec_ctf(p4i_ONE, 0); //{ 1.0, 1.0, 1.0, 1.0} 00078 #endif 00079 00080 static Packet4f p4f_COUNTDOWN = { 0.0, 1.0, 2.0, 3.0 }; 00081 static Packet4i p4i_COUNTDOWN = { 0, 1, 2, 3 }; 00082 00083 static Packet16uc p16uc_REVERSE32 = { 12,13,14,15, 8,9,10,11, 4,5,6,7, 0,1,2,3 }; 00084 static Packet16uc p16uc_DUPLICATE32_HI = { 0,1,2,3, 0,1,2,3, 4,5,6,7, 4,5,6,7 }; 00085 00086 // Mask alignment 00087 #ifdef __PPC64__ 00088 #define _EIGEN_MASK_ALIGNMENT 0xfffffffffffffff0 00089 #else 00090 #define _EIGEN_MASK_ALIGNMENT 0xfffffff0 00091 #endif 00092 00093 #define _EIGEN_ALIGNED_PTR(x) ((std::ptrdiff_t)(x) & _EIGEN_MASK_ALIGNMENT) 00094 00095 // Handle endianness properly while loading constants 00096 // Define global static constants: 00097 #ifdef _BIG_ENDIAN 00098 static Packet16uc p16uc_FORWARD = vec_lvsl(0, (float*)0); 00099 #ifdef __VSX__ 00100 static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; 00101 #endif 00102 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 }; 00103 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 }; 00104 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}; 00105 #else 00106 static Packet16uc p16uc_FORWARD = p16uc_REVERSE32; 00107 static Packet16uc p16uc_REVERSE64 = { 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; 00108 static Packet16uc p16uc_PSET32_WODD = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 1), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 3), 8);//{ 0,1,2,3, 0,1,2,3, 8,9,10,11, 8,9,10,11 }; 00109 static Packet16uc p16uc_PSET32_WEVEN = vec_sld((Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 0), (Packet16uc) vec_splat((Packet4ui)p16uc_FORWARD, 2), 8);//{ 4,5,6,7, 4,5,6,7, 12,13,14,15, 12,13,14,15 }; 00110 static Packet16uc p16uc_HALF64_0_16 = vec_sld(vec_splat((Packet16uc) vec_abs(p4i_MINUS16), 0), (Packet16uc)p4i_ZERO, 8); //{ 0,0,0,0, 0,0,0,0, 16,16,16,16, 16,16,16,16}; 00111 #endif // _BIG_ENDIAN 00112 00113 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 }; 00114 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 }; 00115 static Packet16uc p16uc_TRANSPOSE64_HI = p16uc_PSET64_HI + p16uc_HALF64_0_16; //{ 0,1,2,3, 4,5,6,7, 16,17,18,19, 20,21,22,23}; 00116 static Packet16uc p16uc_TRANSPOSE64_LO = p16uc_PSET64_LO + p16uc_HALF64_0_16; //{ 8,9,10,11, 12,13,14,15, 24,25,26,27, 28,29,30,31}; 00117 00118 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 }; 00119 00120 #ifdef _BIG_ENDIAN 00121 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 }; 00122 #else 00123 static Packet16uc p16uc_COMPLEX32_REV2 = vec_sld(p16uc_PSET64_HI, p16uc_PSET64_LO, 8); //{ 8,9,10,11, 12,13,14,15, 0,1,2,3, 4,5,6,7 }; 00124 #endif // _BIG_ENDIAN 00125 00126 #if EIGEN_HAS_BUILTIN(__builtin_prefetch) || EIGEN_COMP_GNUC 00127 #define EIGEN_PPC_PREFETCH(ADDR) __builtin_prefetch(ADDR); 00128 #else 00129 #define EIGEN_PPC_PREFETCH(ADDR) asm( " dcbt [%[addr]]\n" :: [addr] "r" (ADDR) : "cc" ); 00130 #endif 00131 00132 template<> struct packet_traits<float> : default_packet_traits 00133 { 00134 typedef Packet4f type; 00135 typedef Packet4f half; 00136 enum { 00137 Vectorizable = 1, 00138 AlignedOnScalar = 1, 00139 size=4, 00140 HasHalfPacket = 1, 00141 00142 HasAdd = 1, 00143 HasSub = 1, 00144 HasMul = 1, 00145 HasDiv = 1, 00146 HasMin = 1, 00147 HasMax = 1, 00148 HasAbs = 1, 00149 HasSin = 0, 00150 HasCos = 0, 00151 HasLog = 0, 00152 HasExp = 1, 00153 #ifdef __VSX__ 00154 HasSqrt = 1, 00155 #if !EIGEN_COMP_CLANG 00156 HasRsqrt = 1, 00157 #else 00158 HasRsqrt = 0, 00159 #endif 00160 #else 00161 HasSqrt = 0, 00162 HasRsqrt = 0, 00163 #endif 00164 HasRound = 1, 00165 HasFloor = 1, 00166 HasCeil = 1, 00167 HasNegate = 1, 00168 HasBlend = 1 00169 }; 00170 }; 00171 template<> struct packet_traits<int> : default_packet_traits 00172 { 00173 typedef Packet4i type; 00174 typedef Packet4i half; 00175 enum { 00176 Vectorizable = 1, 00177 AlignedOnScalar = 1, 00178 size = 4, 00179 HasHalfPacket = 0, 00180 00181 HasAdd = 1, 00182 HasSub = 1, 00183 HasMul = 1, 00184 HasDiv = 0, 00185 HasBlend = 1 00186 }; 00187 }; 00188 00189 00190 template<> struct unpacket_traits<Packet4f> { typedef float type; enum {size=4, alignment=Aligned16}; typedef Packet4f half; }; 00191 template<> struct unpacket_traits<Packet4i> { typedef int type; enum {size=4, alignment=Aligned16}; typedef Packet4i half; }; 00192 00193 inline std::ostream & operator <<(std::ostream & s, const Packet16uc & v) 00194 { 00195 union { 00196 Packet16uc v; 00197 unsigned char n[16]; 00198 } vt; 00199 vt.v = v; 00200 for (int i=0; i< 16; i++) 00201 s << (int)vt.n[i] << ", "; 00202 return s; 00203 } 00204 00205 inline std::ostream & operator <<(std::ostream & s, const Packet4f & v) 00206 { 00207 union { 00208 Packet4f v; 00209 float n[4]; 00210 } vt; 00211 vt.v = v; 00212 s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; 00213 return s; 00214 } 00215 00216 inline std::ostream & operator <<(std::ostream & s, const Packet4i & v) 00217 { 00218 union { 00219 Packet4i v; 00220 int n[4]; 00221 } vt; 00222 vt.v = v; 00223 s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; 00224 return s; 00225 } 00226 00227 inline std::ostream & operator <<(std::ostream & s, const Packet4ui & v) 00228 { 00229 union { 00230 Packet4ui v; 00231 unsigned int n[4]; 00232 } vt; 00233 vt.v = v; 00234 s << vt.n[0] << ", " << vt.n[1] << ", " << vt.n[2] << ", " << vt.n[3]; 00235 return s; 00236 } 00237 00238 // Need to define them first or we get specialization after instantiation errors 00239 template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) 00240 { 00241 EIGEN_DEBUG_ALIGNED_LOAD 00242 #ifdef __VSX__ 00243 return vec_vsx_ld(0, from); 00244 #else 00245 return vec_ld(0, from); 00246 #endif 00247 } 00248 00249 template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) 00250 { 00251 EIGEN_DEBUG_ALIGNED_LOAD 00252 #ifdef __VSX__ 00253 return vec_vsx_ld(0, from); 00254 #else 00255 return vec_ld(0, from); 00256 #endif 00257 } 00258 00259 template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) 00260 { 00261 EIGEN_DEBUG_ALIGNED_STORE 00262 #ifdef __VSX__ 00263 vec_vsx_st(from, 0, to); 00264 #else 00265 vec_st(from, 0, to); 00266 #endif 00267 } 00268 00269 template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) 00270 { 00271 EIGEN_DEBUG_ALIGNED_STORE 00272 #ifdef __VSX__ 00273 vec_vsx_st(from, 0, to); 00274 #else 00275 vec_st(from, 0, to); 00276 #endif 00277 } 00278 00279 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { 00280 Packet4f v = {from, from, from, from}; 00281 return v; 00282 } 00283 00284 template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { 00285 Packet4i v = {from, from, from, from}; 00286 return v; 00287 } 00288 template<> EIGEN_STRONG_INLINE void 00289 pbroadcast4<Packet4f>(const float *a, 00290 Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) 00291 { 00292 a3 = pload<Packet4f>(a); 00293 a0 = vec_splat(a3, 0); 00294 a1 = vec_splat(a3, 1); 00295 a2 = vec_splat(a3, 2); 00296 a3 = vec_splat(a3, 3); 00297 } 00298 template<> EIGEN_STRONG_INLINE void 00299 pbroadcast4<Packet4i>(const int *a, 00300 Packet4i& a0, Packet4i& a1, Packet4i& a2, Packet4i& a3) 00301 { 00302 a3 = pload<Packet4i>(a); 00303 a0 = vec_splat(a3, 0); 00304 a1 = vec_splat(a3, 1); 00305 a2 = vec_splat(a3, 2); 00306 a3 = vec_splat(a3, 3); 00307 } 00308 00309 template<> EIGEN_DEVICE_FUNC inline Packet4f pgather<float, Packet4f>(const float* from, Index stride) 00310 { 00311 float EIGEN_ALIGN16 af[4]; 00312 af[0] = from[0*stride]; 00313 af[1] = from[1*stride]; 00314 af[2] = from[2*stride]; 00315 af[3] = from[3*stride]; 00316 return pload<Packet4f>(af); 00317 } 00318 template<> EIGEN_DEVICE_FUNC inline Packet4i pgather<int, Packet4i>(const int* from, Index stride) 00319 { 00320 int EIGEN_ALIGN16 ai[4]; 00321 ai[0] = from[0*stride]; 00322 ai[1] = from[1*stride]; 00323 ai[2] = from[2*stride]; 00324 ai[3] = from[3*stride]; 00325 return pload<Packet4i>(ai); 00326 } 00327 template<> EIGEN_DEVICE_FUNC inline void pscatter<float, Packet4f>(float* to, const Packet4f& from, Index stride) 00328 { 00329 float EIGEN_ALIGN16 af[4]; 00330 pstore<float>(af, from); 00331 to[0*stride] = af[0]; 00332 to[1*stride] = af[1]; 00333 to[2*stride] = af[2]; 00334 to[3*stride] = af[3]; 00335 } 00336 template<> EIGEN_DEVICE_FUNC inline void pscatter<int, Packet4i>(int* to, const Packet4i& from, Index stride) 00337 { 00338 int EIGEN_ALIGN16 ai[4]; 00339 pstore<int>((int *)ai, from); 00340 to[0*stride] = ai[0]; 00341 to[1*stride] = ai[1]; 00342 to[2*stride] = ai[2]; 00343 to[3*stride] = ai[3]; 00344 } 00345 00346 template<> EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(const float& a) { return pset1<Packet4f>(a) + p4f_COUNTDOWN; } 00347 template<> EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(const int& a) { return pset1<Packet4i>(a) + p4i_COUNTDOWN; } 00348 00349 template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return a + b; } 00350 template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return a + b; } 00351 00352 template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return a - b; } 00353 template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return a - b; } 00354 00355 template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return p4f_ZERO - a; } 00356 template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return p4i_ZERO - a; } 00357 00358 template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } 00359 template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } 00360 00361 template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_madd(a,b, p4f_MZERO); } 00362 template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b) { return a * b; } 00363 00364 template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) 00365 { 00366 #ifndef __VSX__ // VSX actually provides a div instruction 00367 Packet4f t, y_0, y_1; 00368 00369 // Altivec does not offer a divide instruction, we have to do a reciprocal approximation 00370 y_0 = vec_re(b); 00371 00372 // Do one Newton-Raphson iteration to get the needed accuracy 00373 t = vec_nmsub(y_0, b, p4f_ONE); 00374 y_1 = vec_madd(y_0, t, y_0); 00375 00376 return vec_madd(a, y_1, p4f_MZERO); 00377 #else 00378 return vec_div(a, b); 00379 #endif 00380 } 00381 00382 template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& /*a*/, const Packet4i& /*b*/) 00383 { eigen_assert(false && "packet integer division are not supported by AltiVec"); 00384 return pset1<Packet4i>(0); 00385 } 00386 00387 // for some weird raisons, it has to be overloaded for packet of integers 00388 template<> EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f& a, const Packet4f& b, const Packet4f& c) { return vec_madd(a,b,c); } 00389 template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return a*b + c; } 00390 00391 template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_min(a, b); } 00392 template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_min(a, b); } 00393 00394 template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_max(a, b); } 00395 template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_max(a, b); } 00396 00397 template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, b); } 00398 template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, b); } 00399 00400 template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_or(a, b); } 00401 template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_or(a, b); } 00402 00403 template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_xor(a, b); } 00404 template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_xor(a, b); } 00405 00406 template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return vec_and(a, vec_nor(b, b)); } 00407 template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, vec_nor(b, b)); } 00408 00409 template<> EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) { return vec_round(a); } 00410 template<> EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) { return vec_ceil(a); } 00411 template<> EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) { return vec_floor(a); } 00412 00413 #ifdef _BIG_ENDIAN 00414 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) 00415 { 00416 EIGEN_DEBUG_ALIGNED_LOAD 00417 Packet16uc MSQ, LSQ; 00418 Packet16uc mask; 00419 MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword 00420 LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword 00421 mask = vec_lvsl(0, from); // create the permute mask 00422 return (Packet4f) vec_perm(MSQ, LSQ, mask); // align the data 00423 00424 } 00425 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) 00426 { 00427 EIGEN_DEBUG_ALIGNED_LOAD 00428 // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html 00429 Packet16uc MSQ, LSQ; 00430 Packet16uc mask; 00431 MSQ = vec_ld(0, (unsigned char *)from); // most significant quadword 00432 LSQ = vec_ld(15, (unsigned char *)from); // least significant quadword 00433 mask = vec_lvsl(0, from); // create the permute mask 00434 return (Packet4i) vec_perm(MSQ, LSQ, mask); // align the data 00435 } 00436 #else 00437 // We also need ot redefine little endian loading of Packet4i/Packet4f using VSX 00438 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) 00439 { 00440 EIGEN_DEBUG_UNALIGNED_LOAD 00441 return (Packet4i) vec_vsx_ld((long)from & 15, (const int*) _EIGEN_ALIGNED_PTR(from)); 00442 } 00443 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) 00444 { 00445 EIGEN_DEBUG_UNALIGNED_LOAD 00446 return (Packet4f) vec_vsx_ld((long)from & 15, (const float*) _EIGEN_ALIGNED_PTR(from)); 00447 } 00448 #endif 00449 00450 template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from) 00451 { 00452 Packet4f p; 00453 if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet4f>(from); 00454 else p = ploadu<Packet4f>(from); 00455 return vec_perm(p, p, p16uc_DUPLICATE32_HI); 00456 } 00457 template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from) 00458 { 00459 Packet4i p; 00460 if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet4i>(from); 00461 else p = ploadu<Packet4i>(from); 00462 return vec_perm(p, p, p16uc_DUPLICATE32_HI); 00463 } 00464 00465 #ifdef _BIG_ENDIAN 00466 template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) 00467 { 00468 EIGEN_DEBUG_UNALIGNED_STORE 00469 // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html 00470 // Warning: not thread safe! 00471 Packet16uc MSQ, LSQ, edges; 00472 Packet16uc edgeAlign, align; 00473 00474 MSQ = vec_ld(0, (unsigned char *)to); // most significant quadword 00475 LSQ = vec_ld(15, (unsigned char *)to); // least significant quadword 00476 edgeAlign = vec_lvsl(0, to); // permute map to extract edges 00477 edges=vec_perm(LSQ,MSQ,edgeAlign); // extract the edges 00478 align = vec_lvsr( 0, to ); // permute map to misalign data 00479 MSQ = vec_perm(edges,(Packet16uc)from,align); // misalign the data (MSQ) 00480 LSQ = vec_perm((Packet16uc)from,edges,align); // misalign the data (LSQ) 00481 vec_st( LSQ, 15, (unsigned char *)to ); // Store the LSQ part first 00482 vec_st( MSQ, 0, (unsigned char *)to ); // Store the MSQ part 00483 } 00484 template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) 00485 { 00486 EIGEN_DEBUG_UNALIGNED_STORE 00487 // Taken from http://developer.apple.com/hardwaredrivers/ve/alignment.html 00488 // Warning: not thread safe! 00489 Packet16uc MSQ, LSQ, edges; 00490 Packet16uc edgeAlign, align; 00491 00492 MSQ = vec_ld(0, (unsigned char *)to); // most significant quadword 00493 LSQ = vec_ld(15, (unsigned char *)to); // least significant quadword 00494 edgeAlign = vec_lvsl(0, to); // permute map to extract edges 00495 edges=vec_perm(LSQ, MSQ, edgeAlign); // extract the edges 00496 align = vec_lvsr( 0, to ); // permute map to misalign data 00497 MSQ = vec_perm(edges, (Packet16uc) from, align); // misalign the data (MSQ) 00498 LSQ = vec_perm((Packet16uc) from, edges, align); // misalign the data (LSQ) 00499 vec_st( LSQ, 15, (unsigned char *)to ); // Store the LSQ part first 00500 vec_st( MSQ, 0, (unsigned char *)to ); // Store the MSQ part 00501 } 00502 #else 00503 // We also need ot redefine little endian loading of Packet4i/Packet4f using VSX 00504 template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) 00505 { 00506 EIGEN_DEBUG_ALIGNED_STORE 00507 vec_vsx_st(from, (long)to & 15, (int*) _EIGEN_ALIGNED_PTR(to)); 00508 } 00509 template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) 00510 { 00511 EIGEN_DEBUG_ALIGNED_STORE 00512 vec_vsx_st(from, (long)to & 15, (float*) _EIGEN_ALIGNED_PTR(to)); 00513 } 00514 #endif 00515 00516 template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { EIGEN_PPC_PREFETCH(addr); } 00517 template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { EIGEN_PPC_PREFETCH(addr); } 00518 00519 template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float EIGEN_ALIGN16 x; vec_ste(a, 0, &x); return x; } 00520 template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int EIGEN_ALIGN16 x; vec_ste(a, 0, &x); return x; } 00521 00522 template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a) 00523 { 00524 return reinterpret_cast<Packet4f>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); 00525 } 00526 template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a) 00527 { 00528 return reinterpret_cast<Packet4i>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE32)); } 00529 00530 template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a) { return vec_abs(a); } 00531 template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a) { return vec_abs(a); } 00532 00533 template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a) 00534 { 00535 Packet4f b, sum; 00536 b = vec_sld(a, a, 8); 00537 sum = a + b; 00538 b = vec_sld(sum, sum, 4); 00539 sum += b; 00540 return pfirst(sum); 00541 } 00542 00543 template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs) 00544 { 00545 Packet4f v[4], sum[4]; 00546 00547 // It's easier and faster to transpose then add as columns 00548 // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation 00549 // Do the transpose, first set of moves 00550 v[0] = vec_mergeh(vecs[0], vecs[2]); 00551 v[1] = vec_mergel(vecs[0], vecs[2]); 00552 v[2] = vec_mergeh(vecs[1], vecs[3]); 00553 v[3] = vec_mergel(vecs[1], vecs[3]); 00554 // Get the resulting vectors 00555 sum[0] = vec_mergeh(v[0], v[2]); 00556 sum[1] = vec_mergel(v[0], v[2]); 00557 sum[2] = vec_mergeh(v[1], v[3]); 00558 sum[3] = vec_mergel(v[1], v[3]); 00559 00560 // Now do the summation: 00561 // Lines 0+1 00562 sum[0] = sum[0] + sum[1]; 00563 // Lines 2+3 00564 sum[1] = sum[2] + sum[3]; 00565 // Add the results 00566 sum[0] = sum[0] + sum[1]; 00567 00568 return sum[0]; 00569 } 00570 00571 template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a) 00572 { 00573 Packet4i sum; 00574 sum = vec_sums(a, p4i_ZERO); 00575 #ifdef _BIG_ENDIAN 00576 sum = vec_sld(sum, p4i_ZERO, 12); 00577 #else 00578 sum = vec_sld(p4i_ZERO, sum, 4); 00579 #endif 00580 return pfirst(sum); 00581 } 00582 00583 template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs) 00584 { 00585 Packet4i v[4], sum[4]; 00586 00587 // It's easier and faster to transpose then add as columns 00588 // Check: http://www.freevec.org/function/matrix_4x4_transpose_floats for explanation 00589 // Do the transpose, first set of moves 00590 v[0] = vec_mergeh(vecs[0], vecs[2]); 00591 v[1] = vec_mergel(vecs[0], vecs[2]); 00592 v[2] = vec_mergeh(vecs[1], vecs[3]); 00593 v[3] = vec_mergel(vecs[1], vecs[3]); 00594 // Get the resulting vectors 00595 sum[0] = vec_mergeh(v[0], v[2]); 00596 sum[1] = vec_mergel(v[0], v[2]); 00597 sum[2] = vec_mergeh(v[1], v[3]); 00598 sum[3] = vec_mergel(v[1], v[3]); 00599 00600 // Now do the summation: 00601 // Lines 0+1 00602 sum[0] = sum[0] + sum[1]; 00603 // Lines 2+3 00604 sum[1] = sum[2] + sum[3]; 00605 // Add the results 00606 sum[0] = sum[0] + sum[1]; 00607 00608 return sum[0]; 00609 } 00610 00611 // Other reduction functions: 00612 // mul 00613 template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a) 00614 { 00615 Packet4f prod; 00616 prod = pmul(a, vec_sld(a, a, 8)); 00617 return pfirst(pmul(prod, vec_sld(prod, prod, 4))); 00618 } 00619 00620 template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a) 00621 { 00622 EIGEN_ALIGN16 int aux[4]; 00623 pstore(aux, a); 00624 return aux[0] * aux[1] * aux[2] * aux[3]; 00625 } 00626 00627 // min 00628 template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a) 00629 { 00630 Packet4f b, res; 00631 b = vec_min(a, vec_sld(a, a, 8)); 00632 res = vec_min(b, vec_sld(b, b, 4)); 00633 return pfirst(res); 00634 } 00635 00636 template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a) 00637 { 00638 Packet4i b, res; 00639 b = vec_min(a, vec_sld(a, a, 8)); 00640 res = vec_min(b, vec_sld(b, b, 4)); 00641 return pfirst(res); 00642 } 00643 00644 // max 00645 template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a) 00646 { 00647 Packet4f b, res; 00648 b = vec_max(a, vec_sld(a, a, 8)); 00649 res = vec_max(b, vec_sld(b, b, 4)); 00650 return pfirst(res); 00651 } 00652 00653 template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a) 00654 { 00655 Packet4i b, res; 00656 b = vec_max(a, vec_sld(a, a, 8)); 00657 res = vec_max(b, vec_sld(b, b, 4)); 00658 return pfirst(res); 00659 } 00660 00661 template<int Offset> 00662 struct palign_impl<Offset,Packet4f> 00663 { 00664 static EIGEN_STRONG_INLINE void run(Packet4f& first, const Packet4f& second) 00665 { 00666 #ifdef _BIG_ENDIAN 00667 switch (Offset % 4) { 00668 case 1: 00669 first = vec_sld(first, second, 4); break; 00670 case 2: 00671 first = vec_sld(first, second, 8); break; 00672 case 3: 00673 first = vec_sld(first, second, 12); break; 00674 } 00675 #else 00676 switch (Offset % 4) { 00677 case 1: 00678 first = vec_sld(second, first, 12); break; 00679 case 2: 00680 first = vec_sld(second, first, 8); break; 00681 case 3: 00682 first = vec_sld(second, first, 4); break; 00683 } 00684 #endif 00685 } 00686 }; 00687 00688 template<int Offset> 00689 struct palign_impl<Offset,Packet4i> 00690 { 00691 static EIGEN_STRONG_INLINE void run(Packet4i& first, const Packet4i& second) 00692 { 00693 #ifdef _BIG_ENDIAN 00694 switch (Offset % 4) { 00695 case 1: 00696 first = vec_sld(first, second, 4); break; 00697 case 2: 00698 first = vec_sld(first, second, 8); break; 00699 case 3: 00700 first = vec_sld(first, second, 12); break; 00701 } 00702 #else 00703 switch (Offset % 4) { 00704 case 1: 00705 first = vec_sld(second, first, 12); break; 00706 case 2: 00707 first = vec_sld(second, first, 8); break; 00708 case 3: 00709 first = vec_sld(second, first, 4); break; 00710 } 00711 #endif 00712 } 00713 }; 00714 00715 EIGEN_DEVICE_FUNC inline void 00716 ptranspose(PacketBlock<Packet4f,4>& kernel) { 00717 Packet4f t0, t1, t2, t3; 00718 t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); 00719 t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); 00720 t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); 00721 t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); 00722 kernel.packet[0] = vec_mergeh(t0, t2); 00723 kernel.packet[1] = vec_mergel(t0, t2); 00724 kernel.packet[2] = vec_mergeh(t1, t3); 00725 kernel.packet[3] = vec_mergel(t1, t3); 00726 } 00727 00728 EIGEN_DEVICE_FUNC inline void 00729 ptranspose(PacketBlock<Packet4i,4>& kernel) { 00730 Packet4i t0, t1, t2, t3; 00731 t0 = vec_mergeh(kernel.packet[0], kernel.packet[2]); 00732 t1 = vec_mergel(kernel.packet[0], kernel.packet[2]); 00733 t2 = vec_mergeh(kernel.packet[1], kernel.packet[3]); 00734 t3 = vec_mergel(kernel.packet[1], kernel.packet[3]); 00735 kernel.packet[0] = vec_mergeh(t0, t2); 00736 kernel.packet[1] = vec_mergel(t0, t2); 00737 kernel.packet[2] = vec_mergeh(t1, t3); 00738 kernel.packet[3] = vec_mergel(t1, t3); 00739 } 00740 00741 template<> EIGEN_STRONG_INLINE Packet4i pblend(const Selector<4>& ifPacket, const Packet4i& thenPacket, const Packet4i& elsePacket) { 00742 Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; 00743 Packet4ui mask = reinterpret_cast<Packet4ui>(vec_cmpeq(reinterpret_cast<Packet4ui>(select), reinterpret_cast<Packet4ui>(p4i_ONE))); 00744 return vec_sel(elsePacket, thenPacket, mask); 00745 } 00746 00747 template<> EIGEN_STRONG_INLINE Packet4f pblend(const Selector<4>& ifPacket, const Packet4f& thenPacket, const Packet4f& elsePacket) { 00748 Packet4ui select = { ifPacket.select[0], ifPacket.select[1], ifPacket.select[2], ifPacket.select[3] }; 00749 Packet4ui mask = reinterpret_cast<Packet4ui>(vec_cmpeq(reinterpret_cast<Packet4ui>(select), reinterpret_cast<Packet4ui>(p4i_ONE))); 00750 return vec_sel(elsePacket, thenPacket, mask); 00751 } 00752 00753 00754 //---------- double ---------- 00755 #ifdef __VSX__ 00756 typedef __vector double Packet2d; 00757 typedef __vector unsigned long long Packet2ul; 00758 typedef __vector long long Packet2l; 00759 #if EIGEN_COMP_CLANG 00760 typedef Packet2ul Packet2bl; 00761 #else 00762 typedef __vector __bool long Packet2bl; 00763 #endif 00764 00765 static Packet2l p2l_ONE = { 1, 1 }; 00766 static Packet2l p2l_ZERO = reinterpret_cast<Packet2l>(p4i_ZERO); 00767 static Packet2d p2d_ONE = { 1.0, 1.0 }; 00768 static Packet2d p2d_ZERO = reinterpret_cast<Packet2d>(p4f_ZERO); 00769 static Packet2d p2d_MZERO = { -0.0, -0.0 }; 00770 00771 #ifdef _BIG_ENDIAN 00772 static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(p2d_ZERO), reinterpret_cast<Packet4f>(p2d_ONE), 8)); 00773 #else 00774 static Packet2d p2d_COUNTDOWN = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(p2d_ONE), reinterpret_cast<Packet4f>(p2d_ZERO), 8)); 00775 #endif 00776 00777 template<int index> Packet2d vec_splat_dbl(Packet2d& a); 00778 00779 template<> EIGEN_STRONG_INLINE Packet2d vec_splat_dbl<0>(Packet2d& a) 00780 { 00781 return reinterpret_cast<Packet2d>(vec_perm(a, a, p16uc_PSET64_HI)); 00782 } 00783 00784 template<> EIGEN_STRONG_INLINE Packet2d vec_splat_dbl<1>(Packet2d& a) 00785 { 00786 return reinterpret_cast<Packet2d>(vec_perm(a, a, p16uc_PSET64_LO)); 00787 } 00788 00789 template<> struct packet_traits<double> : default_packet_traits 00790 { 00791 typedef Packet2d type; 00792 typedef Packet2d half; 00793 enum { 00794 Vectorizable = 1, 00795 AlignedOnScalar = 1, 00796 size=2, 00797 HasHalfPacket = 1, 00798 00799 HasAdd = 1, 00800 HasSub = 1, 00801 HasMul = 1, 00802 HasDiv = 1, 00803 HasMin = 1, 00804 HasMax = 1, 00805 HasAbs = 1, 00806 HasSin = 0, 00807 HasCos = 0, 00808 HasLog = 0, 00809 HasExp = 1, 00810 HasSqrt = 1, 00811 HasRsqrt = 1, 00812 HasRound = 1, 00813 HasFloor = 1, 00814 HasCeil = 1, 00815 HasNegate = 1, 00816 HasBlend = 1 00817 }; 00818 }; 00819 00820 template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2, alignment=Aligned16}; typedef Packet2d half; }; 00821 00822 inline std::ostream & operator <<(std::ostream & s, const Packet2l & v) 00823 { 00824 union { 00825 Packet2l v; 00826 int64_t n[2]; 00827 } vt; 00828 vt.v = v; 00829 s << vt.n[0] << ", " << vt.n[1]; 00830 return s; 00831 } 00832 00833 inline std::ostream & operator <<(std::ostream & s, const Packet2d & v) 00834 { 00835 union { 00836 Packet2d v; 00837 double n[2]; 00838 } vt; 00839 vt.v = v; 00840 s << vt.n[0] << ", " << vt.n[1]; 00841 return s; 00842 } 00843 00844 // Need to define them first or we get specialization after instantiation errors 00845 template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) 00846 { 00847 EIGEN_DEBUG_ALIGNED_LOAD 00848 #ifdef __VSX__ 00849 return vec_vsx_ld(0, from); 00850 #else 00851 return vec_ld(0, from); 00852 #endif 00853 } 00854 00855 template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) 00856 { 00857 EIGEN_DEBUG_ALIGNED_STORE 00858 #ifdef __VSX__ 00859 vec_vsx_st(from, 0, to); 00860 #else 00861 vec_st(from, 0, to); 00862 #endif 00863 } 00864 00865 template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { 00866 Packet2d v = {from, from}; 00867 return v; 00868 } 00869 00870 template<> EIGEN_STRONG_INLINE void 00871 pbroadcast4<Packet2d>(const double *a, 00872 Packet2d& a0, Packet2d& a1, Packet2d& a2, Packet2d& a3) 00873 { 00874 a1 = pload<Packet2d>(a); 00875 a0 = vec_splat_dbl<0>(a1); 00876 a1 = vec_splat_dbl<1>(a1); 00877 a3 = pload<Packet2d>(a+2); 00878 a2 = vec_splat_dbl<0>(a3); 00879 a3 = vec_splat_dbl<1>(a3); 00880 } 00881 00882 template<> EIGEN_DEVICE_FUNC inline Packet2d pgather<double, Packet2d>(const double* from, Index stride) 00883 { 00884 double EIGEN_ALIGN16 af[2]; 00885 af[0] = from[0*stride]; 00886 af[1] = from[1*stride]; 00887 return pload<Packet2d>(af); 00888 } 00889 template<> EIGEN_DEVICE_FUNC inline void pscatter<double, Packet2d>(double* to, const Packet2d& from, Index stride) 00890 { 00891 double EIGEN_ALIGN16 af[2]; 00892 pstore<double>(af, from); 00893 to[0*stride] = af[0]; 00894 to[1*stride] = af[1]; 00895 } 00896 00897 template<> EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(const double& a) { return pset1<Packet2d>(a) + p2d_COUNTDOWN; } 00898 00899 template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return a + b; } 00900 00901 template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return a - b; } 00902 00903 template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a) { return p2d_ZERO - a; } 00904 00905 template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } 00906 00907 template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_madd(a,b,p2d_MZERO); } 00908 template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_div(a,b); } 00909 00910 // for some weird raisons, it has to be overloaded for packet of integers 00911 template<> EIGEN_STRONG_INLINE Packet2d pmadd(const Packet2d& a, const Packet2d& b, const Packet2d& c) { return vec_madd(a, b, c); } 00912 00913 template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_min(a, b); } 00914 00915 template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_max(a, b); } 00916 00917 template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, b); } 00918 00919 template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_or(a, b); } 00920 00921 template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_xor(a, b); } 00922 00923 template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return vec_and(a, vec_nor(b, b)); } 00924 00925 template<> EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) { return vec_round(a); } 00926 template<> EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) { return vec_ceil(a); } 00927 template<> EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(const Packet2d& a) { return vec_floor(a); } 00928 00929 template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) 00930 { 00931 EIGEN_DEBUG_ALIGNED_LOAD 00932 return (Packet2d) vec_vsx_ld((long)from & 15, (const double*) _EIGEN_ALIGNED_PTR(from)); 00933 } 00934 00935 template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from) 00936 { 00937 Packet2d p; 00938 if((std::ptrdiff_t(from) % 16) == 0) p = pload<Packet2d>(from); 00939 else p = ploadu<Packet2d>(from); 00940 return vec_splat_dbl<0>(p); 00941 } 00942 00943 template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) 00944 { 00945 EIGEN_DEBUG_ALIGNED_STORE 00946 vec_vsx_st((Packet4f)from, (long)to & 15, (float*) _EIGEN_ALIGNED_PTR(to)); 00947 } 00948 00949 template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { EIGEN_PPC_PREFETCH(addr); } 00950 00951 template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double EIGEN_ALIGN16 x[2]; pstore<double>(x, a); return x[0]; } 00952 00953 template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a) 00954 { 00955 return reinterpret_cast<Packet2d>(vec_perm(reinterpret_cast<Packet16uc>(a), reinterpret_cast<Packet16uc>(a), p16uc_REVERSE64)); 00956 } 00957 template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a) { return vec_abs(a); } 00958 00959 template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) 00960 { 00961 Packet2d b, sum; 00962 b = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(a), reinterpret_cast<Packet4f>(a), 8)); 00963 sum = a + b; 00964 return pfirst<Packet2d>(sum); 00965 } 00966 00967 template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs) 00968 { 00969 Packet2d v[2], sum; 00970 v[0] = vecs[0] + reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(vecs[0]), reinterpret_cast<Packet4f>(vecs[0]), 8)); 00971 v[1] = vecs[1] + reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(vecs[1]), reinterpret_cast<Packet4f>(vecs[1]), 8)); 00972 00973 #ifdef _BIG_ENDIAN 00974 sum = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(v[0]), reinterpret_cast<Packet4f>(v[1]), 8)); 00975 #else 00976 sum = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4f>(v[1]), reinterpret_cast<Packet4f>(v[0]), 8)); 00977 #endif 00978 00979 return sum; 00980 } 00981 // Other reduction functions: 00982 // mul 00983 template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a) 00984 { 00985 return pfirst(pmul(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8)))); 00986 } 00987 00988 // min 00989 template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a) 00990 { 00991 return pfirst(pmin(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8)))); 00992 } 00993 00994 // max 00995 template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a) 00996 { 00997 return pfirst(pmax(a, reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(a), reinterpret_cast<Packet4ui>(a), 8)))); 00998 } 00999 01000 template<int Offset> 01001 struct palign_impl<Offset,Packet2d> 01002 { 01003 static EIGEN_STRONG_INLINE void run(Packet2d& first, const Packet2d& second) 01004 { 01005 if (Offset == 1) 01006 #ifdef _BIG_ENDIAN 01007 first = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(first), reinterpret_cast<Packet4ui>(second), 8)); 01008 #else 01009 first = reinterpret_cast<Packet2d>(vec_sld(reinterpret_cast<Packet4ui>(second), reinterpret_cast<Packet4ui>(first), 8)); 01010 #endif 01011 } 01012 }; 01013 01014 EIGEN_DEVICE_FUNC inline void 01015 ptranspose(PacketBlock<Packet2d,2>& kernel) { 01016 Packet2d t0, t1; 01017 t0 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_HI); 01018 t1 = vec_perm(kernel.packet[0], kernel.packet[1], p16uc_TRANSPOSE64_LO); 01019 kernel.packet[0] = t0; 01020 kernel.packet[1] = t1; 01021 } 01022 01023 template<> EIGEN_STRONG_INLINE Packet2d pblend(const Selector<2>& ifPacket, const Packet2d& thenPacket, const Packet2d& elsePacket) { 01024 Packet2l select = { ifPacket.select[0], ifPacket.select[1] }; 01025 Packet2bl mask = vec_cmpeq(reinterpret_cast<Packet2d>(select), reinterpret_cast<Packet2d>(p2l_ONE)); 01026 return vec_sel(elsePacket, thenPacket, mask); 01027 } 01028 #endif // __VSX__ 01029 } // end namespace internal 01030 01031 } // end namespace Eigen 01032 01033 #endif // EIGEN_PACKET_MATH_ALTIVEC_H