10 #ifndef EIGEN_PACKET_MATH_SSE_H 11 #define EIGEN_PACKET_MATH_SSE_H 17 #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 18 #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 21 #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 22 #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS (2*sizeof(void*)) 33 #define vec4f_swizzle1(v,p,q,r,s) \ 34 (_mm_castsi128_ps(_mm_shuffle_epi32( _mm_castps_si128(v), ((s)<<6|(r)<<4|(q)<<2|(p))))) 36 #define vec4i_swizzle1(v,p,q,r,s) \ 37 (_mm_shuffle_epi32( v, ((s)<<6|(r)<<4|(q)<<2|(p)))) 39 #define vec2d_swizzle1(v,p,q) \ 40 (_mm_castsi128_pd(_mm_shuffle_epi32( _mm_castpd_si128(v), ((q*2+1)<<6|(q*2)<<4|(p*2+1)<<2|(p*2))))) 42 #define vec4f_swizzle2(a,b,p,q,r,s) \ 43 (_mm_shuffle_ps( (a), (b), ((s)<<6|(r)<<4|(q)<<2|(p)))) 45 #define vec4i_swizzle2(a,b,p,q,r,s) \ 46 (_mm_castps_si128( (_mm_shuffle_ps( _mm_castsi128_ps(a), _mm_castsi128_ps(b), ((s)<<6|(r)<<4|(q)<<2|(p)))))) 48 #define _EIGEN_DECLARE_CONST_Packet4f(NAME,X) \ 49 const Packet4f p4f_##NAME = pset1<Packet4f>(X) 51 #define _EIGEN_DECLARE_CONST_Packet2d(NAME,X) \ 52 const Packet2d p2d_##NAME = pset1<Packet2d>(X) 54 #define _EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME,X) \ 55 const Packet4f p4f_##NAME = _mm_castsi128_ps(pset1<Packet4i>(X)) 57 #define _EIGEN_DECLARE_CONST_Packet4i(NAME,X) \ 58 const Packet4i p4i_##NAME = pset1<Packet4i>(X) 61 template<>
struct packet_traits<float> : default_packet_traits
104 #if defined(_MSC_VER) && (_MSC_VER==1500) 131 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
132 return _mm_xor_ps(a,mask);
136 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x80000000,0x0,0x80000000));
137 return _mm_xor_pd(a,mask);
141 return psub(_mm_setr_epi32(0,0,0,0), a);
152 #ifdef EIGEN_VECTORIZE_SSE4_1 153 return _mm_mullo_epi32(a,b);
169 {
eigen_assert(
false &&
"packet integer division are not supported by SSE");
180 #ifdef EIGEN_VECTORIZE_SSE4_1 181 return _mm_min_epi32(a,b);
184 Packet4i mask = _mm_cmplt_epi32(a,b);
185 return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
193 #ifdef EIGEN_VECTORIZE_SSE4_1 194 return _mm_max_epi32(a,b);
197 Packet4i mask = _mm_cmpgt_epi32(a,b);
198 return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
222 #if defined(_MSC_VER) 230 __m128 res = _mm_loadl_pi(_mm_set1_ps(0.0
f), (
const __m64*)(from));
231 res = _mm_loadh_pi(res, (
const __m64*)(from+2));
234 return _mm_loadu_ps(from);
247 #if defined(__GNUC__) && defined(__i386__) 249 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 1 250 #elif defined(__clang__) 252 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 1 254 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 0 260 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 261 return _mm_loadu_ps(from);
264 res = _mm_load_sd((
const double*)(from)) ;
265 res = _mm_loadh_pd(res, (
const double*)(from+2)) ;
266 return _mm_castpd_ps(res);
272 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 273 return _mm_loadu_pd(from);
276 res = _mm_load_sd(from) ;
277 res = _mm_loadh_pd(res,from+1);
284 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 285 return _mm_loadu_si128(reinterpret_cast<const Packet4i*>(from));
288 res = _mm_load_sd((
const double*)(from)) ;
289 res = _mm_loadh_pd(res, (
const double*)(from+2)) ;
290 return _mm_castpd_si128(res);
297 return vec4f_swizzle1(_mm_castpd_ps(_mm_load_sd(reinterpret_cast<const double*>(from))), 0, 0, 1, 1);
304 tmp = _mm_loadl_epi64(reinterpret_cast<const Packet4i*>(from));
314 _mm_storel_pd((to), from);
315 _mm_storeh_pd((to+1), from);
323 Packet4f pa = _mm_set_ss(a);
329 Packet2d pa = _mm_set_sd(a);
337 #if defined(_MSC_VER) && defined(_WIN64) && !defined(__INTEL_COMPILER) 343 #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER) 355 {
return _mm_shuffle_ps(a,a,0x1B); }
357 {
return _mm_shuffle_pd(a,a,0x1); }
359 {
return _mm_shuffle_epi32(a,0x1B); }
364 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF));
365 return _mm_and_ps(a,mask);
369 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF));
370 return _mm_and_pd(a,mask);
374 #ifdef EIGEN_VECTORIZE_SSSE3 375 return _mm_abs_epi32(a);
377 Packet4i aux = _mm_srai_epi32(a,31);
378 return _mm_sub_epi32(_mm_xor_si128(a,aux),aux);
384 vecs[1] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x55));
385 vecs[2] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xAA));
386 vecs[3] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xFF));
387 vecs[0] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x00));
390 #ifdef EIGEN_VECTORIZE_SSE3 394 return _mm_hadd_ps(_mm_hadd_ps(vecs[0], vecs[1]),_mm_hadd_ps(vecs[2], vecs[3]));
398 return _mm_hadd_pd(vecs[0], vecs[1]);
408 Packet4f tmp0 = _mm_hadd_ps(a,a);
409 return pfirst(_mm_hadd_ps(tmp0, tmp0));
424 Packet4f tmp = _mm_add_ps(a, _mm_movehl_ps(a,a));
425 return pfirst(_mm_add_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
429 return pfirst(_mm_add_sd(a, _mm_unpackhi_pd(a,a)));
434 Packet4f tmp0, tmp1, tmp2;
435 tmp0 = _mm_unpacklo_ps(vecs[0], vecs[1]);
436 tmp1 = _mm_unpackhi_ps(vecs[0], vecs[1]);
437 tmp2 = _mm_unpackhi_ps(vecs[2], vecs[3]);
438 tmp0 = _mm_add_ps(tmp0, tmp1);
439 tmp1 = _mm_unpacklo_ps(vecs[2], vecs[3]);
440 tmp1 = _mm_add_ps(tmp1, tmp2);
441 tmp2 = _mm_movehl_ps(tmp1, tmp0);
442 tmp0 = _mm_movelh_ps(tmp0, tmp1);
443 return _mm_add_ps(tmp0, tmp2);
448 return _mm_add_pd(_mm_unpacklo_pd(vecs[0], vecs[1]), _mm_unpackhi_pd(vecs[0], vecs[1]));
454 Packet4i tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a,a));
460 Packet4i tmp0, tmp1, tmp2;
461 tmp0 = _mm_unpacklo_epi32(vecs[0], vecs[1]);
462 tmp1 = _mm_unpackhi_epi32(vecs[0], vecs[1]);
463 tmp2 = _mm_unpackhi_epi32(vecs[2], vecs[3]);
464 tmp0 = _mm_add_epi32(tmp0, tmp1);
465 tmp1 = _mm_unpacklo_epi32(vecs[2], vecs[3]);
466 tmp1 = _mm_add_epi32(tmp1, tmp2);
467 tmp2 = _mm_unpacklo_epi64(tmp0, tmp1);
468 tmp0 = _mm_unpackhi_epi64(tmp0, tmp1);
469 return _mm_add_epi32(tmp0, tmp2);
477 Packet4f tmp = _mm_mul_ps(a, _mm_movehl_ps(a,a));
478 return pfirst(_mm_mul_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
482 return pfirst(_mm_mul_sd(a, _mm_unpackhi_pd(a,a)));
491 return (aux[0] * aux[1]) * (aux[2] * aux[3]);;
497 Packet4f tmp = _mm_min_ps(a, _mm_movehl_ps(a,a));
498 return pfirst(_mm_min_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
502 return pfirst(_mm_min_sd(a, _mm_unpackhi_pd(a,a)));
510 register int aux0 = aux[0]<aux[1] ? aux[0] : aux[1];
511 register int aux2 = aux[2]<aux[3] ? aux[2] : aux[3];
512 return aux0<aux2 ? aux0 : aux2;
518 Packet4f tmp = _mm_max_ps(a, _mm_movehl_ps(a,a));
519 return pfirst(_mm_max_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
523 return pfirst(_mm_max_sd(a, _mm_unpackhi_pd(a,a)));
531 register int aux0 = aux[0]>aux[1] ? aux[0] : aux[1];
532 register int aux2 = aux[2]>aux[3] ? aux[2] : aux[3];
533 return aux0>aux2 ? aux0 : aux2;
536 #if (defined __GNUC__) 551 #ifdef EIGEN_VECTORIZE_SSSE3 559 first = _mm_castsi128_ps(_mm_alignr_epi8(_mm_castps_si128(second), _mm_castps_si128(first), Offset*4));
569 first = _mm_alignr_epi8(second,first, Offset*4);
579 first = _mm_castsi128_pd(_mm_alignr_epi8(_mm_castpd_si128(second), _mm_castpd_si128(first), 8));
591 first = _mm_move_ss(first,second);
592 first = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(first),0x39));
596 first = _mm_movehl_ps(first,first);
597 first = _mm_movelh_ps(first,second);
601 first = _mm_move_ss(first,second);
602 first = _mm_shuffle_ps(first,second,0x93);
614 first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
615 first = _mm_shuffle_epi32(first,0x39);
619 first = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(first)));
620 first = _mm_castps_si128(_mm_movelh_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
624 first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
625 first = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second),0x93));
637 first = _mm_castps_pd(_mm_movehl_ps(_mm_castpd_ps(first),_mm_castpd_ps(first)));
638 first = _mm_castps_pd(_mm_movelh_ps(_mm_castpd_ps(first),_mm_castpd_ps(second)));
648 #endif // EIGEN_PACKET_MATH_SSE_H EIGEN_STRONG_INLINE Packet4i ploaddup< Packet4i >(const int *from)
EIGEN_STRONG_INLINE Packet4f pxor< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE int pfirst< Packet4i >(const Packet4i &a)
#define EIGEN_STRONG_INLINE
EIGEN_STRONG_INLINE double predux_min< Packet2d >(const Packet2d &a)
EIGEN_STRONG_INLINE Packet4i pload< Packet4i >(const int *from)
EIGEN_STRONG_INLINE double predux_max< Packet2d >(const Packet2d &a)
EIGEN_STRONG_INLINE void pstoreu< double >(double *to, const Packet2d &from)
#define EIGEN_DEBUG_UNALIGNED_LOAD
EIGEN_STRONG_INLINE float pfirst< Packet4f >(const Packet4f &a)
EIGEN_STRONG_INLINE Packet4f ploaddup< Packet4f >(const float *from)
EIGEN_STRONG_INLINE int predux< Packet4i >(const Packet4i &a)
#define EIGEN_DEBUG_ALIGNED_STORE
static EIGEN_STRONG_INLINE void run(Packet4i &first, const Packet4i &second)
EIGEN_STRONG_INLINE Packet4i ploadu< Packet4i >(const int *from)
EIGEN_STRONG_INLINE float predux_max< Packet4f >(const Packet4f &a)
EIGEN_STRONG_INLINE void pstore1< Packet2d >(double *to, const double &a)
static EIGEN_STRONG_INLINE void run(Packet4f &first, const Packet4f &second)
#define EIGEN_DEBUG_UNALIGNED_STORE
EIGEN_STRONG_INLINE void prefetch< float >(const float *addr)
EIGEN_STRONG_INLINE Packet4i pdiv< Packet4i >(const Packet4i &, const Packet4i &)
EIGEN_STRONG_INLINE int predux_min< Packet4i >(const Packet4i &a)
#define EIGEN_DEBUG_ALIGNED_LOAD
void pstore(Scalar *to, const Packet &from)
#define vec4i_swizzle1(v, p, q, r, s)
EIGEN_STRONG_INLINE Packet4i plset< int >(const int &a)
EIGEN_STRONG_INLINE Packet4f plset< float >(const float &a)
EIGEN_STRONG_INLINE Packet2d padd< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_STRONG_INLINE Packet2d ploaddup< Packet2d >(const double *from)
EIGEN_STRONG_INLINE double predux_mul< Packet2d >(const Packet2d &a)
EIGEN_STRONG_INLINE Packet2d preduxp< Packet2d >(const Packet2d *vecs)
EIGEN_STRONG_INLINE Packet2d pdiv< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_STRONG_INLINE Packet4i pmul< Packet4i >(const Packet4i &a, const Packet4i &b)
#define vec2d_swizzle1(v, p, q)
EIGEN_STRONG_INLINE Packet2d pandnot< Packet2d >(const Packet2d &a, const Packet2d &b)
void pstoreu(Scalar *to, const Packet &from)
EIGEN_STRONG_INLINE Packet4f pdiv< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE Packet4f pmin< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE Packet2d pmin< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_STRONG_INLINE void prefetch< int >(const int *addr)
EIGEN_STRONG_INLINE Packet4i pand< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE int predux_max< Packet4i >(const Packet4i &a)
EIGEN_STRONG_INLINE Packet4i pmin< Packet4i >(const Packet4i &a, const Packet4i &b)
Packet psub(const Packet &a, const Packet &b)
EIGEN_STRONG_INLINE Packet4f ploadu< Packet4f >(const float *from)
EIGEN_STRONG_INLINE Packet4i pxor< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE void pstoreu< int >(int *to, const Packet4i &from)
#define vec4f_swizzle1(v, p, q, r, s)
EIGEN_STRONG_INLINE void pstore< float >(float *to, const Packet4f &from)
EIGEN_STRONG_INLINE Packet4f por< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE Packet2d pmax< Packet2d >(const Packet2d &a, const Packet2d &b)
unpacket_traits< Packet >::type pfirst(const Packet &a)
EIGEN_STRONG_INLINE Packet4i preduxp< Packet4i >(const Packet4i *vecs)
EIGEN_STRONG_INLINE Packet4f pandnot< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE float predux< Packet4f >(const Packet4f &a)
EIGEN_STRONG_INLINE Packet2d pand< Packet2d >(const Packet2d &a, const Packet2d &b)
TFSIMD_FORCE_INLINE const tfScalar & x() const
EIGEN_STRONG_INLINE Packet2d ploadu< Packet2d >(const double *from)
EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf &a)
EIGEN_STRONG_INLINE float predux_min< Packet4f >(const Packet4f &a)
EIGEN_STRONG_INLINE Packet2d pload< Packet2d >(const double *from)
EIGEN_STRONG_INLINE Packet2d psub< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_STRONG_INLINE void pstoreu< float >(float *to, const Packet4f &from)
EIGEN_STRONG_INLINE int predux_mul< Packet4i >(const Packet4i &a)
EIGEN_STRONG_INLINE Packet4f pmul< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE double predux< Packet2d >(const Packet2d &a)
EIGEN_STRONG_INLINE Packet4f pload< Packet4f >(const float *from)
EIGEN_STRONG_INLINE Packet4i pmax< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE Packet2d pxor< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_STRONG_INLINE Packet2cf pnegate(const Packet2cf &a)
EIGEN_STRONG_INLINE Packet4i por< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE void pstore< double >(double *to, const Packet2d &from)
EIGEN_STRONG_INLINE Packet4i padd< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE void pstore1< Packet4f >(float *to, const float &a)
EIGEN_STRONG_INLINE Packet4f padd< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE void pstore< int >(int *to, const Packet4i &from)
EIGEN_STRONG_INLINE Packet4i pandnot< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE Packet4f pmadd(const Packet4f &a, const Packet4f &b, const Packet4f &c)
Packet pmul(const Packet &a, const Packet &b)
EIGEN_STRONG_INLINE Packet4f preduxp< Packet4f >(const Packet4f *vecs)
EIGEN_STRONG_INLINE Packet2d pset1< Packet2d >(const double &from)
EIGEN_STRONG_INLINE Packet2d pmul< Packet2d >(const Packet2d &a, const Packet2d &b)
static EIGEN_STRONG_INLINE void run(Packet2d &first, const Packet2d &second)
EIGEN_STRONG_INLINE Packet4f pmax< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE Packet4f pset1< Packet4f >(const float &from)
EIGEN_STRONG_INLINE void punpackp(Packet4f *vecs)
void run(ClassLoader *loader)
EIGEN_STRONG_INLINE double pfirst< Packet2d >(const Packet2d &a)
EIGEN_STRONG_INLINE void prefetch< double >(const double *addr)
EIGEN_STRONG_INLINE Packet4i psub< Packet4i >(const Packet4i &a, const Packet4i &b)
EIGEN_STRONG_INLINE Packet4f psub< Packet4f >(const Packet4f &a, const Packet4f &b)
EIGEN_STRONG_INLINE Packet2d plset< double >(const double &a)
Packet padd(const Packet &a, const Packet &b)
#define vec4i_swizzle2(a, b, p, q, r, s)
EIGEN_STRONG_INLINE Packet4i pset1< Packet4i >(const int &from)
EIGEN_STRONG_INLINE Packet2cf preverse(const Packet2cf &a)
EIGEN_STRONG_INLINE Packet2d por< Packet2d >(const Packet2d &a, const Packet2d &b)
EIGEN_STRONG_INLINE float predux_mul< Packet4f >(const Packet4f &a)
EIGEN_STRONG_INLINE Packet4f pabs(const Packet4f &a)
EIGEN_STRONG_INLINE Packet4f pand< Packet4f >(const Packet4f &a, const Packet4f &b)