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*))
25 typedef __m128 Packet4f;
26 typedef __m128i Packet4i;
27 typedef __m128d Packet2d;
29 template<>
struct is_arithmetic<__m128> {
enum { value =
true }; };
30 template<>
struct is_arithmetic<__m128i> {
enum { value =
true }; };
31 template<>
struct is_arithmetic<__m128d> {
enum { value =
true }; };
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
63 typedef Packet4f type;
70 HasSin = EIGEN_FAST_MATH,
71 HasCos = EIGEN_FAST_MATH,
77 template<>
struct packet_traits<double> : default_packet_traits
79 typedef Packet2d type;
90 template<>
struct packet_traits<int> : default_packet_traits
92 typedef Packet4i type;
101 template<>
struct unpacket_traits<Packet4f> {
typedef float type;
enum {size=4}; };
102 template<>
struct unpacket_traits<Packet2d> {
typedef double type;
enum {size=2}; };
103 template<>
struct unpacket_traits<Packet4i> {
typedef int type;
enum {size=4}; };
105 #if defined(_MSC_VER) && (_MSC_VER==1500)
109 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(
const float& from) {
return _mm_set_ps(from,from,from,from); }
110 template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(
const double& from) {
return _mm_set_pd(from,from); }
111 template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(
const int& from) {
return _mm_set_epi32(from,from,from,from); }
113 template<> EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(
const float& from) {
return _mm_set1_ps(from); }
114 template<> EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(
const double& from) {
return _mm_set1_pd(from); }
115 template<> EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(
const int& from) {
return _mm_set1_epi32(from); }
118 template<> EIGEN_STRONG_INLINE Packet4f plset<float>(
const float& a) {
return _mm_add_ps(pset1<Packet4f>(a), _mm_set_ps(3,2,1,0)); }
119 template<> EIGEN_STRONG_INLINE Packet2d plset<double>(
const double& a) {
return _mm_add_pd(pset1<Packet2d>(a),_mm_set_pd(1,0)); }
120 template<> EIGEN_STRONG_INLINE Packet4i plset<int>(
const int& a) {
return _mm_add_epi32(pset1<Packet4i>(a),_mm_set_epi32(3,2,1,0)); }
122 template<> EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_add_ps(a,b); }
123 template<> EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_add_pd(a,b); }
124 template<> EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
return _mm_add_epi32(a,b); }
126 template<> EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_sub_ps(a,b); }
127 template<> EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_sub_pd(a,b); }
128 template<> EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
return _mm_sub_epi32(a,b); }
130 template<> EIGEN_STRONG_INLINE Packet4f pnegate(
const Packet4f& a)
132 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000,0x80000000,0x80000000,0x80000000));
133 return _mm_xor_ps(a,mask);
135 template<> EIGEN_STRONG_INLINE Packet2d pnegate(
const Packet2d& a)
137 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0,0x80000000,0x0,0x80000000));
138 return _mm_xor_pd(a,mask);
140 template<> EIGEN_STRONG_INLINE Packet4i pnegate(
const Packet4i& a)
142 return psub(_mm_setr_epi32(0,0,0,0), a);
145 template<> EIGEN_STRONG_INLINE Packet4f pconj(
const Packet4f& a) {
return a; }
146 template<> EIGEN_STRONG_INLINE Packet2d pconj(
const Packet2d& a) {
return a; }
147 template<> EIGEN_STRONG_INLINE Packet4i pconj(
const Packet4i& a) {
return a; }
149 template<> EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_mul_ps(a,b); }
150 template<> EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_mul_pd(a,b); }
151 template<> EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(
const Packet4i& a,
const Packet4i& b)
153 #ifdef EIGEN_VECTORIZE_SSE4_1
154 return _mm_mullo_epi32(a,b);
157 return vec4i_swizzle1(
160 _mm_mul_epu32(vec4i_swizzle1(a,1,0,3,2),
161 vec4i_swizzle1(b,1,0,3,2)),
167 template<> EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_div_ps(a,b); }
168 template<> EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_div_pd(a,b); }
169 template<> EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(
const Packet4i& ,
const Packet4i& )
170 { eigen_assert(
false &&
"packet integer division are not supported by SSE");
171 return pset1<Packet4i>(0);
175 template<> EIGEN_STRONG_INLINE Packet4i pmadd(
const Packet4i& a,
const Packet4i& b,
const Packet4i& c) {
return padd(pmul(a,b), c); }
177 template<> EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_min_ps(a,b); }
178 template<> EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_min_pd(a,b); }
179 template<> EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(
const Packet4i& a,
const Packet4i& b)
181 #ifdef EIGEN_VECTORIZE_SSE4_1
182 return _mm_min_epi32(a,b);
185 Packet4i mask = _mm_cmplt_epi32(a,b);
186 return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
190 template<> EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_max_ps(a,b); }
191 template<> EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_max_pd(a,b); }
192 template<> EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(
const Packet4i& a,
const Packet4i& b)
194 #ifdef EIGEN_VECTORIZE_SSE4_1
195 return _mm_max_epi32(a,b);
198 Packet4i mask = _mm_cmpgt_epi32(a,b);
199 return _mm_or_si128(_mm_and_si128(mask,a),_mm_andnot_si128(mask,b));
203 template<> EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_and_ps(a,b); }
204 template<> EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_and_pd(a,b); }
205 template<> EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
return _mm_and_si128(a,b); }
207 template<> EIGEN_STRONG_INLINE Packet4f por<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_or_ps(a,b); }
208 template<> EIGEN_STRONG_INLINE Packet2d por<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_or_pd(a,b); }
209 template<> EIGEN_STRONG_INLINE Packet4i por<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
return _mm_or_si128(a,b); }
211 template<> EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_xor_ps(a,b); }
212 template<> EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_xor_pd(a,b); }
213 template<> EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
return _mm_xor_si128(a,b); }
215 template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
return _mm_andnot_ps(a,b); }
216 template<> EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
return _mm_andnot_pd(a,b); }
217 template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
return _mm_andnot_si128(a,b); }
219 template<> EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(
const float* from) { EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_ps(from); }
220 template<> EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(
const double* from) { EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_pd(from); }
221 template<> EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(
const int* from) { EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_si128(reinterpret_cast<const Packet4i*>(from)); }
223 #if defined(_MSC_VER)
224 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(
const float* from) {
225 EIGEN_DEBUG_UNALIGNED_LOAD
231 __m128 res = _mm_loadl_pi(_mm_set1_ps(0.0f), (
const __m64*)(from));
232 res = _mm_loadh_pi(res, (
const __m64*)(from+2));
235 return _mm_loadu_ps(from);
238 template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(
const double* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_loadu_pd(from); }
239 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(
const int* from) { EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_loadu_si128(reinterpret_cast<const Packet4i*>(from)); }
248 #if defined(__GNUC__) && defined(__i386__)
250 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 1
251 #elif defined(__clang__)
253 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 1
255 #define EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS 0
258 template<> EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(
const float* from)
260 EIGEN_DEBUG_UNALIGNED_LOAD
261 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS
262 return _mm_loadu_ps(from);
265 res = _mm_load_sd((
const double*)(from)) ;
266 res = _mm_loadh_pd(res, (
const double*)(from+2)) ;
267 return _mm_castpd_ps(res);
270 template<> EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(
const double* from)
272 EIGEN_DEBUG_UNALIGNED_LOAD
273 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS
274 return _mm_loadu_pd(from);
277 res = _mm_load_sd(from) ;
278 res = _mm_loadh_pd(res,from+1);
282 template<> EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(
const int* from)
284 EIGEN_DEBUG_UNALIGNED_LOAD
285 #if EIGEN_AVOID_CUSTOM_UNALIGNED_LOADS
286 return _mm_loadu_si128(reinterpret_cast<const Packet4i*>(from));
289 res = _mm_load_sd((
const double*)(from)) ;
290 res = _mm_loadh_pd(res, (
const double*)(from+2)) ;
291 return _mm_castpd_si128(res);
296 template<> EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(
const float* from)
298 return vec4f_swizzle1(_mm_castpd_ps(_mm_load_sd(reinterpret_cast<const double*>(from))), 0, 0, 1, 1);
300 template<> EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(
const double* from)
301 {
return pset1<Packet2d>(from[0]); }
302 template<> EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(
const int* from)
305 tmp = _mm_loadl_epi64(reinterpret_cast<const Packet4i*>(from));
306 return vec4i_swizzle1(tmp, 0, 0, 1, 1);
309 template<> EIGEN_STRONG_INLINE
void pstore<float>(
float* to,
const Packet4f& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_ps(to, from); }
310 template<> EIGEN_STRONG_INLINE
void pstore<double>(
double* to,
const Packet2d& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_pd(to, from); }
311 template<> EIGEN_STRONG_INLINE
void pstore<int>(
int* to,
const Packet4i& from) { EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(reinterpret_cast<Packet4i*>(to), from); }
313 template<> EIGEN_STRONG_INLINE
void pstoreu<double>(
double* to,
const Packet2d& from) {
314 EIGEN_DEBUG_UNALIGNED_STORE
315 _mm_storel_pd((to), from);
316 _mm_storeh_pd((to+1), from);
318 template<> EIGEN_STRONG_INLINE
void pstoreu<float>(
float* to,
const Packet4f& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<double*>(to), _mm_castps_pd(from)); }
319 template<> EIGEN_STRONG_INLINE
void pstoreu<int>(
int* to,
const Packet4i& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(reinterpret_cast<double*>(to), _mm_castsi128_pd(from)); }
322 template<> EIGEN_STRONG_INLINE
void pstore1<Packet4f>(
float* to,
const float& a)
324 Packet4f pa = _mm_set_ss(a);
325 pstore(to, vec4f_swizzle1(pa,0,0,0,0));
328 template<> EIGEN_STRONG_INLINE
void pstore1<Packet2d>(
double* to,
const double& a)
330 Packet2d pa = _mm_set_sd(a);
331 pstore(to, vec2d_swizzle1(pa,0,0));
334 template<> EIGEN_STRONG_INLINE
void prefetch<float>(
const float* addr) { _mm_prefetch((
const char*)(addr), _MM_HINT_T0); }
335 template<> EIGEN_STRONG_INLINE
void prefetch<double>(
const double* addr) { _mm_prefetch((
const char*)(addr), _MM_HINT_T0); }
336 template<> EIGEN_STRONG_INLINE
void prefetch<int>(
const int* addr) { _mm_prefetch((
const char*)(addr), _MM_HINT_T0); }
338 #if defined(_MSC_VER) && defined(_WIN64) && !defined(__INTEL_COMPILER)
341 template<> EIGEN_STRONG_INLINE
float pfirst<Packet4f>(
const Packet4f& a) {
return a.m128_f32[0]; }
342 template<> EIGEN_STRONG_INLINE
double pfirst<Packet2d>(
const Packet2d& a) {
return a.m128d_f64[0]; }
343 template<> EIGEN_STRONG_INLINE
int pfirst<Packet4i>(
const Packet4i& a) {
int x = _mm_cvtsi128_si32(a);
return x; }
344 #elif defined(_MSC_VER) && !defined(__INTEL_COMPILER)
346 template<> EIGEN_STRONG_INLINE
float pfirst<Packet4f>(
const Packet4f& a) {
float x = _mm_cvtss_f32(a);
return x; }
347 template<> EIGEN_STRONG_INLINE
double pfirst<Packet2d>(
const Packet2d& a) {
double x = _mm_cvtsd_f64(a);
return x; }
348 template<> EIGEN_STRONG_INLINE
int pfirst<Packet4i>(
const Packet4i& a) {
int x = _mm_cvtsi128_si32(a);
return x; }
350 template<> EIGEN_STRONG_INLINE
float pfirst<Packet4f>(
const Packet4f& a) {
return _mm_cvtss_f32(a); }
351 template<> EIGEN_STRONG_INLINE
double pfirst<Packet2d>(
const Packet2d& a) {
return _mm_cvtsd_f64(a); }
352 template<> EIGEN_STRONG_INLINE
int pfirst<Packet4i>(
const Packet4i& a) {
return _mm_cvtsi128_si32(a); }
355 template<> EIGEN_STRONG_INLINE Packet4f preverse(
const Packet4f& a)
356 {
return _mm_shuffle_ps(a,a,0x1B); }
357 template<> EIGEN_STRONG_INLINE Packet2d preverse(
const Packet2d& a)
358 {
return _mm_shuffle_pd(a,a,0x1); }
359 template<> EIGEN_STRONG_INLINE Packet4i preverse(
const Packet4i& a)
360 {
return _mm_shuffle_epi32(a,0x1B); }
363 template<> EIGEN_STRONG_INLINE Packet4f pabs(
const Packet4f& a)
365 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF));
366 return _mm_and_ps(a,mask);
368 template<> EIGEN_STRONG_INLINE Packet2d pabs(
const Packet2d& a)
370 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0x7FFFFFFF));
371 return _mm_and_pd(a,mask);
373 template<> EIGEN_STRONG_INLINE Packet4i pabs(
const Packet4i& a)
375 #ifdef EIGEN_VECTORIZE_SSSE3
376 return _mm_abs_epi32(a);
378 Packet4i aux = _mm_srai_epi32(a,31);
379 return _mm_sub_epi32(_mm_xor_si128(a,aux),aux);
383 EIGEN_STRONG_INLINE
void punpackp(Packet4f* vecs)
385 vecs[1] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x55));
386 vecs[2] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xAA));
387 vecs[3] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xFF));
388 vecs[0] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x00));
391 #ifdef EIGEN_VECTORIZE_SSE3
393 template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(
const Packet4f* vecs)
395 return _mm_hadd_ps(_mm_hadd_ps(vecs[0], vecs[1]),_mm_hadd_ps(vecs[2], vecs[3]));
397 template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(
const Packet2d* vecs)
399 return _mm_hadd_pd(vecs[0], vecs[1]);
407 template<> EIGEN_STRONG_INLINE
float predux<Packet4f>(
const Packet4f& a)
409 Packet4f tmp0 = _mm_hadd_ps(a,a);
410 return pfirst(_mm_hadd_ps(tmp0, tmp0));
413 template<> EIGEN_STRONG_INLINE
double predux<Packet2d>(
const Packet2d& a) {
return pfirst(_mm_hadd_pd(a, a)); }
423 template<> EIGEN_STRONG_INLINE
float predux<Packet4f>(
const Packet4f& a)
425 Packet4f tmp = _mm_add_ps(a, _mm_movehl_ps(a,a));
426 return pfirst(_mm_add_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
428 template<> EIGEN_STRONG_INLINE
double predux<Packet2d>(
const Packet2d& a)
430 return pfirst(_mm_add_sd(a, _mm_unpackhi_pd(a,a)));
433 template<> EIGEN_STRONG_INLINE Packet4f preduxp<Packet4f>(
const Packet4f* vecs)
435 Packet4f tmp0, tmp1, tmp2;
436 tmp0 = _mm_unpacklo_ps(vecs[0], vecs[1]);
437 tmp1 = _mm_unpackhi_ps(vecs[0], vecs[1]);
438 tmp2 = _mm_unpackhi_ps(vecs[2], vecs[3]);
439 tmp0 = _mm_add_ps(tmp0, tmp1);
440 tmp1 = _mm_unpacklo_ps(vecs[2], vecs[3]);
441 tmp1 = _mm_add_ps(tmp1, tmp2);
442 tmp2 = _mm_movehl_ps(tmp1, tmp0);
443 tmp0 = _mm_movelh_ps(tmp0, tmp1);
444 return _mm_add_ps(tmp0, tmp2);
447 template<> EIGEN_STRONG_INLINE Packet2d preduxp<Packet2d>(
const Packet2d* vecs)
449 return _mm_add_pd(_mm_unpacklo_pd(vecs[0], vecs[1]), _mm_unpackhi_pd(vecs[0], vecs[1]));
453 template<> EIGEN_STRONG_INLINE
int predux<Packet4i>(
const Packet4i& a)
455 Packet4i tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a,a));
456 return pfirst(tmp) + pfirst(_mm_shuffle_epi32(tmp, 1));
459 template<> EIGEN_STRONG_INLINE Packet4i preduxp<Packet4i>(
const Packet4i* vecs)
461 Packet4i tmp0, tmp1, tmp2;
462 tmp0 = _mm_unpacklo_epi32(vecs[0], vecs[1]);
463 tmp1 = _mm_unpackhi_epi32(vecs[0], vecs[1]);
464 tmp2 = _mm_unpackhi_epi32(vecs[2], vecs[3]);
465 tmp0 = _mm_add_epi32(tmp0, tmp1);
466 tmp1 = _mm_unpacklo_epi32(vecs[2], vecs[3]);
467 tmp1 = _mm_add_epi32(tmp1, tmp2);
468 tmp2 = _mm_unpacklo_epi64(tmp0, tmp1);
469 tmp0 = _mm_unpackhi_epi64(tmp0, tmp1);
470 return _mm_add_epi32(tmp0, tmp2);
476 template<> EIGEN_STRONG_INLINE
float predux_mul<Packet4f>(
const Packet4f& a)
478 Packet4f tmp = _mm_mul_ps(a, _mm_movehl_ps(a,a));
479 return pfirst(_mm_mul_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
481 template<> EIGEN_STRONG_INLINE
double predux_mul<Packet2d>(
const Packet2d& a)
483 return pfirst(_mm_mul_sd(a, _mm_unpackhi_pd(a,a)));
485 template<> EIGEN_STRONG_INLINE
int predux_mul<Packet4i>(
const Packet4i& a)
490 EIGEN_ALIGN16
int aux[4];
492 return (aux[0] * aux[1]) * (aux[2] * aux[3]);;
496 template<> EIGEN_STRONG_INLINE
float predux_min<Packet4f>(
const Packet4f& a)
498 Packet4f tmp = _mm_min_ps(a, _mm_movehl_ps(a,a));
499 return pfirst(_mm_min_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
501 template<> EIGEN_STRONG_INLINE
double predux_min<Packet2d>(
const Packet2d& a)
503 return pfirst(_mm_min_sd(a, _mm_unpackhi_pd(a,a)));
505 template<> EIGEN_STRONG_INLINE
int predux_min<Packet4i>(
const Packet4i& a)
509 EIGEN_ALIGN16
int aux[4];
511 int aux0 = aux[0]<aux[1] ? aux[0] : aux[1];
512 int aux2 = aux[2]<aux[3] ? aux[2] : aux[3];
513 return aux0<aux2 ? aux0 : aux2;
517 template<> EIGEN_STRONG_INLINE
float predux_max<Packet4f>(
const Packet4f& a)
519 Packet4f tmp = _mm_max_ps(a, _mm_movehl_ps(a,a));
520 return pfirst(_mm_max_ss(tmp, _mm_shuffle_ps(tmp,tmp, 1)));
522 template<> EIGEN_STRONG_INLINE
double predux_max<Packet2d>(
const Packet2d& a)
524 return pfirst(_mm_max_sd(a, _mm_unpackhi_pd(a,a)));
526 template<> EIGEN_STRONG_INLINE
int predux_max<Packet4i>(
const Packet4i& a)
530 EIGEN_ALIGN16
int aux[4];
532 int aux0 = aux[0]>aux[1] ? aux[0] : aux[1];
533 int aux2 = aux[2]>aux[3] ? aux[2] : aux[3];
534 return aux0>aux2 ? aux0 : aux2;
537 #if (defined __GNUC__)
552 #ifdef EIGEN_VECTORIZE_SSSE3
555 struct palign_impl<Offset,Packet4f>
557 static EIGEN_STRONG_INLINE
void run(Packet4f& first,
const Packet4f& second)
560 first = _mm_castsi128_ps(_mm_alignr_epi8(_mm_castps_si128(second), _mm_castps_si128(first), Offset*4));
565 struct palign_impl<Offset,Packet4i>
567 static EIGEN_STRONG_INLINE
void run(Packet4i& first,
const Packet4i& second)
570 first = _mm_alignr_epi8(second,first, Offset*4);
575 struct palign_impl<Offset,Packet2d>
577 static EIGEN_STRONG_INLINE
void run(Packet2d& first,
const Packet2d& second)
580 first = _mm_castsi128_pd(_mm_alignr_epi8(_mm_castpd_si128(second), _mm_castpd_si128(first), 8));
586 struct palign_impl<Offset,Packet4f>
588 static EIGEN_STRONG_INLINE
void run(Packet4f& first,
const Packet4f& second)
592 first = _mm_move_ss(first,second);
593 first = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(first),0x39));
597 first = _mm_movehl_ps(first,first);
598 first = _mm_movelh_ps(first,second);
602 first = _mm_move_ss(first,second);
603 first = _mm_shuffle_ps(first,second,0x93);
609 struct palign_impl<Offset,Packet4i>
611 static EIGEN_STRONG_INLINE
void run(Packet4i& first,
const Packet4i& second)
615 first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
616 first = _mm_shuffle_epi32(first,0x39);
620 first = _mm_castps_si128(_mm_movehl_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(first)));
621 first = _mm_castps_si128(_mm_movelh_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
625 first = _mm_castps_si128(_mm_move_ss(_mm_castsi128_ps(first),_mm_castsi128_ps(second)));
626 first = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(first),_mm_castsi128_ps(second),0x93));
632 struct palign_impl<Offset,Packet2d>
634 static EIGEN_STRONG_INLINE
void run(Packet2d& first,
const Packet2d& second)
638 first = _mm_castps_pd(_mm_movehl_ps(_mm_castpd_ps(first),_mm_castpd_ps(first)));
639 first = _mm_castps_pd(_mm_movelh_ps(_mm_castpd_ps(first),_mm_castpd_ps(second)));
649 #endif // EIGEN_PACKET_MATH_SSE_H