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_PACKET_MATH_SSE_H
00026 #define EIGEN_PACKET_MATH_SSE_H
00027
00028 namespace internal {
00029
00030 #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
00031 #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
00032 #endif
00033
00034 #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS
00035 #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS (2*sizeof(void*))
00036 #endif
00037
00038 typedef __m128 Packet4f;
00039 typedef __m128i Packet4i;
00040 typedef __m128d Packet2d;
00041
00042 template<> struct is_arithmetic<__m128> { enum { value = true }; };
00043 template<> struct is_arithmetic<__m128i> { enum { value = true }; };
00044 template<> struct is_arithmetic<__m128d> { enum { value = true }; };
00045
00046 #define vec4f_swizzle1(v,p,q,r,s) \
00047 (_mm_castsi128_ps(_mm_shuffle_epi32( _mm_castps_si128(v), ((s)<<6|(r)<<4|(q)<<2|(p)))))
00048
00049 #define vec4i_swizzle1(v,p,q,r,s) \
00050 (_mm_shuffle_epi32( v, ((s)<<6|(r)<<4|(q)<<2|(p))))
00051
00052 #define vec2d_swizzle1(v,p,q) \
00053 (_mm_castsi128_pd(_mm_shuffle_epi32( _mm_castpd_si128(v), ((q*2+1)<<6|(q*2)<<4|(p*2+1)<<2|(p*2)))))
00054
00055 #define vec4f_swizzle2(a,b,p,q,r,s) \
00056 (_mm_shuffle_ps( (a), (b), ((s)<<6|(r)<<4|(q)<<2|(p))))
00057
00058 #define vec4i_swizzle2(a,b,p,q,r,s) \
00059 (_mm_castps_si128( (_mm_shuffle_ps( _mm_castsi128_ps(a), _mm_castsi128_ps(b), ((s)<<6|(r)<<4|(q)<<2|(p))))))
00060
00061 #define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \
00062 const Packet4f p4f_##NAME = pset1<Packet4f>(X)
00063
00064 #define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \
00065 const Packet4f p4f_##NAME = _mm_castsi128_ps(pset1<Packet4i>(X))
00066
00067 #define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \
00068 const Packet4i p4i_##NAME = pset1<Packet4i>(X)
00069
00070
00071 template<> struct packet_traits<float> : default_packet_traits
00072 {
00073 typedef Packet4f type;
00074 enum {
00075 Vectorizable = 1,
00076 AlignedOnScalar = 1,
00077 size=4,
00078
00079 HasDiv = 1,
00080 HasSin = EIGEN_FAST_MATH,
00081 HasCos = EIGEN_FAST_MATH,
00082 HasLog = 1,
00083 HasExp = 1,
00084 HasSqrt = 1
00085 };
00086 };
00087 template<> struct packet_traits<double> : default_packet_traits
00088 {
00089 typedef Packet2d type;
00090 enum {
00091 Vectorizable = 1,
00092 AlignedOnScalar = 1,
00093 size=2,
00094
00095 HasDiv = 1
00096 };
00097 };
00098 template<> struct packet_traits<int> : default_packet_traits
00099 {
00100 typedef Packet4i type;
00101 enum {
00102
00103 Vectorizable = 1,
00104 AlignedOnScalar = 1,
00105 size=4
00106 };
00107 };
00108
00109 template<> struct unpacket_traits<Packet4f> { typedef float type; enum {size=4}; };
00110 template<> struct unpacket_traits<Packet2d> { typedef double type; enum {size=2}; };
00111 template<> struct unpacket_traits<Packet4i> { typedef int type; enum {size=4}; };
00112
00113 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(const float& from) { return _mm_set1_ps(from); }
00114 template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(const double& from) { return _mm_set1_pd(from); }
00115 template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(const int& from) { return _mm_set1_epi32(from); }
00116
00117 template<> EIGEN_STRONG_INLINE Packet4f plset<float>(const float& a) { return _mm_add_ps(pset1<Packet4f>(a), _mm_set_ps(3,2,1,0)); }
00118 template<> EIGEN_STRONG_INLINE Packet2d plset<double>(const double& a) { return _mm_add_pd(pset1<Packet2d>(a),_mm_set_pd(1,0)); }
00119 template<> EIGEN_STRONG_INLINE Packet4i plset<int>(const int& a) { return _mm_add_epi32(pset1<Packet4i>(a),_mm_set_epi32(3,2,1,0)); }
00120
00121 template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_add_ps(a,b); }
00122 template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_add_pd(a,b); }
00123 template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_add_epi32(a,b); }
00124
00125 template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_sub_ps(a,b); }
00126 template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_sub_pd(a,b); }
00127 template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_sub_epi32(a,b); }
00128
00129 template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a)
00130 {
00131 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
00132 return _mm_xor_ps(a,mask);
00133 }
00134 template<> EIGEN_STRONG_INLINE Packet2d pnegate(const Packet2d& a)
00135 {
00136 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x80000000,0x0,0x80000000));
00137 return _mm_xor_pd(a,mask);
00138 }
00139 template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a)
00140 {
00141 return psub(_mm_setr_epi32(0,0,0,0), a);
00142 }
00143
00144 template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_mul_ps(a,b); }
00145 template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_mul_pd(a,b); }
00146 template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(const Packet4i& a, const Packet4i& b)
00147 {
00148 #ifdef EIGEN_VECTORIZE_SSE4_1
00149 return _mm_mullo_epi32(a,b);
00150 #else
00151
00152 return vec4i_swizzle1(
00153 vec4i_swizzle2(
00154 _mm_mul_epu32(a,b),
00155 _mm_mul_epu32(vec4i_swizzle1(a,1,0,3,2),
00156 vec4i_swizzle1(b,1,0,3,2)),
00157 0,2,0,2),
00158 0,2,1,3);
00159 #endif
00160 }
00161
00162 template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_div_ps(a,b); }
00163 template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_div_pd(a,b); }
00164 template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(const Packet4i& , const Packet4i& )
00165 { eigen_assert(false && "packet integer division are not supported by SSE");
00166 return pset1<Packet4i>(0);
00167 }
00168
00169
00170 template<> EIGEN_STRONG_INLINE Packet4i pmadd(const Packet4i& a, const Packet4i& b, const Packet4i& c) { return padd(pmul(a,b), c); }
00171
00172 template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_min_ps(a,b); }
00173 template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_min_pd(a,b); }
00174 template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(const Packet4i& a, const Packet4i& b)
00175 {
00176
00177 Packet4i mask = _mm_cmplt_epi32(a,b);
00178 return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
00179 }
00180
00181 template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_max_ps(a,b); }
00182 template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_max_pd(a,b); }
00183 template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(const Packet4i& a, const Packet4i& b)
00184 {
00185
00186 Packet4i mask = _mm_cmpgt_epi32(a,b);
00187 return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
00188 }
00189
00190 template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_and_ps(a,b); }
00191 template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_and_pd(a,b); }
00192 template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_and_si128(a,b); }
00193
00194 template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_or_ps(a,b); }
00195 template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_or_pd(a,b); }
00196 template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_or_si128(a,b); }
00197
00198 template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_xor_ps(a,b); }
00199 template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_xor_pd(a,b); }
00200 template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_xor_si128(a,b); }
00201
00202 template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, const Packet4f& b) { return _mm_andnot_ps(a,b); }
00203 template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(const Packet2d& a, const Packet2d& b) { return _mm_andnot_pd(a,b); }
00204 template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return _mm_andnot_si128(a,b); }
00205
00206 template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(const float* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_ps(from); }
00207 template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(const double* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_pd(from); }
00208 template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(const int* from) { EIGEN_DEBUG_ALIGNED_LOAD return _mm_load_si128(reinterpret_cast<const Packet4i*>(from)); }
00209
00210 #if defined(_MSC_VER)
00211 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from) {
00212 EIGEN_DEBUG_UNALIGNED_LOAD
00213 #if (_MSC_VER==1600)
00214
00215
00216
00217
00218 __m128 res = _mm_loadl_pi(_mm_set1_ps(0.0f), (const __m64*)(from));
00219 res = _mm_loadh_pi(res, (const __m64*)(from+2));
00220 return res;
00221 #else
00222 return _mm_loadu_ps(from);
00223 #endif
00224 }
00225 template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm_loadu_pd(from); }
00226 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from) { EIGEN_DEBUG_UNALIGNED_LOAD return _mm_loadu_si128(reinterpret_cast<const Packet4i*>(from)); }
00227 #else
00228
00229
00230
00231
00232
00233
00234
00235 #if defined(__GNUC__) && defined(__i386__)
00236
00237 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 1
00238 #elif defined(__clang__)
00239
00240 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 1
00241 #else
00242 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 0
00243 #endif
00244
00245 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(const float* from)
00246 {
00247 EIGEN_DEBUG_UNALIGNED_LOAD
00248 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS
00249 return _mm_loadu_ps(from);
00250 #else
00251 __m128d res;
00252 res = _mm_load_sd((const double*)(from)) ;
00253 res = _mm_loadh_pd(res, (const double*)(from+2)) ;
00254 return _mm_castpd_ps(res);
00255 #endif
00256 }
00257 template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(const double* from)
00258 {
00259 EIGEN_DEBUG_UNALIGNED_LOAD
00260 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS
00261 return _mm_loadu_pd(from);
00262 #else
00263 __m128d res;
00264 res = _mm_load_sd(from) ;
00265 res = _mm_loadh_pd(res,from+1);
00266 return res;
00267 #endif
00268 }
00269 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(const int* from)
00270 {
00271 EIGEN_DEBUG_UNALIGNED_LOAD
00272 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS
00273 return _mm_loadu_si128(reinterpret_cast<const Packet4i*>(from));
00274 #else
00275 __m128d res;
00276 res = _mm_load_sd((const double*)(from)) ;
00277 res = _mm_loadh_pd(res, (const double*)(from+2)) ;
00278 return _mm_castpd_si128(res);
00279 #endif
00280 }
00281 #endif
00282
00283 template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(const float* from)
00284 {
00285 return vec4f_swizzle1(_mm_castpd_ps(_mm_load_sd((const double*)from)), 0, 0, 1, 1);
00286 }
00287 template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(const double* from)
00288 { return pset1<Packet2d>(from[0]); }
00289 template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(const int* from)
00290 {
00291 Packet4i tmp;
00292 tmp = _mm_loadl_epi64(reinterpret_cast<const Packet4i*>(from));
00293 return vec4i_swizzle1(tmp, 0, 0, 1, 1);
00294 }
00295
00296 template<> EIGEN_STRONG_INLINE void pstore<float>(float* to, const Packet4f& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_ps(to, from); }
00297 template<> EIGEN_STRONG_INLINE void pstore<double>(double* to, const Packet2d& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_pd(to, from); }
00298 template<> EIGEN_STRONG_INLINE void pstore<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(reinterpret_cast<Packet4i*>(to), from); }
00299
00300 template<> EIGEN_STRONG_INLINE void pstoreu<double>(double* to, const Packet2d& from) {
00301 EIGEN_DEBUG_UNALIGNED_STORE
00302 _mm_storel_pd((to), from);
00303 _mm_storeh_pd((to+1), from);
00304 }
00305 template<> EIGEN_STRONG_INLINE void pstoreu<float>(float* to, const Packet4f& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, _mm_castps_pd(from)); }
00306 template<> EIGEN_STRONG_INLINE void pstoreu<int>(int* to, const Packet4i& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu((double*)to, _mm_castsi128_pd(from)); }
00307
00308 template<> EIGEN_STRONG_INLINE void prefetch<float>(const float* addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
00309 template<> EIGEN_STRONG_INLINE void prefetch<double>(const double* addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
00310 template<> EIGEN_STRONG_INLINE void prefetch<int>(const int* addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); }
00311
00312 #if defined(_MSC_VER) && defined(_WIN64) && !defined(__INTEL_COMPILER)
00313
00314
00315 template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return a.m128_f32[0]; }
00316 template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return a.m128d_f64[0]; }
00317 template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int x = _mm_cvtsi128_si32(a); return x; }
00318 #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER)
00319
00320 template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { float x = _mm_cvtss_f32(a); return x; }
00321 template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { double x = _mm_cvtsd_f64(a); return x; }
00322 template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { int x = _mm_cvtsi128_si32(a); return x; }
00323 #else
00324 template<> EIGEN_STRONG_INLINE float pfirst<Packet4f>(const Packet4f& a) { return _mm_cvtss_f32(a); }
00325 template<> EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) { return _mm_cvtsd_f64(a); }
00326 template<> EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) { return _mm_cvtsi128_si32(a); }
00327 #endif
00328
00329 template<> EIGEN_STRONG_INLINE Packet4f preverse(const Packet4f& a)
00330 { return _mm_shuffle_ps(a,a,0x1B); }
00331 template<> EIGEN_STRONG_INLINE Packet2d preverse(const Packet2d& a)
00332 { return _mm_shuffle_pd(a,a,0x1); }
00333 template<> EIGEN_STRONG_INLINE Packet4i preverse(const Packet4i& a)
00334 { return _mm_shuffle_epi32(a,0x1B); }
00335
00336
00337 template<> EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f& a)
00338 {
00339 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF));
00340 return _mm_and_ps(a,mask);
00341 }
00342 template<> EIGEN_STRONG_INLINE Packet2d pabs(const Packet2d& a)
00343 {
00344 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF));
00345 return _mm_and_pd(a,mask);
00346 }
00347 template<> EIGEN_STRONG_INLINE Packet4i pabs(const Packet4i& a)
00348 {
00349 #ifdef EIGEN_VECTORIZE_SSSE3
00350 return _mm_abs_epi32(a);
00351 #else
00352 Packet4i aux = _mm_srai_epi32(a,31);
00353 return _mm_sub_epi32(_mm_xor_si128(a,aux),aux);
00354 #endif
00355 }
00356
00357 EIGEN_STRONG_INLINE void punpackp(Packet4f* vecs)
00358 {
00359 vecs[1] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x55));
00360 vecs[2] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xAA));
00361 vecs[3] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xFF));
00362 vecs[0] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x00));
00363 }
00364
00365 #ifdef EIGEN_VECTORIZE_SSE3
00366
00367 template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs)
00368 {
00369 return _mm_hadd_ps(_mm_hadd_ps(vecs[0], vecs[1]),_mm_hadd_ps(vecs[2], vecs[3]));
00370 }
00371 template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs)
00372 {
00373 return _mm_hadd_pd(vecs[0], vecs[1]);
00374 }
00375
00376
00377
00378
00379
00380
00381 template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
00382 {
00383 Packet4f tmp0 = _mm_hadd_ps(a,a);
00384 return pfirst(_mm_hadd_ps(tmp0, tmp0));
00385 }
00386
00387 template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a) { return pfirst(_mm_hadd_pd(a, a)); }
00388
00389
00390
00391
00392
00393
00394
00395 #else
00396
00397 template<> EIGEN_STRONG_INLINE float predux<Packet4f>(const Packet4f& a)
00398 {
00399 Packet4f tmp = _mm_add_ps(a, _mm_movehl_ps(a,a));
00400 return pfirst(_mm_add_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
00401 }
00402 template<> EIGEN_STRONG_INLINE double predux<Packet2d>(const Packet2d& a)
00403 {
00404 return pfirst(_mm_add_sd(a, _mm_unpackhi_pd(a,a)));
00405 }
00406
00407 template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(const Packet4f* vecs)
00408 {
00409 Packet4f tmp0, tmp1, tmp2;
00410 tmp0 = _mm_unpacklo_ps(vecs[0], vecs[1]);
00411 tmp1 = _mm_unpackhi_ps(vecs[0], vecs[1]);
00412 tmp2 = _mm_unpackhi_ps(vecs[2], vecs[3]);
00413 tmp0 = _mm_add_ps(tmp0, tmp1);
00414 tmp1 = _mm_unpacklo_ps(vecs[2], vecs[3]);
00415 tmp1 = _mm_add_ps(tmp1, tmp2);
00416 tmp2 = _mm_movehl_ps(tmp1, tmp0);
00417 tmp0 = _mm_movelh_ps(tmp0, tmp1);
00418 return _mm_add_ps(tmp0, tmp2);
00419 }
00420
00421 template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(const Packet2d* vecs)
00422 {
00423 return _mm_add_pd(_mm_unpacklo_pd(vecs[0], vecs[1]), _mm_unpackhi_pd(vecs[0], vecs[1]));
00424 }
00425 #endif // SSE3
00426
00427 template<> EIGEN_STRONG_INLINE int predux<Packet4i>(const Packet4i& a)
00428 {
00429 Packet4i tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a,a));
00430 return pfirst(tmp) + pfirst(_mm_shuffle_epi32(tmp, 1));
00431 }
00432
00433 template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(const Packet4i* vecs)
00434 {
00435 Packet4i tmp0, tmp1, tmp2;
00436 tmp0 = _mm_unpacklo_epi32(vecs[0], vecs[1]);
00437 tmp1 = _mm_unpackhi_epi32(vecs[0], vecs[1]);
00438 tmp2 = _mm_unpackhi_epi32(vecs[2], vecs[3]);
00439 tmp0 = _mm_add_epi32(tmp0, tmp1);
00440 tmp1 = _mm_unpacklo_epi32(vecs[2], vecs[3]);
00441 tmp1 = _mm_add_epi32(tmp1, tmp2);
00442 tmp2 = _mm_unpacklo_epi64(tmp0, tmp1);
00443 tmp0 = _mm_unpackhi_epi64(tmp0, tmp1);
00444 return _mm_add_epi32(tmp0, tmp2);
00445 }
00446
00447
00448
00449
00450 template<> EIGEN_STRONG_INLINE float predux_mul<Packet4f>(const Packet4f& a)
00451 {
00452 Packet4f tmp = _mm_mul_ps(a, _mm_movehl_ps(a,a));
00453 return pfirst(_mm_mul_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
00454 }
00455 template<> EIGEN_STRONG_INLINE double predux_mul<Packet2d>(const Packet2d& a)
00456 {
00457 return pfirst(_mm_mul_sd(a, _mm_unpackhi_pd(a,a)));
00458 }
00459 template<> EIGEN_STRONG_INLINE int predux_mul<Packet4i>(const Packet4i& a)
00460 {
00461
00462
00463
00464 EIGEN_ALIGN16 int aux[4];
00465 pstore(aux, a);
00466 return (aux[0] * aux[1]) * (aux[2] * aux[3]);;
00467 }
00468
00469
00470 template<> EIGEN_STRONG_INLINE float predux_min<Packet4f>(const Packet4f& a)
00471 {
00472 Packet4f tmp = _mm_min_ps(a, _mm_movehl_ps(a,a));
00473 return pfirst(_mm_min_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
00474 }
00475 template<> EIGEN_STRONG_INLINE double predux_min<Packet2d>(const Packet2d& a)
00476 {
00477 return pfirst(_mm_min_sd(a, _mm_unpackhi_pd(a,a)));
00478 }
00479 template<> EIGEN_STRONG_INLINE int predux_min<Packet4i>(const Packet4i& a)
00480 {
00481
00482
00483 EIGEN_ALIGN16 int aux[4];
00484 pstore(aux, a);
00485 register int aux0 = aux[0]<aux[1] ? aux[0] : aux[1];
00486 register int aux2 = aux[2]<aux[3] ? aux[2] : aux[3];
00487 return aux0<aux2 ? aux0 : aux2;
00488 }
00489
00490
00491 template<> EIGEN_STRONG_INLINE float predux_max<Packet4f>(const Packet4f& a)
00492 {
00493 Packet4f tmp = _mm_max_ps(a, _mm_movehl_ps(a,a));
00494 return pfirst(_mm_max_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
00495 }
00496 template<> EIGEN_STRONG_INLINE double predux_max<Packet2d>(const Packet2d& a)
00497 {
00498 return pfirst(_mm_max_sd(a, _mm_unpackhi_pd(a,a)));
00499 }
00500 template<> EIGEN_STRONG_INLINE int predux_max<Packet4i>(const Packet4i& a)
00501 {
00502
00503
00504 EIGEN_ALIGN16 int aux[4];
00505 pstore(aux, a);
00506 register int aux0 = aux[0]>aux[1] ? aux[0] : aux[1];
00507 register int aux2 = aux[2]>aux[3] ? aux[2] : aux[3];
00508 return aux0>aux2 ? aux0 : aux2;
00509 }
00510
00511 #if (defined __GNUC__)
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524 #endif
00525
00526 #ifdef EIGEN_VECTORIZE_SSSE3
00527
00528 template<int Offset>
00529 struct palign_impl<Offset,Packet4f>
00530 {
00531 EIGEN_STRONG_INLINE static void run(Packet4f& first, const Packet4f& second)
00532 {
00533 if (Offset!=0)
00534 first = _mm_castsi128_ps(_mm_alignr_epi8(_mm_castps_si128(second), _mm_castps_si128(first), Offset*4));
00535 }
00536 };
00537
00538 template<int Offset>
00539 struct palign_impl<Offset,Packet4i>
00540 {
00541 EIGEN_STRONG_INLINE static void run(Packet4i& first, const Packet4i& second)
00542 {
00543 if (Offset!=0)
00544 first = _mm_alignr_epi8(second,first, Offset*4);
00545 }
00546 };
00547
00548 template<int Offset>
00549 struct palign_impl<Offset,Packet2d>
00550 {
00551 EIGEN_STRONG_INLINE static void run(Packet2d& first, const Packet2d& second)
00552 {
00553 if (Offset==1)
00554 first = _mm_castsi128_pd(_mm_alignr_epi8(_mm_castpd_si128(second), _mm_castpd_si128(first), 8));
00555 }
00556 };
00557 #else
00558
00559 template<int Offset>
00560 struct palign_impl<Offset,Packet4f>
00561 {
00562 EIGEN_STRONG_INLINE static void run(Packet4f& first, const Packet4f& second)
00563 {
00564 if (Offset==1)
00565 {
00566 first = _mm_move_ss(first,second);
00567 first = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(first),0x39));
00568 }
00569 else if (Offset==2)
00570 {
00571 first = _mm_movehl_ps(first,first);
00572 first = _mm_movelh_ps(first,second);
00573 }
00574 else if (Offset==3)
00575 {
00576 first = _mm_move_ss(first,second);
00577 first = _mm_shuffle_ps(first,second,0x93);
00578 }
00579 }
00580 };
00581
00582 template<int Offset>
00583 struct palign_impl<Offset,Packet4i>
00584 {
00585 EIGEN_STRONG_INLINE static void run(Packet4i& first, const Packet4i& second)
00586 {
00587 if (Offset==1)
00588 {
00589 first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
00590 first = _mm_shuffle_epi32(first,0x39);
00591 }
00592 else if (Offset==2)
00593 {
00594 first = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(first)));
00595 first = _mm_castps_si128(_mm_movelh_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
00596 }
00597 else if (Offset==3)
00598 {
00599 first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
00600 first = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second),0x93));
00601 }
00602 }
00603 };
00604
00605 template<int Offset>
00606 struct palign_impl<Offset,Packet2d>
00607 {
00608 EIGEN_STRONG_INLINE static void run(Packet2d& first, const Packet2d& second)
00609 {
00610 if (Offset==1)
00611 {
00612 first = _mm_castps_pd(_mm_movehl_ps(_mm_castpd_ps(first),_mm_castpd_ps(first)));
00613 first = _mm_castps_pd(_mm_movelh_ps(_mm_castpd_ps(first),_mm_castpd_ps(second)));
00614 }
00615 }
00616 };
00617 #endif
00618
00619 }
00620
00621 #endif // EIGEN_PACKET_MATH_SSE_H