10#ifndef EIGEN_PACKET_MATH_SSE_H
11#define EIGEN_PACKET_MATH_SSE_H
15#include "../../InternalHeaderCheck.h"
21#ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
22#define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8
25#if !defined(EIGEN_VECTORIZE_AVX) && !defined(EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS)
28#define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS (2 * sizeof(void*))
31#ifdef EIGEN_VECTORIZE_FMA
32#ifndef EIGEN_HAS_SINGLE_INSTRUCTION_MADD
33#define EIGEN_HAS_SINGLE_INSTRUCTION_MADD
37#if ((defined EIGEN_VECTORIZE_AVX) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_MINGW || EIGEN_COMP_LCC) && \
38 (__GXX_ABI_VERSION < 1004)) || \
45typedef eigen_packet_wrapper<__m128> Packet4f;
46typedef eigen_packet_wrapper<__m128d> Packet2d;
48typedef __m128 Packet4f;
49typedef __m128d Packet2d;
52typedef eigen_packet_wrapper<__m128i, 0> Packet4i;
53typedef eigen_packet_wrapper<__m128i, 1> Packet16b;
54typedef eigen_packet_wrapper<__m128i, 4> Packet4ui;
55typedef eigen_packet_wrapper<__m128i, 5> Packet2l;
58struct is_arithmetic<__m128> {
59 enum { value =
true };
62struct is_arithmetic<__m128i> {
63 enum { value =
true };
66struct is_arithmetic<__m128d> {
67 enum { value =
true };
70struct is_arithmetic<Packet4i> {
71 enum { value =
true };
74struct is_arithmetic<Packet2l> {
75 enum { value =
true };
81struct is_arithmetic<Packet4ui> {
82 enum { value =
false };
85struct is_arithmetic<Packet16b> {
86 enum { value =
true };
89template <
int p,
int q,
int r,
int s>
91 enum { mask = (s) << 6 | (r) << 4 | (q) << 2 | (p) };
95#define vec4f_swizzle1(v, p, q, r, s) \
96 Packet4f(_mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(v), (shuffle_mask<p, q, r, s>::mask))))
98#define vec4i_swizzle1(v, p, q, r, s) Packet4i(_mm_shuffle_epi32(v, (shuffle_mask<p, q, r, s>::mask)))
100#define vec4ui_swizzle1(v, p, q, r, s) Packet4ui(vec4i_swizzle1(v, p, q, r, s))
102#define vec2d_swizzle1(v, p, q) \
103 Packet2d(_mm_castsi128_pd( \
104 _mm_shuffle_epi32(_mm_castpd_si128(v), (shuffle_mask<2 * p, 2 * p + 1, 2 * q, 2 * q + 1>::mask))))
106#define vec4f_swizzle2(a, b, p, q, r, s) Packet4f(_mm_shuffle_ps((a), (b), (shuffle_mask<p, q, r, s>::mask)))
108#define vec4i_swizzle2(a, b, p, q, r, s) \
110 _mm_castps_si128((_mm_shuffle_ps(_mm_castsi128_ps(a), _mm_castsi128_ps(b), (shuffle_mask<p, q, r, s>::mask)))))
112#define vec4ui_swizzle2(a, b, p, q, r, s) Packet4i(vec4i_swizzle2(a, b, p, q, r, s))
114EIGEN_STRONG_INLINE Packet4f vec4f_movelh(
const Packet4f& a,
const Packet4f& b) {
115 return Packet4f(_mm_movelh_ps(a, b));
117EIGEN_STRONG_INLINE Packet4f vec4f_movehl(
const Packet4f& a,
const Packet4f& b) {
118 return Packet4f(_mm_movehl_ps(a, b));
120EIGEN_STRONG_INLINE Packet4f vec4f_unpacklo(
const Packet4f& a,
const Packet4f& b) {
121 return Packet4f(_mm_unpacklo_ps(a, b));
123EIGEN_STRONG_INLINE Packet4f vec4f_unpackhi(
const Packet4f& a,
const Packet4f& b) {
124 return Packet4f(_mm_unpackhi_ps(a, b));
126#define vec4f_duplane(a, p) vec4f_swizzle2(a, a, p, p, p, p)
128#define vec2d_swizzle2(a, b, mask) Packet2d(_mm_shuffle_pd(a, b, mask))
130EIGEN_STRONG_INLINE Packet2d vec2d_unpacklo(
const Packet2d& a,
const Packet2d& b) {
131 return Packet2d(_mm_unpacklo_pd(a, b));
133EIGEN_STRONG_INLINE Packet2d vec2d_unpackhi(
const Packet2d& a,
const Packet2d& b) {
134 return Packet2d(_mm_unpackhi_pd(a, b));
136#define vec2d_duplane(a, p) vec2d_swizzle2(a, a, (p << 1) | p)
138#define EIGEN_DECLARE_CONST_Packet4f(NAME, X) const Packet4f p4f_##NAME = pset1<Packet4f>(X)
140#define EIGEN_DECLARE_CONST_Packet2d(NAME, X) const Packet2d p2d_##NAME = pset1<Packet2d>(X)
142#define EIGEN_DECLARE_CONST_Packet4f_FROM_INT(NAME, X) const Packet4f p4f_##NAME = pset1frombits<Packet4f>(X)
144#define EIGEN_DECLARE_CONST_Packet4i(NAME, X) const Packet4i p4i_##NAME = pset1<Packet4i>(X)
146#define EIGEN_DECLARE_CONST_Packet4ui(NAME, X) const Packet4ui p4ui_##NAME = pset1<Packet4ui>(X)
150EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_0(
const __m128i& a) {
return _mm_cvtsi128_si64(a); }
151#ifdef EIGEN_VECTORIZE_SSE4_1
152EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_1(
const __m128i& a) {
return _mm_extract_epi64(a, 1); }
154EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_1(
const __m128i& a) {
155 return _mm_cvtsi128_si64(_mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(a), _mm_castsi128_pd(a), 0x1)));
161EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_0(
const __m128i& a) {
162 return numext::bit_cast<int64_t>(_mm_cvtsd_f64(_mm_castsi128_pd(a)));
164EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_1(
const __m128i& a) {
165 return numext::bit_cast<int64_t>(_mm_cvtsd_f64(_mm_shuffle_pd(_mm_castsi128_pd(a), _mm_castsi128_pd(a), 0x1)));
171#ifndef EIGEN_VECTORIZE_AVX
173struct packet_traits<float> : default_packet_traits {
174 typedef Packet4f type;
175 typedef Packet4f half;
183 HasReciprocal = EIGEN_FAST_MATH,
184 HasSin = EIGEN_FAST_MATH,
185 HasCos = EIGEN_FAST_MATH,
198 HasTanh = EIGEN_FAST_MATH,
199 HasErf = EIGEN_FAST_MATH,
205struct packet_traits<double> : default_packet_traits {
206 typedef Packet2d type;
207 typedef Packet2d half;
215 HasSin = EIGEN_FAST_MATH,
216 HasCos = EIGEN_FAST_MATH,
226struct packet_traits<int> : default_packet_traits {
227 typedef Packet4i type;
228 typedef Packet4i half;
241struct packet_traits<uint32_t> : default_packet_traits {
242 typedef Packet4ui type;
243 typedef Packet4ui half;
257struct packet_traits<int64_t> : default_packet_traits {
258 typedef Packet2l type;
259 typedef Packet2l half;
273struct packet_traits<bool> : default_packet_traits {
274 typedef Packet16b type;
275 typedef Packet16b half;
295struct unpacket_traits<Packet4f> {
297 typedef Packet4f half;
298 typedef Packet4i integer_packet;
303 masked_load_available =
false,
304 masked_store_available =
false
308struct unpacket_traits<Packet2d> {
310 typedef Packet2d half;
311 typedef Packet2l integer_packet;
316 masked_load_available =
false,
317 masked_store_available =
false
321struct unpacket_traits<Packet2l> {
322 typedef int64_t type;
323 typedef Packet2l half;
328 masked_load_available =
false,
329 masked_store_available =
false
333struct unpacket_traits<Packet4i> {
335 typedef Packet4i half;
340 masked_load_available =
false,
341 masked_store_available =
false
345struct unpacket_traits<Packet4ui> {
346 typedef uint32_t type;
347 typedef Packet4ui half;
352 masked_load_available =
false,
353 masked_store_available =
false
357struct unpacket_traits<Packet16b> {
359 typedef Packet16b half;
364 masked_load_available =
false,
365 masked_store_available =
false
369#ifndef EIGEN_VECTORIZE_AVX
371struct scalar_div_cost<float, true> {
375struct scalar_div_cost<double, true> {
381EIGEN_STRONG_INLINE Packet4f pset1<Packet4f>(
const float& from) {
382 return _mm_set_ps1(from);
385EIGEN_STRONG_INLINE Packet2d pset1<Packet2d>(
const double& from) {
386 return _mm_set1_pd(from);
389EIGEN_STRONG_INLINE Packet2l pset1<Packet2l>(
const int64_t& from) {
390 return _mm_set1_epi64x(from);
393EIGEN_STRONG_INLINE Packet4i pset1<Packet4i>(
const int& from) {
394 return _mm_set1_epi32(from);
397EIGEN_STRONG_INLINE Packet4ui pset1<Packet4ui>(
const uint32_t& from) {
398 return _mm_set1_epi32(numext::bit_cast<int32_t>(from));
401EIGEN_STRONG_INLINE Packet16b pset1<Packet16b>(
const bool& from) {
402 return _mm_set1_epi8(
static_cast<char>(from));
406EIGEN_STRONG_INLINE Packet4f pset1frombits<Packet4f>(
unsigned int from) {
407 return _mm_castsi128_ps(pset1<Packet4i>(from));
410EIGEN_STRONG_INLINE Packet2d pset1frombits<Packet2d>(uint64_t from) {
411 return _mm_castsi128_pd(_mm_set1_epi64x(from));
415EIGEN_STRONG_INLINE Packet4f peven_mask(
const Packet4f& ) {
416 return _mm_castsi128_ps(_mm_set_epi32(0, -1, 0, -1));
419EIGEN_STRONG_INLINE Packet2l peven_mask(
const Packet2l& ) {
420 return _mm_set_epi32(0, 0, -1, -1);
423EIGEN_STRONG_INLINE Packet4i peven_mask(
const Packet4i& ) {
424 return _mm_set_epi32(0, -1, 0, -1);
427EIGEN_STRONG_INLINE Packet4ui peven_mask(
const Packet4ui& ) {
428 return _mm_set_epi32(0, -1, 0, -1);
431EIGEN_STRONG_INLINE Packet2d peven_mask(
const Packet2d& ) {
432 return _mm_castsi128_pd(_mm_set_epi32(0, 0, -1, -1));
436EIGEN_STRONG_INLINE Packet4f pzero(
const Packet4f& ) {
437 return _mm_setzero_ps();
440EIGEN_STRONG_INLINE Packet2d pzero(
const Packet2d& ) {
441 return _mm_setzero_pd();
444EIGEN_STRONG_INLINE Packet2l pzero(
const Packet2l& ) {
445 return _mm_setzero_si128();
448EIGEN_STRONG_INLINE Packet4i pzero(
const Packet4i& ) {
449 return _mm_setzero_si128();
452EIGEN_STRONG_INLINE Packet4ui pzero(
const Packet4ui& ) {
453 return _mm_setzero_si128();
461#if EIGEN_COMP_GNUC_STRICT && (!defined __AVX__)
463EIGEN_STRONG_INLINE Packet4f pload1<Packet4f>(
const float* from) {
464 return vec4f_swizzle1(_mm_load_ss(from), 0, 0, 0, 0);
469EIGEN_STRONG_INLINE Packet4f plset<Packet4f>(
const float& a) {
470 return _mm_add_ps(pset1<Packet4f>(a), _mm_set_ps(3, 2, 1, 0));
473EIGEN_STRONG_INLINE Packet2d plset<Packet2d>(
const double& a) {
474 return _mm_add_pd(pset1<Packet2d>(a), _mm_set_pd(1, 0));
477EIGEN_STRONG_INLINE Packet2l plset<Packet2l>(
const int64_t& a) {
478 return _mm_add_epi32(pset1<Packet2l>(a), _mm_set_epi64x(1, 0));
481EIGEN_STRONG_INLINE Packet4i plset<Packet4i>(
const int& a) {
482 return _mm_add_epi32(pset1<Packet4i>(a), _mm_set_epi32(3, 2, 1, 0));
485EIGEN_STRONG_INLINE Packet4ui plset<Packet4ui>(
const uint32_t& a) {
486 return _mm_add_epi32(pset1<Packet4ui>(a), _mm_set_epi32(3, 2, 1, 0));
490EIGEN_STRONG_INLINE Packet4f padd<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
491 return _mm_add_ps(a, b);
494EIGEN_STRONG_INLINE Packet2d padd<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
495 return _mm_add_pd(a, b);
498EIGEN_STRONG_INLINE Packet2l padd<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
499 return _mm_add_epi64(a, b);
502EIGEN_STRONG_INLINE Packet4i padd<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
503 return _mm_add_epi32(a, b);
506EIGEN_STRONG_INLINE Packet4ui padd<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
507 return _mm_add_epi32(a, b);
511EIGEN_STRONG_INLINE Packet16b padd<Packet16b>(
const Packet16b& a,
const Packet16b& b) {
512 return _mm_or_si128(a, b);
515template <
typename Packet>
516EIGEN_STRONG_INLINE Packet padds(
const Packet& a,
const Packet& b);
518EIGEN_STRONG_INLINE Packet4f padds<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
519 return _mm_add_ss(a, b);
522EIGEN_STRONG_INLINE Packet2d padds<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
523 return _mm_add_sd(a, b);
527EIGEN_STRONG_INLINE Packet4f psub<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
528 return _mm_sub_ps(a, b);
531EIGEN_STRONG_INLINE Packet2d psub<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
532 return _mm_sub_pd(a, b);
535EIGEN_STRONG_INLINE Packet2l psub<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
536 return _mm_sub_epi64(a, b);
539EIGEN_STRONG_INLINE Packet4i psub<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
540 return _mm_sub_epi32(a, b);
543EIGEN_STRONG_INLINE Packet4ui psub<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
544 return _mm_sub_epi32(a, b);
547EIGEN_STRONG_INLINE Packet16b psub<Packet16b>(
const Packet16b& a,
const Packet16b& b) {
548 return _mm_xor_si128(a, b);
552EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(
const Packet4f& a,
const Packet4f& b);
554EIGEN_STRONG_INLINE Packet4f paddsub<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
555#ifdef EIGEN_VECTORIZE_SSE3
556 return _mm_addsub_ps(a, b);
558 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000, 0x0, 0x80000000, 0x0));
559 return padd(a, pxor(mask, b));
564EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(
const Packet2d&,
const Packet2d&);
566EIGEN_STRONG_INLINE Packet2d paddsub<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
567#ifdef EIGEN_VECTORIZE_SSE3
568 return _mm_addsub_pd(a, b);
570 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0, 0x80000000, 0x0, 0x0));
571 return padd(a, pxor(mask, b));
576EIGEN_STRONG_INLINE Packet4f pnegate(
const Packet4f& a) {
577 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x80000000, 0x80000000, 0x80000000, 0x80000000));
578 return _mm_xor_ps(a, mask);
581EIGEN_STRONG_INLINE Packet2d pnegate(
const Packet2d& a) {
582 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0x0, 0x80000000, 0x0, 0x80000000));
583 return _mm_xor_pd(a, mask);
586EIGEN_STRONG_INLINE Packet2l pnegate(
const Packet2l& a) {
587 return psub(pzero(a), a);
591EIGEN_STRONG_INLINE Packet4i pnegate(
const Packet4i& a) {
592 return psub(pzero(a), a);
596EIGEN_STRONG_INLINE Packet4f pconj(
const Packet4f& a) {
600EIGEN_STRONG_INLINE Packet2d pconj(
const Packet2d& a) {
604EIGEN_STRONG_INLINE Packet2l pconj(
const Packet2l& a) {
608EIGEN_STRONG_INLINE Packet4i pconj(
const Packet4i& a) {
613EIGEN_STRONG_INLINE Packet4f pmul<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
614 return _mm_mul_ps(a, b);
617EIGEN_STRONG_INLINE Packet2d pmul<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
618 return _mm_mul_pd(a, b);
621EIGEN_STRONG_INLINE Packet2l pmul<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
623 __m128i upper32_a = _mm_srli_epi64(a, 32);
624 __m128i upper32_b = _mm_srli_epi64(b, 32);
627 __m128i mul1 = _mm_mul_epu32(upper32_a, b);
628 __m128i mul2 = _mm_mul_epu32(upper32_b, a);
630 __m128i mul3 = _mm_mul_epu32(a, b);
632 __m128i high = _mm_slli_epi64(_mm_add_epi64(mul1, mul2), 32);
633 return _mm_add_epi64(high, mul3);
636EIGEN_STRONG_INLINE Packet4i pmul<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
637#ifdef EIGEN_VECTORIZE_SSE4_1
638 return _mm_mullo_epi32(a, b);
641 return vec4i_swizzle1(
642 vec4i_swizzle2(_mm_mul_epu32(a, b), _mm_mul_epu32(vec4i_swizzle1(a, 1, 0, 3, 2), vec4i_swizzle1(b, 1, 0, 3, 2)),
648EIGEN_STRONG_INLINE Packet4ui pmul<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
649#ifdef EIGEN_VECTORIZE_SSE4_1
650 return _mm_mullo_epi32(a, b);
653 return vec4ui_swizzle1(
654 vec4ui_swizzle2(_mm_mul_epu32(a, b),
655 _mm_mul_epu32(vec4ui_swizzle1(a, 1, 0, 3, 2), vec4ui_swizzle1(b, 1, 0, 3, 2)), 0, 2, 0, 2),
661EIGEN_STRONG_INLINE Packet16b pmul<Packet16b>(
const Packet16b& a,
const Packet16b& b) {
662 return _mm_and_si128(a, b);
666EIGEN_STRONG_INLINE Packet4f pdiv<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
667 return _mm_div_ps(a, b);
670EIGEN_STRONG_INLINE Packet2d pdiv<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
671 return _mm_div_pd(a, b);
675EIGEN_STRONG_INLINE Packet4i pdiv<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
676#ifdef EIGEN_VECTORIZE_AVX
677 return _mm256_cvttpd_epi32(_mm256_div_pd(_mm256_cvtepi32_pd(a), _mm256_cvtepi32_pd(b)));
679 __m128i q_lo = _mm_cvttpd_epi32(_mm_div_pd(_mm_cvtepi32_pd(a), _mm_cvtepi32_pd(b)));
680 __m128i q_hi = _mm_cvttpd_epi32(
681 _mm_div_pd(_mm_cvtepi32_pd(vec4i_swizzle1(a, 2, 3, 0, 1)), _mm_cvtepi32_pd(vec4i_swizzle1(b, 2, 3, 0, 1))));
682 return vec4i_swizzle1(_mm_unpacklo_epi32(q_lo, q_hi), 0, 2, 1, 3);
686#ifdef EIGEN_VECTORIZE_FMA
688EIGEN_STRONG_INLINE Packet4f pmadd(
const Packet4f& a,
const Packet4f& b,
const Packet4f& c) {
689 return _mm_fmadd_ps(a, b, c);
692EIGEN_STRONG_INLINE Packet2d pmadd(
const Packet2d& a,
const Packet2d& b,
const Packet2d& c) {
693 return _mm_fmadd_pd(a, b, c);
696EIGEN_STRONG_INLINE Packet4f pmsub(
const Packet4f& a,
const Packet4f& b,
const Packet4f& c) {
697 return _mm_fmsub_ps(a, b, c);
700EIGEN_STRONG_INLINE Packet2d pmsub(
const Packet2d& a,
const Packet2d& b,
const Packet2d& c) {
701 return _mm_fmsub_pd(a, b, c);
704EIGEN_STRONG_INLINE Packet4f pnmadd(
const Packet4f& a,
const Packet4f& b,
const Packet4f& c) {
705 return _mm_fnmadd_ps(a, b, c);
708EIGEN_STRONG_INLINE Packet2d pnmadd(
const Packet2d& a,
const Packet2d& b,
const Packet2d& c) {
709 return _mm_fnmadd_pd(a, b, c);
712EIGEN_STRONG_INLINE Packet4f pnmsub(
const Packet4f& a,
const Packet4f& b,
const Packet4f& c) {
713 return _mm_fnmsub_ps(a, b, c);
716EIGEN_STRONG_INLINE Packet2d pnmsub(
const Packet2d& a,
const Packet2d& b,
const Packet2d& c) {
717 return _mm_fnmsub_pd(a, b, c);
720template <
typename Packet>
721EIGEN_STRONG_INLINE Packet pmadds(
const Packet& a,
const Packet& b,
const Packet& c);
723EIGEN_STRONG_INLINE Packet4f pmadds<Packet4f>(
const Packet4f& a,
const Packet4f& b,
const Packet4f& c) {
724 return _mm_fmadd_ss(a, b, c);
727EIGEN_STRONG_INLINE Packet2d pmadds<Packet2d>(
const Packet2d& a,
const Packet2d& b,
const Packet2d& c) {
728 return _mm_fmadd_sd(a, b, c);
732#ifdef EIGEN_VECTORIZE_SSE4_1
734EIGEN_STRONG_INLINE Packet4f pselect(
const Packet4f& mask,
const Packet4f& a,
const Packet4f& b) {
735 return _mm_blendv_ps(b, a, mask);
739EIGEN_STRONG_INLINE Packet2l pselect(
const Packet2l& mask,
const Packet2l& a,
const Packet2l& b) {
740 return _mm_castpd_si128(_mm_blendv_pd(_mm_castsi128_pd(b), _mm_castsi128_pd(a), _mm_castsi128_pd(mask)));
744EIGEN_STRONG_INLINE Packet4i pselect(
const Packet4i& mask,
const Packet4i& a,
const Packet4i& b) {
745 return _mm_castps_si128(_mm_blendv_ps(_mm_castsi128_ps(b), _mm_castsi128_ps(a), _mm_castsi128_ps(mask)));
749EIGEN_STRONG_INLINE Packet4ui pselect(
const Packet4ui& mask,
const Packet4ui& a,
const Packet4ui& b) {
750 return _mm_castps_si128(_mm_blendv_ps(_mm_castsi128_ps(b), _mm_castsi128_ps(a), _mm_castsi128_ps(mask)));
754EIGEN_STRONG_INLINE Packet2d pselect(
const Packet2d& mask,
const Packet2d& a,
const Packet2d& b) {
755 return _mm_blendv_pd(b, a, mask);
760EIGEN_STRONG_INLINE Packet2l ptrue<Packet2l>(
const Packet2l& a) {
761 return _mm_cmpeq_epi32(a, a);
764EIGEN_STRONG_INLINE Packet4i ptrue<Packet4i>(
const Packet4i& a) {
765 return _mm_cmpeq_epi32(a, a);
768EIGEN_STRONG_INLINE Packet16b ptrue<Packet16b>(
const Packet16b& ) {
769 return pset1<Packet16b>(
true);
772EIGEN_STRONG_INLINE Packet4f ptrue<Packet4f>(
const Packet4f& a) {
773 Packet4i b = _mm_castps_si128(a);
774 return _mm_castsi128_ps(_mm_cmpeq_epi32(b, b));
777EIGEN_STRONG_INLINE Packet2d ptrue<Packet2d>(
const Packet2d& a) {
778 Packet4i b = _mm_castpd_si128(a);
779 return _mm_castsi128_pd(_mm_cmpeq_epi32(b, b));
783EIGEN_STRONG_INLINE Packet4f pand<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
784 return _mm_and_ps(a, b);
787EIGEN_STRONG_INLINE Packet2d pand<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
788 return _mm_and_pd(a, b);
791EIGEN_STRONG_INLINE Packet2l pand<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
792 return _mm_and_si128(a, b);
795EIGEN_STRONG_INLINE Packet4i pand<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
796 return _mm_and_si128(a, b);
799EIGEN_STRONG_INLINE Packet4ui pand<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
800 return _mm_and_si128(a, b);
803EIGEN_STRONG_INLINE Packet16b pand<Packet16b>(
const Packet16b& a,
const Packet16b& b) {
804 return _mm_and_si128(a, b);
808EIGEN_STRONG_INLINE Packet4f por<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
809 return _mm_or_ps(a, b);
812EIGEN_STRONG_INLINE Packet2d por<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
813 return _mm_or_pd(a, b);
816EIGEN_STRONG_INLINE Packet2l por<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
817 return _mm_or_si128(a, b);
820EIGEN_STRONG_INLINE Packet4i por<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
821 return _mm_or_si128(a, b);
824EIGEN_STRONG_INLINE Packet4ui por<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
825 return _mm_or_si128(a, b);
828EIGEN_STRONG_INLINE Packet16b por<Packet16b>(
const Packet16b& a,
const Packet16b& b) {
829 return _mm_or_si128(a, b);
833EIGEN_STRONG_INLINE Packet4f pxor<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
834 return _mm_xor_ps(a, b);
837EIGEN_STRONG_INLINE Packet2d pxor<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
838 return _mm_xor_pd(a, b);
841EIGEN_STRONG_INLINE Packet2l pxor<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
842 return _mm_xor_si128(a, b);
845EIGEN_STRONG_INLINE Packet4i pxor<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
846 return _mm_xor_si128(a, b);
849EIGEN_STRONG_INLINE Packet4ui pxor<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
850 return _mm_xor_si128(a, b);
853EIGEN_STRONG_INLINE Packet16b pxor<Packet16b>(
const Packet16b& a,
const Packet16b& b) {
854 return _mm_xor_si128(a, b);
858EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
859 return _mm_andnot_ps(b, a);
862EIGEN_STRONG_INLINE Packet2d pandnot<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
863 return _mm_andnot_pd(b, a);
866EIGEN_STRONG_INLINE Packet2l pandnot<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
867 return _mm_andnot_si128(b, a);
870EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
871 return _mm_andnot_si128(b, a);
874EIGEN_STRONG_INLINE Packet4ui pandnot<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
875 return _mm_andnot_si128(b, a);
879EIGEN_STRONG_INLINE Packet4f pcmp_le(
const Packet4f& a,
const Packet4f& b) {
880 return _mm_cmple_ps(a, b);
883EIGEN_STRONG_INLINE Packet4f pcmp_lt(
const Packet4f& a,
const Packet4f& b) {
884 return _mm_cmplt_ps(a, b);
887EIGEN_STRONG_INLINE Packet4f pcmp_lt_or_nan(
const Packet4f& a,
const Packet4f& b) {
888 return _mm_cmpnge_ps(a, b);
891EIGEN_STRONG_INLINE Packet4f pcmp_eq(
const Packet4f& a,
const Packet4f& b) {
892 return _mm_cmpeq_ps(a, b);
896EIGEN_STRONG_INLINE Packet2d pcmp_le(
const Packet2d& a,
const Packet2d& b) {
897 return _mm_cmple_pd(a, b);
900EIGEN_STRONG_INLINE Packet2d pcmp_lt(
const Packet2d& a,
const Packet2d& b) {
901 return _mm_cmplt_pd(a, b);
904EIGEN_STRONG_INLINE Packet2d pcmp_lt_or_nan(
const Packet2d& a,
const Packet2d& b) {
905 return _mm_cmpnge_pd(a, b);
908EIGEN_STRONG_INLINE Packet2d pcmp_eq(
const Packet2d& a,
const Packet2d& b) {
909 return _mm_cmpeq_pd(a, b);
912EIGEN_STRONG_INLINE Packet4i pcmp_lt(
const Packet4i& a,
const Packet4i& b) {
913 return _mm_cmplt_epi32(a, b);
916EIGEN_STRONG_INLINE Packet4i pcmp_eq(
const Packet4i& a,
const Packet4i& b) {
917 return _mm_cmpeq_epi32(a, b);
920EIGEN_STRONG_INLINE Packet4i pcmp_le(
const Packet4i& a,
const Packet4i& b) {
921 return por(pcmp_lt(a, b), pcmp_eq(a, b));
924EIGEN_STRONG_INLINE Packet2l pcmp_lt(
const Packet2l& a,
const Packet2l& b) {
925#ifdef EIGEN_VECTORIZE_SSE4_2
926 return _mm_cmpgt_epi64(b, a);
928 Packet4i eq = pcmp_eq<Packet4i>(Packet4i(a), Packet4i(b));
929 Packet2l hi_eq = Packet2l(_mm_shuffle_epi32(eq, (shuffle_mask<1, 1, 3, 3>::mask)));
930 Packet4i lt = pcmp_lt<Packet4i>(Packet4i(a), Packet4i(b));
931 Packet2l hi_lt = Packet2l(_mm_shuffle_epi32(lt, (shuffle_mask<1, 1, 3, 3>::mask)));
932 Packet2l lo_lt = Packet2l(_mm_shuffle_epi32(lt, (shuffle_mask<0, 0, 2, 2>::mask)));
934 return por(hi_lt, pand(hi_eq, lo_lt));
938EIGEN_STRONG_INLINE Packet2l pcmp_eq(
const Packet2l& a,
const Packet2l& b) {
939#ifdef EIGEN_VECTORIZE_SSE4_1
940 return _mm_cmpeq_epi64(a, b);
942 Packet4i tmp = pcmp_eq<Packet4i>(Packet4i(a), Packet4i(b));
943 return Packet2l(pand<Packet4i>(tmp, _mm_shuffle_epi32(tmp, (shuffle_mask<1, 0, 3, 2>::mask))));
947EIGEN_STRONG_INLINE Packet2l pcmp_le(
const Packet2l& a,
const Packet2l& b) {
948 return por(pcmp_lt(a, b), pcmp_eq(a, b));
951EIGEN_STRONG_INLINE Packet16b pcmp_eq(
const Packet16b& a,
const Packet16b& b) {
953 const Packet16b kBoolMask = pset1<Packet16b>(
true);
954 return _mm_and_si128(_mm_cmpeq_epi8(a, b), kBoolMask);
957EIGEN_STRONG_INLINE Packet4ui pcmp_eq(
const Packet4ui& a,
const Packet4ui& b) {
958 return _mm_cmpeq_epi32(a, b);
962EIGEN_STRONG_INLINE Packet4f pmin<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
963#if EIGEN_GNUC_STRICT_LESS_THAN(6, 3, 0)
968#ifdef EIGEN_VECTORIZE_AVX
970 asm(
"vminps %[a], %[b], %[res]" : [res]
"=x"(res) : [a]
"x"(a), [b]
"x"(b));
973 asm(
"minps %[a], %[res]" : [res]
"+x"(res) : [a]
"x"(a));
978 return _mm_min_ps(b, a);
982EIGEN_STRONG_INLINE Packet2d pmin<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
983#if EIGEN_GNUC_STRICT_LESS_THAN(6, 3, 0)
988#ifdef EIGEN_VECTORIZE_AVX
990 asm(
"vminpd %[a], %[b], %[res]" : [res]
"=x"(res) : [a]
"x"(a), [b]
"x"(b));
993 asm(
"minpd %[a], %[res]" : [res]
"+x"(res) : [a]
"x"(a));
998 return _mm_min_pd(b, a);
1002EIGEN_STRONG_INLINE Packet2l pmin<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
1003 Packet2l a_lt_mask = pcmp_lt(a, b);
1004 return por(pandnot(b, a_lt_mask), pand(a, a_lt_mask));
1007EIGEN_STRONG_INLINE Packet4i pmin<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
1008#ifdef EIGEN_VECTORIZE_SSE4_1
1009 return _mm_min_epi32(a, b);
1012 Packet4i mask = _mm_cmplt_epi32(a, b);
1013 return _mm_or_si128(_mm_and_si128(mask, a), _mm_andnot_si128(mask, b));
1017EIGEN_STRONG_INLINE Packet4ui pmin<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
1018#ifdef EIGEN_VECTORIZE_SSE4_1
1019 return _mm_min_epu32(a, b);
1021 return padd((Packet4ui)pmin((Packet4i)psub(a, pset1<Packet4ui>(0x80000000UL)),
1022 (Packet4i)psub(b, pset1<Packet4ui>(0x80000000UL))),
1023 pset1<Packet4ui>(0x80000000UL));
1028EIGEN_STRONG_INLINE Packet4f pmax<Packet4f>(
const Packet4f& a,
const Packet4f& b) {
1029#if EIGEN_GNUC_STRICT_LESS_THAN(6, 3, 0)
1034#ifdef EIGEN_VECTORIZE_AVX
1036 asm(
"vmaxps %[a], %[b], %[res]" : [res]
"=x"(res) : [a]
"x"(a), [b]
"x"(b));
1039 asm(
"maxps %[a], %[res]" : [res]
"+x"(res) : [a]
"x"(a));
1044 return _mm_max_ps(b, a);
1048EIGEN_STRONG_INLINE Packet2d pmax<Packet2d>(
const Packet2d& a,
const Packet2d& b) {
1049#if EIGEN_GNUC_STRICT_LESS_THAN(6, 3, 0)
1054#ifdef EIGEN_VECTORIZE_AVX
1056 asm(
"vmaxpd %[a], %[b], %[res]" : [res]
"=x"(res) : [a]
"x"(a), [b]
"x"(b));
1059 asm(
"maxpd %[a], %[res]" : [res]
"+x"(res) : [a]
"x"(a));
1064 return _mm_max_pd(b, a);
1068EIGEN_STRONG_INLINE Packet2l pmax<Packet2l>(
const Packet2l& a,
const Packet2l& b) {
1069 Packet2l a_lt_mask = pcmp_lt(a, b);
1070 return por(pandnot(a, a_lt_mask), pand(b, a_lt_mask));
1073EIGEN_STRONG_INLINE Packet4i pmax<Packet4i>(
const Packet4i& a,
const Packet4i& b) {
1074#ifdef EIGEN_VECTORIZE_SSE4_1
1075 return _mm_max_epi32(a, b);
1078 Packet4i mask = _mm_cmpgt_epi32(a, b);
1079 return _mm_or_si128(_mm_and_si128(mask, a), _mm_andnot_si128(mask, b));
1083EIGEN_STRONG_INLINE Packet4ui pmax<Packet4ui>(
const Packet4ui& a,
const Packet4ui& b) {
1084#ifdef EIGEN_VECTORIZE_SSE4_1
1085 return _mm_max_epu32(a, b);
1087 return padd((Packet4ui)pmax((Packet4i)psub(a, pset1<Packet4ui>(0x80000000UL)),
1088 (Packet4i)psub(b, pset1<Packet4ui>(0x80000000UL))),
1089 pset1<Packet4ui>(0x80000000UL));
1094EIGEN_STRONG_INLINE Packet4ui pcmp_lt(
const Packet4ui& a,
const Packet4ui& b) {
1095#ifdef EIGEN_VECTORIZE_SSE4_1
1096 return pxor(pcmp_eq(a, pmax(a, b)), ptrue(a));
1098 return (Packet4ui)pcmp_lt((Packet4i)psub(a, pset1<Packet4ui>(0x80000000UL)),
1099 (Packet4i)psub(b, pset1<Packet4ui>(0x80000000UL)));
1103EIGEN_STRONG_INLINE Packet4ui pcmp_le(
const Packet4ui& a,
const Packet4ui& b) {
1104#ifdef EIGEN_VECTORIZE_SSE4_1
1105 return pcmp_eq(a, pmin(a, b));
1107 return (Packet4ui)pcmp_le((Packet4i)psub(a, pset1<Packet4ui>(0x80000000UL)),
1108 (Packet4i)psub(b, pset1<Packet4ui>(0x80000000UL)));
1112template <
typename Packet,
typename Op>
1113EIGEN_STRONG_INLINE Packet pminmax_propagate_numbers(
const Packet& a,
const Packet& b, Op op) {
1116 Packet not_nan_mask_a = pcmp_eq(a, a);
1117 Packet m = op(a, b);
1118 return pselect<Packet>(not_nan_mask_a, m, b);
1121template <
typename Packet,
typename Op>
1122EIGEN_STRONG_INLINE Packet pminmax_propagate_nan(
const Packet& a,
const Packet& b, Op op) {
1125 Packet not_nan_mask_a = pcmp_eq(a, a);
1126 Packet m = op(b, a);
1127 return pselect<Packet>(not_nan_mask_a, m, a);
1132EIGEN_STRONG_INLINE Packet4f pmin<PropagateNumbers, Packet4f>(
const Packet4f& a,
const Packet4f& b) {
1133 return pminmax_propagate_numbers(a, b, pmin<Packet4f>);
1136EIGEN_STRONG_INLINE Packet2d pmin<PropagateNumbers, Packet2d>(
const Packet2d& a,
const Packet2d& b) {
1137 return pminmax_propagate_numbers(a, b, pmin<Packet2d>);
1140EIGEN_STRONG_INLINE Packet4f pmax<PropagateNumbers, Packet4f>(
const Packet4f& a,
const Packet4f& b) {
1141 return pminmax_propagate_numbers(a, b, pmax<Packet4f>);
1144EIGEN_STRONG_INLINE Packet2d pmax<PropagateNumbers, Packet2d>(
const Packet2d& a,
const Packet2d& b) {
1145 return pminmax_propagate_numbers(a, b, pmax<Packet2d>);
1148EIGEN_STRONG_INLINE Packet4f pmin<PropagateNaN, Packet4f>(
const Packet4f& a,
const Packet4f& b) {
1149 return pminmax_propagate_nan(a, b, pmin<Packet4f>);
1152EIGEN_STRONG_INLINE Packet2d pmin<PropagateNaN, Packet2d>(
const Packet2d& a,
const Packet2d& b) {
1153 return pminmax_propagate_nan(a, b, pmin<Packet2d>);
1156EIGEN_STRONG_INLINE Packet4f pmax<PropagateNaN, Packet4f>(
const Packet4f& a,
const Packet4f& b) {
1157 return pminmax_propagate_nan(a, b, pmax<Packet4f>);
1160EIGEN_STRONG_INLINE Packet2d pmax<PropagateNaN, Packet2d>(
const Packet2d& a,
const Packet2d& b) {
1161 return pminmax_propagate_nan(a, b, pmax<Packet2d>);
1165EIGEN_STRONG_INLINE Packet4f psignbit(
const Packet4f& a) {
1166 return _mm_castsi128_ps(_mm_srai_epi32(_mm_castps_si128(a), 31));
1169EIGEN_STRONG_INLINE Packet2d psignbit(
const Packet2d& a) {
1170 Packet4f tmp = psignbit<Packet4f>(_mm_castpd_ps(a));
1171#ifdef EIGEN_VECTORIZE_AVX
1172 return _mm_castps_pd(_mm_permute_ps(tmp, (shuffle_mask<1, 1, 3, 3>::mask)));
1174 return _mm_castps_pd(_mm_shuffle_ps(tmp, tmp, (shuffle_mask<1, 1, 3, 3>::mask)));
1178EIGEN_STRONG_INLINE Packet4i psignbit(
const Packet4i& a) {
1179 return _mm_srai_epi32(a, 31);
1182EIGEN_STRONG_INLINE Packet4ui psignbit(
const Packet4ui& a) {
1186EIGEN_STRONG_INLINE Packet2l psignbit(
const Packet2l& a) {
1187 Packet4i tmp = psignbit<Packet4i>(Packet4i(a));
1188 return Packet2l(_mm_shuffle_epi32(tmp, (shuffle_mask<1, 1, 3, 3>::mask)));
1192EIGEN_STRONG_INLINE Packet2l parithmetic_shift_right(
const Packet2l& a) {
1193 Packet2l signbit = psignbit(a);
1194 return por(_mm_slli_epi64(signbit, 64 - N), _mm_srli_epi64(a, N));
1197EIGEN_STRONG_INLINE Packet2l plogical_shift_right(
const Packet2l& a) {
1198 return _mm_srli_epi64(a, N);
1201EIGEN_STRONG_INLINE Packet2l plogical_shift_left(
const Packet2l& a) {
1202 return _mm_slli_epi64(a, N);
1205EIGEN_STRONG_INLINE Packet4i parithmetic_shift_right(
const Packet4i& a) {
1206 return _mm_srai_epi32(a, N);
1209EIGEN_STRONG_INLINE Packet4i plogical_shift_right(
const Packet4i& a) {
1210 return _mm_srli_epi32(a, N);
1213EIGEN_STRONG_INLINE Packet4i plogical_shift_left(
const Packet4i& a) {
1214 return _mm_slli_epi32(a, N);
1217EIGEN_STRONG_INLINE Packet4ui parithmetic_shift_right(
const Packet4ui& a) {
1218 return _mm_srli_epi32(a, N);
1221EIGEN_STRONG_INLINE Packet4ui plogical_shift_right(
const Packet4ui& a) {
1222 return _mm_srli_epi32(a, N);
1225EIGEN_STRONG_INLINE Packet4ui plogical_shift_left(
const Packet4ui& a) {
1226 return _mm_slli_epi32(a, N);
1230EIGEN_STRONG_INLINE Packet4f pabs(
const Packet4f& a) {
1231 const Packet4f mask = _mm_castsi128_ps(_mm_setr_epi32(0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF));
1232 return _mm_and_ps(a, mask);
1235EIGEN_STRONG_INLINE Packet2d pabs(
const Packet2d& a) {
1236 const Packet2d mask = _mm_castsi128_pd(_mm_setr_epi32(0xFFFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF, 0x7FFFFFFF));
1237 return _mm_and_pd(a, mask);
1240EIGEN_STRONG_INLINE Packet2l pabs(
const Packet2l& a) {
1241 Packet2l signbit = psignbit(a);
1242 return _mm_sub_epi64(_mm_xor_si128(a, signbit), signbit);
1245EIGEN_STRONG_INLINE Packet4i pabs(
const Packet4i& a) {
1246#ifdef EIGEN_VECTORIZE_SSSE3
1247 return _mm_abs_epi32(a);
1249 Packet4i signbit = psignbit(a);
1250 return _mm_sub_epi32(_mm_xor_si128(a, signbit), signbit);
1254EIGEN_STRONG_INLINE Packet4ui pabs(
const Packet4ui& a) {
1258#ifdef EIGEN_VECTORIZE_SSE4_1
1260EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(
const Packet4f& a) {
1262 const Packet4f mask = pset1frombits<Packet4f>(0x80000000u);
1263 const Packet4f prev0dot5 = pset1frombits<Packet4f>(0x3EFFFFFFu);
1264 return _mm_round_ps(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
1268EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(
const Packet2d& a) {
1269 const Packet2d mask = _mm_castsi128_pd(_mm_set_epi64x(0x8000000000000000ull, 0x8000000000000000ull));
1270 const Packet2d prev0dot5 = _mm_castsi128_pd(_mm_set_epi64x(0x3FDFFFFFFFFFFFFFull, 0x3FDFFFFFFFFFFFFFull));
1271 return _mm_round_pd(padd(por(pand(a, mask), prev0dot5), a), _MM_FROUND_TO_ZERO);
1275EIGEN_STRONG_INLINE Packet4f print<Packet4f>(
const Packet4f& a) {
1276 return _mm_round_ps(a, _MM_FROUND_CUR_DIRECTION);
1279EIGEN_STRONG_INLINE Packet2d print<Packet2d>(
const Packet2d& a) {
1280 return _mm_round_pd(a, _MM_FROUND_CUR_DIRECTION);
1284EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(
const Packet4f& a) {
1285 return _mm_ceil_ps(a);
1288EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(
const Packet2d& a) {
1289 return _mm_ceil_pd(a);
1293EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(
const Packet4f& a) {
1294 return _mm_floor_ps(a);
1297EIGEN_STRONG_INLINE Packet2d pfloor<Packet2d>(
const Packet2d& a) {
1298 return _mm_floor_pd(a);
1302EIGEN_STRONG_INLINE Packet4f ptrunc<Packet4f>(
const Packet4f& a) {
1303 return _mm_round_ps(a, _MM_FROUND_TRUNC);
1306EIGEN_STRONG_INLINE Packet2d ptrunc<Packet2d>(
const Packet2d& a) {
1307 return _mm_round_pd(a, _MM_FROUND_TRUNC);
1312EIGEN_STRONG_INLINE Packet4f pload<Packet4f>(
const float* from) {
1313 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_ps(from);
1316EIGEN_STRONG_INLINE Packet2d pload<Packet2d>(
const double* from) {
1317 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_pd(from);
1320EIGEN_STRONG_INLINE Packet2l pload<Packet2l>(
const int64_t* from) {
1321 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_si128(
reinterpret_cast<const __m128i*
>(from));
1324EIGEN_STRONG_INLINE Packet4i pload<Packet4i>(
const int* from) {
1325 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_si128(
reinterpret_cast<const __m128i*
>(from));
1328EIGEN_STRONG_INLINE Packet4ui pload<Packet4ui>(
const uint32_t* from) {
1329 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_si128(
reinterpret_cast<const __m128i*
>(from));
1332EIGEN_STRONG_INLINE Packet16b pload<Packet16b>(
const bool* from) {
1333 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_si128(
reinterpret_cast<const __m128i*
>(from));
1338EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(
const float* from) {
1339 EIGEN_DEBUG_UNALIGNED_LOAD
1340 return _mm_loadu_ps(from);
1346EIGEN_STRONG_INLINE Packet4f ploadu<Packet4f>(
const float* from) {
1347 EIGEN_DEBUG_UNALIGNED_LOAD
1348 return _mm_loadu_ps(from);
1353EIGEN_STRONG_INLINE Packet2d ploadu<Packet2d>(
const double* from) {
1354 EIGEN_DEBUG_UNALIGNED_LOAD
1355 return _mm_loadu_pd(from);
1358EIGEN_STRONG_INLINE Packet2l ploadu<Packet2l>(
const int64_t* from) {
1359 EIGEN_DEBUG_UNALIGNED_LOAD
1360 return _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(from));
1363EIGEN_STRONG_INLINE Packet4i ploadu<Packet4i>(
const int* from) {
1364 EIGEN_DEBUG_UNALIGNED_LOAD
1365 return _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(from));
1368EIGEN_STRONG_INLINE Packet4ui ploadu<Packet4ui>(
const uint32_t* from) {
1369 EIGEN_DEBUG_UNALIGNED_LOAD
1370 return _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(from));
1373EIGEN_STRONG_INLINE Packet16b ploadu<Packet16b>(
const bool* from) {
1374 EIGEN_DEBUG_UNALIGNED_LOAD
1375 return _mm_loadu_si128(
reinterpret_cast<const __m128i*
>(from));
1379template <
typename Packet>
1380EIGEN_STRONG_INLINE Packet ploadl(
const typename unpacket_traits<Packet>::type* from);
1382EIGEN_STRONG_INLINE Packet4f ploadl<Packet4f>(
const float* from) {
1383 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_castpd_ps(_mm_load_sd(
reinterpret_cast<const double*
>(from)));
1386EIGEN_STRONG_INLINE Packet2d ploadl<Packet2d>(
const double* from) {
1387 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_load_sd(from);
1391template <
typename Packet>
1392EIGEN_STRONG_INLINE Packet ploads(
const typename unpacket_traits<Packet>::type* from);
1394EIGEN_STRONG_INLINE Packet4f ploads<Packet4f>(
const float* from) {
1395 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_load_ss(from);
1398EIGEN_STRONG_INLINE Packet2d ploads<Packet2d>(
const double* from) {
1399 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_load_sd(from);
1403EIGEN_STRONG_INLINE Packet4f ploaddup<Packet4f>(
const float* from) {
1404 return vec4f_swizzle1(_mm_castpd_ps(_mm_load_sd(
reinterpret_cast<const double*
>(from))), 0, 0, 1, 1);
1407EIGEN_STRONG_INLINE Packet2d ploaddup<Packet2d>(
const double* from) {
1408 return pset1<Packet2d>(from[0]);
1411EIGEN_STRONG_INLINE Packet2l ploaddup<Packet2l>(
const int64_t* from) {
1412 return pset1<Packet2l>(from[0]);
1415EIGEN_STRONG_INLINE Packet4i ploaddup<Packet4i>(
const int* from) {
1417 tmp = _mm_loadl_epi64(
reinterpret_cast<const __m128i*
>(from));
1418 return vec4i_swizzle1(tmp, 0, 0, 1, 1);
1421EIGEN_STRONG_INLINE Packet4ui ploaddup<Packet4ui>(
const uint32_t* from) {
1423 tmp = _mm_loadl_epi64(
reinterpret_cast<const __m128i*
>(from));
1424 return vec4ui_swizzle1(tmp, 0, 0, 1, 1);
1430EIGEN_STRONG_INLINE Packet16b ploaddup<Packet16b>(
const bool* from) {
1431 __m128i tmp = _mm_castpd_si128(pload1<Packet2d>(
reinterpret_cast<const double*
>(from)));
1432 return _mm_unpacklo_epi8(tmp, tmp);
1438EIGEN_STRONG_INLINE Packet16b ploadquad<Packet16b>(
const bool* from) {
1439 __m128i tmp = _mm_castps_si128(pload1<Packet4f>(
reinterpret_cast<const float*
>(from)));
1440 tmp = _mm_unpacklo_epi8(tmp, tmp);
1441 return _mm_unpacklo_epi16(tmp, tmp);
1445EIGEN_STRONG_INLINE
void pstore<float>(
float* to,
const Packet4f& from) {
1446 EIGEN_DEBUG_ALIGNED_STORE _mm_store_ps(to, from);
1449EIGEN_STRONG_INLINE
void pstore<double>(
double* to,
const Packet2d& from) {
1450 EIGEN_DEBUG_ALIGNED_STORE _mm_store_pd(to, from);
1453EIGEN_STRONG_INLINE
void pstore<int64_t>(int64_t* to,
const Packet2l& from) {
1454 EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(
reinterpret_cast<__m128i*
>(to), from);
1457EIGEN_STRONG_INLINE
void pstore<int>(
int* to,
const Packet4i& from) {
1458 EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(
reinterpret_cast<__m128i*
>(to), from);
1461EIGEN_STRONG_INLINE
void pstore<uint32_t>(uint32_t* to,
const Packet4ui& from) {
1462 EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(
reinterpret_cast<__m128i*
>(to), from);
1465EIGEN_STRONG_INLINE
void pstore<bool>(
bool* to,
const Packet16b& from) {
1466 EIGEN_DEBUG_ALIGNED_STORE _mm_store_si128(
reinterpret_cast<__m128i*
>(to), from);
1470EIGEN_STRONG_INLINE
void pstoreu<double>(
double* to,
const Packet2d& from) {
1471 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_pd(to, from);
1474EIGEN_STRONG_INLINE
void pstoreu<float>(
float* to,
const Packet4f& from) {
1475 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_ps(to, from);
1478EIGEN_STRONG_INLINE
void pstoreu<int64_t>(int64_t* to,
const Packet2l& from) {
1479 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_si128(
reinterpret_cast<__m128i*
>(to), from);
1482EIGEN_STRONG_INLINE
void pstoreu<int>(
int* to,
const Packet4i& from) {
1483 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_si128(
reinterpret_cast<__m128i*
>(to), from);
1486EIGEN_STRONG_INLINE
void pstoreu<uint32_t>(uint32_t* to,
const Packet4ui& from) {
1487 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_si128(
reinterpret_cast<__m128i*
>(to), from);
1490EIGEN_STRONG_INLINE
void pstoreu<bool>(
bool* to,
const Packet16b& from) {
1491 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_si128(
reinterpret_cast<__m128i*
>(to), from);
1494template <
typename Scalar,
typename Packet>
1495EIGEN_STRONG_INLINE
void pstorel(Scalar* to,
const Packet& from);
1497EIGEN_STRONG_INLINE
void pstorel(
float* to,
const Packet4f& from) {
1498 EIGEN_DEBUG_UNALIGNED_STORE _mm_storel_pi(
reinterpret_cast<__m64*
>(to), from);
1501EIGEN_STRONG_INLINE
void pstorel(
double* to,
const Packet2d& from) {
1502 EIGEN_DEBUG_UNALIGNED_STORE _mm_storel_pd(to, from);
1505template <
typename Scalar,
typename Packet>
1506EIGEN_STRONG_INLINE
void pstores(Scalar* to,
const Packet& from);
1508EIGEN_STRONG_INLINE
void pstores(
float* to,
const Packet4f& from) {
1509 EIGEN_DEBUG_UNALIGNED_STORE _mm_store_ss(to, from);
1512EIGEN_STRONG_INLINE
void pstores(
double* to,
const Packet2d& from) {
1513 EIGEN_DEBUG_UNALIGNED_STORE _mm_store_sd(to, from);
1517EIGEN_STRONG_INLINE Packet4f preverse(
const Packet4f& a) {
1518 return _mm_shuffle_ps(a, a, 0x1B);
1521EIGEN_STRONG_INLINE Packet2d preverse(
const Packet2d& a) {
1522 return _mm_shuffle_pd(a, a, 0x1);
1525EIGEN_STRONG_INLINE Packet2l preverse(
const Packet2l& a) {
1526 return _mm_castpd_si128(preverse(_mm_castsi128_pd(a)));
1529EIGEN_STRONG_INLINE Packet4i preverse(
const Packet4i& a) {
1530 return _mm_shuffle_epi32(a, 0x1B);
1533EIGEN_STRONG_INLINE Packet4ui preverse(
const Packet4ui& a) {
1534 return _mm_shuffle_epi32(a, 0x1B);
1537EIGEN_STRONG_INLINE Packet16b preverse(
const Packet16b& a) {
1538#ifdef EIGEN_VECTORIZE_SSSE3
1539 __m128i mask = _mm_set_epi8(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
1540 return _mm_shuffle_epi8(a, mask);
1542 Packet16b tmp = _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 1, 2, 3));
1543 tmp = _mm_shufflehi_epi16(_mm_shufflelo_epi16(tmp, _MM_SHUFFLE(2, 3, 0, 1)), _MM_SHUFFLE(2, 3, 0, 1));
1544 return _mm_or_si128(_mm_slli_epi16(tmp, 8), _mm_srli_epi16(tmp, 8));
1548#if EIGEN_COMP_MSVC_STRICT && EIGEN_OS_WIN64
1552EIGEN_STRONG_INLINE
float pfirst<Packet4f>(
const Packet4f& a) {
1553 return a.m128_f32[0];
1556EIGEN_STRONG_INLINE
double pfirst<Packet2d>(
const Packet2d& a) {
1557 return a.m128d_f64[0];
1560EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(
const Packet2l& a) {
1561 int64_t x = _mm_extract_epi64_0(a);
1565EIGEN_STRONG_INLINE
int pfirst<Packet4i>(
const Packet4i& a) {
1566 int x = _mm_cvtsi128_si32(a);
1570EIGEN_STRONG_INLINE uint32_t pfirst<Packet4ui>(
const Packet4ui& a) {
1571 uint32_t x = numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(a));
1574#elif EIGEN_COMP_MSVC_STRICT
1577EIGEN_STRONG_INLINE
float pfirst<Packet4f>(
const Packet4f& a) {
1578 float x = _mm_cvtss_f32(a);
1582EIGEN_STRONG_INLINE
double pfirst<Packet2d>(
const Packet2d& a) {
1583 double x = _mm_cvtsd_f64(a);
1587EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(
const Packet2l& a) {
1588 int64_t x = _mm_extract_epi64_0(a);
1592EIGEN_STRONG_INLINE
int pfirst<Packet4i>(
const Packet4i& a) {
1593 int x = _mm_cvtsi128_si32(a);
1597EIGEN_STRONG_INLINE uint32_t pfirst<Packet4ui>(
const Packet4ui& a) {
1598 uint32_t x = numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(a));
1603EIGEN_STRONG_INLINE
float pfirst<Packet4f>(
const Packet4f& a) {
1604 return _mm_cvtss_f32(a);
1607EIGEN_STRONG_INLINE
double pfirst<Packet2d>(
const Packet2d& a) {
1608 return _mm_cvtsd_f64(a);
1611EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(
const Packet2l& a) {
1612 return _mm_extract_epi64_0(a);
1615EIGEN_STRONG_INLINE
int pfirst<Packet4i>(
const Packet4i& a) {
1616 return _mm_cvtsi128_si32(a);
1619EIGEN_STRONG_INLINE uint32_t pfirst<Packet4ui>(
const Packet4ui& a) {
1620 return numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(a));
1624EIGEN_STRONG_INLINE
bool pfirst<Packet16b>(
const Packet16b& a) {
1625 int x = _mm_cvtsi128_si32(a);
1626 return static_cast<bool>(x & 1);
1630EIGEN_STRONG_INLINE Packet4f pgather<float, Packet4f>(
const float* from, Index stride) {
1631 return _mm_set_ps(from[3 * stride], from[2 * stride], from[1 * stride], from[0 * stride]);
1634EIGEN_STRONG_INLINE Packet2d pgather<double, Packet2d>(
const double* from, Index stride) {
1635 return _mm_set_pd(from[1 * stride], from[0 * stride]);
1638EIGEN_STRONG_INLINE Packet2l pgather<int64_t, Packet2l>(
const int64_t* from, Index stride) {
1639 return _mm_set_epi64x(from[1 * stride], from[0 * stride]);
1642EIGEN_STRONG_INLINE Packet4i pgather<int, Packet4i>(
const int* from, Index stride) {
1643 return _mm_set_epi32(from[3 * stride], from[2 * stride], from[1 * stride], from[0 * stride]);
1646EIGEN_STRONG_INLINE Packet4ui pgather<uint32_t, Packet4ui>(
const uint32_t* from, Index stride) {
1647 return _mm_set_epi32(numext::bit_cast<int32_t>(from[3 * stride]), numext::bit_cast<int32_t>(from[2 * stride]),
1648 numext::bit_cast<int32_t>(from[1 * stride]), numext::bit_cast<int32_t>(from[0 * stride]));
1652EIGEN_STRONG_INLINE Packet16b pgather<bool, Packet16b>(
const bool* from, Index stride) {
1653 return _mm_set_epi8(from[15 * stride], from[14 * stride], from[13 * stride], from[12 * stride], from[11 * stride],
1654 from[10 * stride], from[9 * stride], from[8 * stride], from[7 * stride], from[6 * stride],
1655 from[5 * stride], from[4 * stride], from[3 * stride], from[2 * stride], from[1 * stride],
1660EIGEN_STRONG_INLINE
void pscatter<float, Packet4f>(
float* to,
const Packet4f& from, Index stride) {
1661 to[stride * 0] = pfirst(from);
1662 to[stride * 1] = pfirst(_mm_shuffle_ps(from, from, 1));
1663 to[stride * 2] = pfirst(_mm_shuffle_ps(from, from, 2));
1664 to[stride * 3] = pfirst(_mm_shuffle_ps(from, from, 3));
1667EIGEN_STRONG_INLINE
void pscatter<double, Packet2d>(
double* to,
const Packet2d& from, Index stride) {
1668 to[stride * 0] = pfirst(from);
1669 to[stride * 1] = pfirst(preverse(from));
1672EIGEN_STRONG_INLINE
void pscatter<int64_t, Packet2l>(int64_t* to,
const Packet2l& from, Index stride) {
1673 to[stride * 0] = pfirst(from);
1674 to[stride * 1] = pfirst(preverse(from));
1677EIGEN_STRONG_INLINE
void pscatter<int, Packet4i>(
int* to,
const Packet4i& from, Index stride) {
1678 to[stride * 0] = _mm_cvtsi128_si32(from);
1679 to[stride * 1] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 1));
1680 to[stride * 2] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 2));
1681 to[stride * 3] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 3));
1684EIGEN_STRONG_INLINE
void pscatter<uint32_t, Packet4ui>(uint32_t* to,
const Packet4ui& from, Index stride) {
1685 to[stride * 0] = numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(from));
1686 to[stride * 1] = numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(_mm_shuffle_epi32(from, 1)));
1687 to[stride * 2] = numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(_mm_shuffle_epi32(from, 2)));
1688 to[stride * 3] = numext::bit_cast<uint32_t>(_mm_cvtsi128_si32(_mm_shuffle_epi32(from, 3)));
1691EIGEN_STRONG_INLINE
void pscatter<bool, Packet16b>(
bool* to,
const Packet16b& from, Index stride) {
1692 to[4 * stride * 0] = _mm_cvtsi128_si32(from);
1693 to[4 * stride * 1] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 1));
1694 to[4 * stride * 2] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 2));
1695 to[4 * stride * 3] = _mm_cvtsi128_si32(_mm_shuffle_epi32(from, 3));
1700EIGEN_STRONG_INLINE
void pstore1<Packet4f>(
float* to,
const float& a) {
1701 Packet4f pa = _mm_set_ss(a);
1702 pstore(to, Packet4f(vec4f_swizzle1(pa, 0, 0, 0, 0)));
1706EIGEN_STRONG_INLINE
void pstore1<Packet2d>(
double* to,
const double& a) {
1707 Packet2d pa = _mm_set_sd(a);
1708 pstore(to, Packet2d(vec2d_swizzle1(pa, 0, 0)));
1711#if EIGEN_COMP_PGI && EIGEN_COMP_PGI < 1900
1712typedef const void* SsePrefetchPtrType;
1714typedef const char* SsePrefetchPtrType;
1717#ifndef EIGEN_VECTORIZE_AVX
1719EIGEN_STRONG_INLINE
void prefetch<float>(
const float* addr) {
1720 _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0);
1723EIGEN_STRONG_INLINE
void prefetch<double>(
const double* addr) {
1724 _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0);
1727EIGEN_STRONG_INLINE
void prefetch<int>(
const int* addr) {
1728 _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0);
1731EIGEN_STRONG_INLINE
void prefetch<int64_t>(
const int64_t* addr) {
1732 _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0);
1735EIGEN_STRONG_INLINE
void prefetch<uint32_t>(
const uint32_t* addr) {
1736 _mm_prefetch((SsePrefetchPtrType)(addr), _MM_HINT_T0);
1741EIGEN_STRONG_INLINE Packet4f pfrexp<Packet4f>(
const Packet4f& a, Packet4f& exponent) {
1742 return pfrexp_generic(a, exponent);
1747EIGEN_STRONG_INLINE Packet2d pfrexp_generic_get_biased_exponent(
const Packet2d& a) {
1748 const Packet2d cst_exp_mask = pset1frombits<Packet2d>(
static_cast<uint64_t
>(0x7ff0000000000000ull));
1749 __m128i a_expo = _mm_srli_epi64(_mm_castpd_si128(pand(a, cst_exp_mask)), 52);
1750 return _mm_cvtepi32_pd(vec4i_swizzle1(a_expo, 0, 2, 1, 3));
1754EIGEN_STRONG_INLINE Packet2d pfrexp<Packet2d>(
const Packet2d& a, Packet2d& exponent) {
1755 return pfrexp_generic(a, exponent);
1759EIGEN_STRONG_INLINE Packet4f pldexp<Packet4f>(
const Packet4f& a,
const Packet4f& exponent) {
1760 return pldexp_generic(a, exponent);
1767EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(
const Packet2d& a,
const Packet2d& exponent) {
1769 const Packet2d max_exponent = pset1<Packet2d>(2099.0);
1770 const Packet2d e = pmin(pmax(exponent, pnegate(max_exponent)), max_exponent);
1773 const Packet4i ei = vec4i_swizzle1(_mm_cvtpd_epi32(e), 0, 3, 1, 3);
1776 const Packet4i bias = _mm_set_epi32(0, 1023, 0, 1023);
1777 Packet4i b = parithmetic_shift_right<2>(ei);
1778 Packet2d c = _mm_castsi128_pd(_mm_slli_epi64(padd(b, bias), 52));
1779 Packet2d out = pmul(pmul(pmul(a, c), c), c);
1780 b = psub(psub(psub(ei, b), b), b);
1781 c = _mm_castsi128_pd(_mm_slli_epi64(padd(b, bias), 52));
1789EIGEN_STRONG_INLINE
void pbroadcast4<Packet4f>(
const float* a, Packet4f& a0, Packet4f& a1, Packet4f& a2, Packet4f& a3) {
1790 a3 = pload<Packet4f>(a);
1791 a0 = vec4f_swizzle1(a3, 0, 0, 0, 0);
1792 a1 = vec4f_swizzle1(a3, 1, 1, 1, 1);
1793 a2 = vec4f_swizzle1(a3, 2, 2, 2, 2);
1794 a3 = vec4f_swizzle1(a3, 3, 3, 3, 3);
1797EIGEN_STRONG_INLINE
void pbroadcast4<Packet2d>(
const double* a, Packet2d& a0, Packet2d& a1, Packet2d& a2,
1799#ifdef EIGEN_VECTORIZE_SSE3
1800 a0 = _mm_loaddup_pd(a + 0);
1801 a1 = _mm_loaddup_pd(a + 1);
1802 a2 = _mm_loaddup_pd(a + 2);
1803 a3 = _mm_loaddup_pd(a + 3);
1805 a1 = pload<Packet2d>(a);
1806 a0 = vec2d_swizzle1(a1, 0, 0);
1807 a1 = vec2d_swizzle1(a1, 1, 1);
1808 a3 = pload<Packet2d>(a + 2);
1809 a2 = vec2d_swizzle1(a3, 0, 0);
1810 a3 = vec2d_swizzle1(a3, 1, 1);
1815EIGEN_STRONG_INLINE
void punpackp(Packet4f* vecs) {
1816 vecs[1] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x55));
1817 vecs[2] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xAA));
1818 vecs[3] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0xFF));
1819 vecs[0] = _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(vecs[0]), 0x00));
1823EIGEN_STRONG_INLINE
float predux<Packet4f>(
const Packet4f& a) {
1830 Packet4f tmp = _mm_add_ps(a, _mm_movehl_ps(a, a));
1831 return pfirst<Packet4f>(_mm_add_ss(tmp, _mm_shuffle_ps(tmp, tmp, 1)));
1836EIGEN_STRONG_INLINE
double predux<Packet2d>(
const Packet2d& a) {
1842 return pfirst<Packet2d>(_mm_add_sd(a, _mm_unpackhi_pd(a, a)));
1847EIGEN_STRONG_INLINE int64_t predux<Packet2l>(
const Packet2l& a) {
1848 return pfirst<Packet2l>(_mm_add_epi64(a, _mm_unpackhi_epi64(a, a)));
1851#ifdef EIGEN_VECTORIZE_SSSE3
1853EIGEN_STRONG_INLINE
int predux<Packet4i>(
const Packet4i& a) {
1854 Packet4i tmp0 = _mm_hadd_epi32(a, a);
1855 return pfirst<Packet4i>(_mm_hadd_epi32(tmp0, tmp0));
1858EIGEN_STRONG_INLINE uint32_t predux<Packet4ui>(
const Packet4ui& a) {
1859 Packet4ui tmp0 = _mm_hadd_epi32(a, a);
1860 return pfirst<Packet4ui>(_mm_hadd_epi32(tmp0, tmp0));
1864EIGEN_STRONG_INLINE
int predux<Packet4i>(
const Packet4i& a) {
1865 Packet4i tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a, a));
1866 return pfirst(tmp) + pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1));
1869EIGEN_STRONG_INLINE uint32_t predux<Packet4ui>(
const Packet4ui& a) {
1870 Packet4ui tmp = _mm_add_epi32(a, _mm_unpackhi_epi64(a, a));
1871 return pfirst(tmp) + pfirst<Packet4ui>(_mm_shuffle_epi32(tmp, 1));
1876EIGEN_STRONG_INLINE
bool predux<Packet16b>(
const Packet16b& a) {
1877 Packet4i tmp = _mm_or_si128(a, _mm_unpackhi_epi64(a, a));
1878 return (pfirst(tmp) != 0) || (pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1)) != 0);
1885EIGEN_STRONG_INLINE
float predux_mul<Packet4f>(
const Packet4f& a) {
1886 Packet4f tmp = _mm_mul_ps(a, _mm_movehl_ps(a, a));
1887 return pfirst<Packet4f>(_mm_mul_ss(tmp, _mm_shuffle_ps(tmp, tmp, 1)));
1890EIGEN_STRONG_INLINE
double predux_mul<Packet2d>(
const Packet2d& a) {
1891 return pfirst<Packet2d>(_mm_mul_sd(a, _mm_unpackhi_pd(a, a)));
1894EIGEN_STRONG_INLINE int64_t predux_mul<Packet2l>(
const Packet2l& a) {
1895 EIGEN_ALIGN16 int64_t aux[2];
1897 return aux[0] * aux[1];
1900EIGEN_STRONG_INLINE
int predux_mul<Packet4i>(
const Packet4i& a) {
1904 EIGEN_ALIGN16
int aux[4];
1906 return (aux[0] * aux[1]) * (aux[2] * aux[3]);
1909EIGEN_STRONG_INLINE uint32_t predux_mul<Packet4ui>(
const Packet4ui& a) {
1913 EIGEN_ALIGN16 uint32_t aux[4];
1915 return (aux[0] * aux[1]) * (aux[2] * aux[3]);
1919EIGEN_STRONG_INLINE
bool predux_mul<Packet16b>(
const Packet16b& a) {
1920 Packet4i tmp = _mm_and_si128(a, _mm_unpackhi_epi64(a, a));
1921 return ((pfirst<Packet4i>(tmp) == 0x01010101) && (pfirst<Packet4i>(_mm_shuffle_epi32(tmp, 1)) == 0x01010101));
1926EIGEN_STRONG_INLINE
float predux_min<Packet4f>(
const Packet4f& a) {
1927 Packet4f tmp = _mm_min_ps(a, _mm_movehl_ps(a, a));
1928 return pfirst<Packet4f>(_mm_min_ss(tmp, _mm_shuffle_ps(tmp, tmp, 1)));
1931EIGEN_STRONG_INLINE
double predux_min<Packet2d>(
const Packet2d& a) {
1932 return pfirst<Packet2d>(_mm_min_sd(a, _mm_unpackhi_pd(a, a)));
1935EIGEN_STRONG_INLINE
int predux_min<Packet4i>(
const Packet4i& a) {
1936#ifdef EIGEN_VECTORIZE_SSE4_1
1937 Packet4i tmp = _mm_min_epi32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 0, 3, 2)));
1938 return pfirst<Packet4i>(_mm_min_epi32(tmp, _mm_shuffle_epi32(tmp, 1)));
1942 EIGEN_ALIGN16
int aux[4];
1944 int aux0 = aux[0] < aux[1] ? aux[0] : aux[1];
1945 int aux2 = aux[2] < aux[3] ? aux[2] : aux[3];
1946 return aux0 < aux2 ? aux0 : aux2;
1950EIGEN_STRONG_INLINE uint32_t predux_min<Packet4ui>(
const Packet4ui& a) {
1951#ifdef EIGEN_VECTORIZE_SSE4_1
1952 Packet4ui tmp = _mm_min_epu32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 0, 3, 2)));
1953 return pfirst<Packet4ui>(_mm_min_epu32(tmp, _mm_shuffle_epi32(tmp, 1)));
1957 EIGEN_ALIGN16 uint32_t aux[4];
1959 uint32_t aux0 = aux[0] < aux[1] ? aux[0] : aux[1];
1960 uint32_t aux2 = aux[2] < aux[3] ? aux[2] : aux[3];
1961 return aux0 < aux2 ? aux0 : aux2;
1967EIGEN_STRONG_INLINE
float predux_max<Packet4f>(
const Packet4f& a) {
1968 Packet4f tmp = _mm_max_ps(a, _mm_movehl_ps(a, a));
1969 return pfirst<Packet4f>(_mm_max_ss(tmp, _mm_shuffle_ps(tmp, tmp, 1)));
1972EIGEN_STRONG_INLINE
double predux_max<Packet2d>(
const Packet2d& a) {
1973 return pfirst<Packet2d>(_mm_max_sd(a, _mm_unpackhi_pd(a, a)));
1976EIGEN_STRONG_INLINE
int predux_max<Packet4i>(
const Packet4i& a) {
1977#ifdef EIGEN_VECTORIZE_SSE4_1
1978 Packet4i tmp = _mm_max_epi32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 0, 3, 2)));
1979 return pfirst<Packet4i>(_mm_max_epi32(tmp, _mm_shuffle_epi32(tmp, 1)));
1983 EIGEN_ALIGN16
int aux[4];
1985 int aux0 = aux[0] > aux[1] ? aux[0] : aux[1];
1986 int aux2 = aux[2] > aux[3] ? aux[2] : aux[3];
1987 return aux0 > aux2 ? aux0 : aux2;
1991EIGEN_STRONG_INLINE uint32_t predux_max<Packet4ui>(
const Packet4ui& a) {
1992#ifdef EIGEN_VECTORIZE_SSE4_1
1993 Packet4ui tmp = _mm_max_epu32(a, _mm_shuffle_epi32(a, _MM_SHUFFLE(0, 0, 3, 2)));
1994 return pfirst<Packet4ui>(_mm_max_epu32(tmp, _mm_shuffle_epi32(tmp, 1)));
1998 EIGEN_ALIGN16 uint32_t aux[4];
2000 uint32_t aux0 = aux[0] > aux[1] ? aux[0] : aux[1];
2001 uint32_t aux2 = aux[2] > aux[3] ? aux[2] : aux[3];
2002 return aux0 > aux2 ? aux0 : aux2;
2013EIGEN_STRONG_INLINE
bool predux_any(
const Packet2d& x) {
2014 return _mm_movemask_pd(x) != 0x0;
2018EIGEN_STRONG_INLINE
bool predux_any(
const Packet4f& x) {
2019 return _mm_movemask_ps(x) != 0x0;
2023EIGEN_STRONG_INLINE
bool predux_any(
const Packet2l& x) {
2024 return _mm_movemask_pd(_mm_castsi128_pd(x)) != 0x0;
2028EIGEN_STRONG_INLINE
bool predux_any(
const Packet4i& x) {
2029 return _mm_movemask_ps(_mm_castsi128_ps(x)) != 0x0;
2032EIGEN_STRONG_INLINE
bool predux_any(
const Packet4ui& x) {
2033 return _mm_movemask_ps(_mm_castsi128_ps(x)) != 0x0;
2036EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet4f, 4>& kernel) {
2037 _MM_TRANSPOSE4_PS(kernel.packet[0], kernel.packet[1], kernel.packet[2], kernel.packet[3]);
2040EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2d, 2>& kernel) {
2041 __m128d tmp = _mm_unpackhi_pd(kernel.packet[0], kernel.packet[1]);
2042 kernel.packet[0] = _mm_unpacklo_pd(kernel.packet[0], kernel.packet[1]);
2043 kernel.packet[1] = tmp;
2046EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet2l, 2>& kernel) {
2047 __m128i tmp = _mm_unpackhi_epi64(kernel.packet[0], kernel.packet[1]);
2048 kernel.packet[0] = _mm_unpacklo_epi64(kernel.packet[0], kernel.packet[1]);
2049 kernel.packet[1] = tmp;
2052EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet4i, 4>& kernel) {
2053 __m128i T0 = _mm_unpacklo_epi32(kernel.packet[0], kernel.packet[1]);
2054 __m128i T1 = _mm_unpacklo_epi32(kernel.packet[2], kernel.packet[3]);
2055 __m128i T2 = _mm_unpackhi_epi32(kernel.packet[0], kernel.packet[1]);
2056 __m128i T3 = _mm_unpackhi_epi32(kernel.packet[2], kernel.packet[3]);
2058 kernel.packet[0] = _mm_unpacklo_epi64(T0, T1);
2059 kernel.packet[1] = _mm_unpackhi_epi64(T0, T1);
2060 kernel.packet[2] = _mm_unpacklo_epi64(T2, T3);
2061 kernel.packet[3] = _mm_unpackhi_epi64(T2, T3);
2063EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet4ui, 4>& kernel) {
2064 ptranspose((PacketBlock<Packet4i, 4>&)kernel);
2067EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet16b, 4>& kernel) {
2068 __m128i T0 = _mm_unpacklo_epi8(kernel.packet[0], kernel.packet[1]);
2069 __m128i T1 = _mm_unpackhi_epi8(kernel.packet[0], kernel.packet[1]);
2070 __m128i T2 = _mm_unpacklo_epi8(kernel.packet[2], kernel.packet[3]);
2071 __m128i T3 = _mm_unpackhi_epi8(kernel.packet[2], kernel.packet[3]);
2072 kernel.packet[0] = _mm_unpacklo_epi16(T0, T2);
2073 kernel.packet[1] = _mm_unpackhi_epi16(T0, T2);
2074 kernel.packet[2] = _mm_unpacklo_epi16(T1, T3);
2075 kernel.packet[3] = _mm_unpackhi_epi16(T1, T3);
2078EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet16b, 16>& kernel) {
2091 _mm_unpacklo_epi8(kernel.packet[0], kernel.packet[1]);
2093 _mm_unpackhi_epi8(kernel.packet[0], kernel.packet[1]);
2095 _mm_unpacklo_epi8(kernel.packet[2], kernel.packet[3]);
2097 _mm_unpackhi_epi8(kernel.packet[2], kernel.packet[3]);
2099 _mm_unpacklo_epi8(kernel.packet[4], kernel.packet[5]);
2100 __m128i t5 = _mm_unpackhi_epi8(kernel.packet[4], kernel.packet[5]);
2101 __m128i t6 = _mm_unpacklo_epi8(kernel.packet[6], kernel.packet[7]);
2102 __m128i t7 = _mm_unpackhi_epi8(kernel.packet[6], kernel.packet[7]);
2103 __m128i t8 = _mm_unpacklo_epi8(kernel.packet[8], kernel.packet[9]);
2104 __m128i t9 = _mm_unpackhi_epi8(kernel.packet[8], kernel.packet[9]);
2105 __m128i ta = _mm_unpacklo_epi8(kernel.packet[10], kernel.packet[11]);
2106 __m128i tb = _mm_unpackhi_epi8(kernel.packet[10], kernel.packet[11]);
2107 __m128i tc = _mm_unpacklo_epi8(kernel.packet[12], kernel.packet[13]);
2108 __m128i td = _mm_unpackhi_epi8(kernel.packet[12], kernel.packet[13]);
2109 __m128i te = _mm_unpacklo_epi8(kernel.packet[14], kernel.packet[15]);
2110 __m128i tf = _mm_unpackhi_epi8(kernel.packet[14], kernel.packet[15]);
2112 __m128i s0 = _mm_unpacklo_epi16(t0, t2);
2113 __m128i s1 = _mm_unpackhi_epi16(t0, t2);
2114 __m128i s2 = _mm_unpacklo_epi16(t1, t3);
2115 __m128i s3 = _mm_unpackhi_epi16(t1, t3);
2116 __m128i s4 = _mm_unpacklo_epi16(t4, t6);
2117 __m128i s5 = _mm_unpackhi_epi16(t4, t6);
2118 __m128i s6 = _mm_unpacklo_epi16(t5, t7);
2119 __m128i s7 = _mm_unpackhi_epi16(t5, t7);
2120 __m128i s8 = _mm_unpacklo_epi16(t8, ta);
2121 __m128i s9 = _mm_unpackhi_epi16(t8, ta);
2122 __m128i sa = _mm_unpacklo_epi16(t9, tb);
2123 __m128i sb = _mm_unpackhi_epi16(t9, tb);
2124 __m128i sc = _mm_unpacklo_epi16(tc, te);
2125 __m128i sd = _mm_unpackhi_epi16(tc, te);
2126 __m128i se = _mm_unpacklo_epi16(td, tf);
2127 __m128i sf = _mm_unpackhi_epi16(td, tf);
2129 __m128i u0 = _mm_unpacklo_epi32(s0, s4);
2130 __m128i u1 = _mm_unpackhi_epi32(s0, s4);
2131 __m128i u2 = _mm_unpacklo_epi32(s1, s5);
2132 __m128i u3 = _mm_unpackhi_epi32(s1, s5);
2133 __m128i u4 = _mm_unpacklo_epi32(s2, s6);
2134 __m128i u5 = _mm_unpackhi_epi32(s2, s6);
2135 __m128i u6 = _mm_unpacklo_epi32(s3, s7);
2136 __m128i u7 = _mm_unpackhi_epi32(s3, s7);
2137 __m128i u8 = _mm_unpacklo_epi32(s8, sc);
2138 __m128i u9 = _mm_unpackhi_epi32(s8, sc);
2139 __m128i ua = _mm_unpacklo_epi32(s9, sd);
2140 __m128i ub = _mm_unpackhi_epi32(s9, sd);
2141 __m128i uc = _mm_unpacklo_epi32(sa, se);
2142 __m128i ud = _mm_unpackhi_epi32(sa, se);
2143 __m128i ue = _mm_unpacklo_epi32(sb, sf);
2144 __m128i uf = _mm_unpackhi_epi32(sb, sf);
2146 kernel.packet[0] = _mm_unpacklo_epi64(u0, u8);
2147 kernel.packet[1] = _mm_unpackhi_epi64(u0, u8);
2148 kernel.packet[2] = _mm_unpacklo_epi64(u1, u9);
2149 kernel.packet[3] = _mm_unpackhi_epi64(u1, u9);
2150 kernel.packet[4] = _mm_unpacklo_epi64(u2, ua);
2151 kernel.packet[5] = _mm_unpackhi_epi64(u2, ua);
2152 kernel.packet[6] = _mm_unpacklo_epi64(u3, ub);
2153 kernel.packet[7] = _mm_unpackhi_epi64(u3, ub);
2154 kernel.packet[8] = _mm_unpacklo_epi64(u4, uc);
2155 kernel.packet[9] = _mm_unpackhi_epi64(u4, uc);
2156 kernel.packet[10] = _mm_unpacklo_epi64(u5, ud);
2157 kernel.packet[11] = _mm_unpackhi_epi64(u5, ud);
2158 kernel.packet[12] = _mm_unpacklo_epi64(u6, ue);
2159 kernel.packet[13] = _mm_unpackhi_epi64(u6, ue);
2160 kernel.packet[14] = _mm_unpacklo_epi64(u7, uf);
2161 kernel.packet[15] = _mm_unpackhi_epi64(u7, uf);
2164EIGEN_STRONG_INLINE __m128i sse_blend_mask(
const Selector<2>& ifPacket) {
2165 return _mm_set_epi64x(0 - ifPacket.select[1], 0 - ifPacket.select[0]);
2168EIGEN_STRONG_INLINE __m128i sse_blend_mask(
const Selector<4>& ifPacket) {
2169 return _mm_set_epi32(0 - ifPacket.select[3], 0 - ifPacket.select[2], 0 - ifPacket.select[1], 0 - ifPacket.select[0]);
2173EIGEN_STRONG_INLINE Packet2l pblend(
const Selector<2>& ifPacket,
const Packet2l& thenPacket,
2174 const Packet2l& elsePacket) {
2175 const __m128i true_mask = sse_blend_mask(ifPacket);
2176 return pselect<Packet2l>(true_mask, thenPacket, elsePacket);
2179EIGEN_STRONG_INLINE Packet4i pblend(
const Selector<4>& ifPacket,
const Packet4i& thenPacket,
2180 const Packet4i& elsePacket) {
2181 const __m128i true_mask = sse_blend_mask(ifPacket);
2182 return pselect<Packet4i>(true_mask, thenPacket, elsePacket);
2185EIGEN_STRONG_INLINE Packet4ui pblend(
const Selector<4>& ifPacket,
const Packet4ui& thenPacket,
2186 const Packet4ui& elsePacket) {
2187 return (Packet4ui)pblend(ifPacket, (Packet4i)thenPacket, (Packet4i)elsePacket);
2190EIGEN_STRONG_INLINE Packet4f pblend(
const Selector<4>& ifPacket,
const Packet4f& thenPacket,
2191 const Packet4f& elsePacket) {
2192 const __m128i true_mask = sse_blend_mask(ifPacket);
2193 return pselect<Packet4f>(_mm_castsi128_ps(true_mask), thenPacket, elsePacket);
2196EIGEN_STRONG_INLINE Packet2d pblend(
const Selector<2>& ifPacket,
const Packet2d& thenPacket,
2197 const Packet2d& elsePacket) {
2198 const __m128i true_mask = sse_blend_mask(ifPacket);
2199 return pselect<Packet2d>(_mm_castsi128_pd(true_mask), thenPacket, elsePacket);
2203#ifdef EIGEN_VECTORIZE_FMA
2205EIGEN_STRONG_INLINE
float pmadd(
const float& a,
const float& b,
const float& c) {
2206 return ::fmaf(a, b, c);
2209EIGEN_STRONG_INLINE
double pmadd(
const double& a,
const double& b,
const double& c) {
2210 return ::fma(a, b, c);
2213EIGEN_STRONG_INLINE
float pmsub(
const float& a,
const float& b,
const float& c) {
2214 return ::fmaf(a, b, -c);
2217EIGEN_STRONG_INLINE
double pmsub(
const double& a,
const double& b,
const double& c) {
2218 return ::fma(a, b, -c);
2221EIGEN_STRONG_INLINE
float pnmadd(
const float& a,
const float& b,
const float& c) {
2222 return ::fmaf(-a, b, c);
2225EIGEN_STRONG_INLINE
double pnmadd(
const double& a,
const double& b,
const double& c) {
2226 return ::fma(-a, b, c);
2229EIGEN_STRONG_INLINE
float pnmsub(
const float& a,
const float& b,
const float& c) {
2230 return ::fmaf(-a, b, -c);
2233EIGEN_STRONG_INLINE
double pnmsub(
const double& a,
const double& b,
const double& c) {
2234 return ::fma(-a, b, -c);
2238#ifdef EIGEN_VECTORIZE_SSE4_1
2241EIGEN_STRONG_INLINE __m128i half2floatsse(__m128i h) {
2242 __m128i input = _mm_cvtepu16_epi32(h);
2245 __m128i shifted_exp = _mm_set1_epi32(0x7c00 << 13);
2247 __m128i ou = _mm_slli_epi32(_mm_and_si128(input, _mm_set1_epi32(0x7fff)), 13);
2249 __m128i
exp = _mm_and_si128(ou, shifted_exp);
2251 ou = _mm_add_epi32(ou, _mm_set1_epi32((127 - 15) << 23));
2254 __m128i naninf_mask = _mm_cmpeq_epi32(
exp, shifted_exp);
2256 __m128i naninf_adj = _mm_and_si128(_mm_set1_epi32((128 - 16) << 23), naninf_mask);
2258 ou = _mm_add_epi32(ou, naninf_adj);
2261 __m128i zeroden_mask = _mm_cmpeq_epi32(
exp, _mm_setzero_si128());
2262 __m128i zeroden_adj = _mm_and_si128(zeroden_mask, _mm_set1_epi32(1 << 23));
2264 ou = _mm_add_epi32(ou, zeroden_adj);
2266 __m128i magic = _mm_and_si128(zeroden_mask, _mm_set1_epi32(113 << 23));
2268 ou = _mm_castps_si128(_mm_sub_ps(_mm_castsi128_ps(ou), _mm_castsi128_ps(magic)));
2270 __m128i
sign = _mm_slli_epi32(_mm_and_si128(input, _mm_set1_epi32(0x8000)), 16);
2272 ou = _mm_or_si128(ou,
sign);
2279EIGEN_STRONG_INLINE __m128i float2half(__m128 f) {
2280 __m128i o = _mm_setzero_si128();
2283 __m128i
sign = _mm_set1_epi32(0x80000000u);
2285 sign = _mm_and_si128(
sign, _mm_castps_si128(f));
2287 f = _mm_xor_ps(f, _mm_castsi128_ps(
sign));
2289 __m128i fu = _mm_castps_si128(f);
2291 __m128i f16max = _mm_set1_epi32((127 + 16) << 23);
2292 __m128i f32infty = _mm_set1_epi32(255 << 23);
2295 __m128i infnan_mask = _mm_cmplt_epi32(f16max, _mm_castps_si128(f));
2296 __m128i inf_mask = _mm_cmpgt_epi32(_mm_castps_si128(f), f32infty);
2297 __m128i nan_mask = _mm_andnot_si128(inf_mask, infnan_mask);
2298 __m128i inf_value = _mm_and_si128(inf_mask, _mm_set1_epi32(0x7e00));
2299 __m128i nan_value = _mm_and_si128(nan_mask, _mm_set1_epi32(0x7c00));
2301 __m128i naninf_value = _mm_or_si128(inf_value, nan_value);
2303 __m128i denorm_magic = _mm_set1_epi32(((127 - 15) + (23 - 10) + 1) << 23);
2304 __m128i subnorm_mask = _mm_cmplt_epi32(_mm_castps_si128(f), _mm_set1_epi32(113 << 23));
2306 f = _mm_add_ps(f, _mm_castsi128_ps(denorm_magic));
2308 o = _mm_sub_epi32(_mm_castps_si128(f), denorm_magic);
2309 o = _mm_and_si128(o, subnorm_mask);
2311 o = _mm_or_si128(o, naninf_value);
2313 __m128i mask = _mm_or_si128(infnan_mask, subnorm_mask);
2314 o = _mm_and_si128(o, mask);
2317 __m128i mand_odd = _mm_and_si128(_mm_srli_epi32(fu, 13), _mm_set1_epi32(0x1));
2319 fu = _mm_add_epi32(fu, _mm_set1_epi32(0xc8000fffU));
2321 fu = _mm_add_epi32(fu, mand_odd);
2322 fu = _mm_andnot_si128(mask, fu);
2324 fu = _mm_srli_epi32(fu, 13);
2325 o = _mm_or_si128(fu, o);
2328 o = _mm_or_si128(o, _mm_srli_epi32(
sign, 16));
2331 return _mm_and_si128(o, _mm_set1_epi32(0xffff));
2345template<>
struct is_arithmetic<Packet4h> {
enum { value =
true }; };
2348struct packet_traits<
Eigen::half> : default_packet_traits {
2349 typedef Packet4h type;
2351 typedef Packet4h half;
2354 AlignedOnScalar = 1,
2371template<>
struct unpacket_traits<Packet4h> {
typedef Eigen::half type;
enum {size=4, alignment=
Aligned16, vectorizable=
true, masked_load_available=
false, masked_store_available=
false};
typedef Packet4h half; };
2373template<> EIGEN_STRONG_INLINE Packet4h pset1<Packet4h>(
const Eigen::half& from) {
2375 result.x = _mm_set1_pi16(from.x);
2379template<> EIGEN_STRONG_INLINE Eigen::half pfirst<Packet4h>(
const Packet4h& from) {
2380 return half_impl::raw_uint16_to_half(
static_cast<unsigned short>(_mm_cvtsi64_si32(from.x)));
2383template<> EIGEN_STRONG_INLINE Packet4h pconj(
const Packet4h& a) {
return a; }
2385template<> EIGEN_STRONG_INLINE Packet4h padd<Packet4h>(
const Packet4h& a,
const Packet4h& b) {
2386 __int64_t a64 = _mm_cvtm64_si64(a.x);
2387 __int64_t b64 = _mm_cvtm64_si64(b.x);
2391 Eigen::half ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64));
2392 Eigen::half hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64));
2394 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 16));
2395 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 16));
2397 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 32));
2398 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 32));
2400 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 48));
2401 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 48));
2404 result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
2408template<> EIGEN_STRONG_INLINE Packet4h psub<Packet4h>(
const Packet4h& a,
const Packet4h& b) {
2409 __int64_t a64 = _mm_cvtm64_si64(a.x);
2410 __int64_t b64 = _mm_cvtm64_si64(b.x);
2414 Eigen::half ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64));
2415 Eigen::half hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64));
2417 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 16));
2418 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 16));
2420 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 32));
2421 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 32));
2423 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 48));
2424 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 48));
2427 result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
2431template<> EIGEN_STRONG_INLINE Packet4h pmul<Packet4h>(
const Packet4h& a,
const Packet4h& b) {
2432 __int64_t a64 = _mm_cvtm64_si64(a.x);
2433 __int64_t b64 = _mm_cvtm64_si64(b.x);
2437 Eigen::half ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64));
2438 Eigen::half hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64));
2440 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 16));
2441 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 16));
2443 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 32));
2444 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 32));
2446 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 48));
2447 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 48));
2450 result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
2454template<> EIGEN_STRONG_INLINE Packet4h pdiv<Packet4h>(
const Packet4h& a,
const Packet4h& b) {
2455 __int64_t a64 = _mm_cvtm64_si64(a.x);
2456 __int64_t b64 = _mm_cvtm64_si64(b.x);
2460 Eigen::half ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64));
2461 Eigen::half hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64));
2463 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 16));
2464 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 16));
2466 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 32));
2467 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 32));
2469 ha = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(a64 >> 48));
2470 hb = half_impl::raw_uint16_to_half(
static_cast<unsigned short>(b64 >> 48));
2473 result.x = _mm_set_pi16(h[3].x, h[2].x, h[1].x, h[0].x);
2477template<> EIGEN_STRONG_INLINE Packet4h pload<Packet4h>(
const Eigen::half* from) {
2479 result.x = _mm_cvtsi64_m64(*
reinterpret_cast<const __int64_t*
>(from));
2483template<> EIGEN_STRONG_INLINE Packet4h ploadu<Packet4h>(
const Eigen::half* from) {
2485 result.x = _mm_cvtsi64_m64(*
reinterpret_cast<const __int64_t*
>(from));
2489template<> EIGEN_STRONG_INLINE
void pstore<Eigen::half>(Eigen::half* to,
const Packet4h& from) {
2490 __int64_t r = _mm_cvtm64_si64(from.x);
2491 *(
reinterpret_cast<__int64_t*
>(to)) = r;
2494template<> EIGEN_STRONG_INLINE
void pstoreu<Eigen::half>(Eigen::half* to,
const Packet4h& from) {
2495 __int64_t r = _mm_cvtm64_si64(from.x);
2496 *(
reinterpret_cast<__int64_t*
>(to)) = r;
2499template<> EIGEN_STRONG_INLINE Packet4h
2500ploadquad<Packet4h>(
const Eigen::half* from) {
2501 return pset1<Packet4h>(*from);
2504template<> EIGEN_STRONG_INLINE Packet4h pgather<Eigen::half, Packet4h>(
const Eigen::half* from, Index stride)
2507 result.x = _mm_set_pi16(from[3*stride].x, from[2*stride].x, from[1*stride].x, from[0*stride].x);
2511template<> EIGEN_STRONG_INLINE
void pscatter<Eigen::half, Packet4h>(Eigen::half* to,
const Packet4h& from, Index stride)
2513 __int64_t a = _mm_cvtm64_si64(from.x);
2514 to[stride*0].x =
static_cast<unsigned short>(a);
2515 to[stride*1].x =
static_cast<unsigned short>(a >> 16);
2516 to[stride*2].x =
static_cast<unsigned short>(a >> 32);
2517 to[stride*3].x =
static_cast<unsigned short>(a >> 48);
2520EIGEN_STRONG_INLINE
void
2521ptranspose(PacketBlock<Packet4h,4>& kernel) {
2522 __m64 T0 = _mm_unpacklo_pi16(kernel.packet[0].x, kernel.packet[1].x);
2523 __m64 T1 = _mm_unpacklo_pi16(kernel.packet[2].x, kernel.packet[3].x);
2524 __m64 T2 = _mm_unpackhi_pi16(kernel.packet[0].x, kernel.packet[1].x);
2525 __m64 T3 = _mm_unpackhi_pi16(kernel.packet[2].x, kernel.packet[3].x);
2527 kernel.packet[0].x = _mm_unpacklo_pi32(T0, T1);
2528 kernel.packet[1].x = _mm_unpackhi_pi32(T0, T1);
2529 kernel.packet[2].x = _mm_unpacklo_pi32(T2, T3);
2530 kernel.packet[3].x = _mm_unpackhi_pi32(T2, T3);
2539#if EIGEN_COMP_PGI && EIGEN_COMP_PGI < 1900
2541static inline __m128 _mm_castpd_ps(__m128d x) {
return reinterpret_cast<__m128&
>(x); }
2542static inline __m128i _mm_castpd_si128(__m128d x) {
return reinterpret_cast<__m128i&
>(x); }
2543static inline __m128d _mm_castps_pd(__m128 x) {
return reinterpret_cast<__m128d&
>(x); }
2544static inline __m128i _mm_castps_si128(__m128 x) {
return reinterpret_cast<__m128i&
>(x); }
2545static inline __m128 _mm_castsi128_ps(__m128i x) {
return reinterpret_cast<__m128&
>(x); }
2546static inline __m128d _mm_castsi128_pd(__m128i x) {
return reinterpret_cast<__m128d&
>(x); }
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition Core:137
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_exp_op< typename Derived::Scalar >, const Derived > exp(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sign_op< typename Derived::Scalar >, const Derived > sign(const Eigen::ArrayBase< Derived > &x)