10#ifndef EIGEN_PACKET_MATH_FP16_AVX512_H
11#define EIGEN_PACKET_MATH_FP16_AVX512_H
14#include "../../InternalHeaderCheck.h"
20typedef __m512h Packet32h;
21typedef __m256h Packet16h;
22typedef __m128h Packet8h;
25struct is_arithmetic<Packet8h> {
26 enum { value =
true };
30struct packet_traits<half> : default_packet_traits {
31 typedef Packet32h type;
32 typedef Packet16h half;
58 HasSin = EIGEN_FAST_MATH,
59 HasCos = EIGEN_FAST_MATH,
60 HasTanh = EIGEN_FAST_MATH,
67struct unpacket_traits<Packet32h> {
68 typedef Eigen::half type;
69 typedef Packet16h half;
70 typedef Packet32s integer_packet;
75 masked_load_available =
false,
76 masked_store_available =
false
81struct unpacket_traits<Packet16h> {
82 typedef Eigen::half type;
83 typedef Packet8h half;
84 typedef Packet16s integer_packet;
89 masked_load_available =
false,
90 masked_store_available =
false
95struct unpacket_traits<Packet8h> {
96 typedef Eigen::half type;
97 typedef Packet8h half;
98 typedef Packet8s integer_packet;
103 masked_load_available =
false,
104 masked_store_available =
false
110EIGEN_STRONG_INLINE Packet16f half2float(
const Packet16h& a) {
return _mm512_cvtxph_ps(a); }
112EIGEN_STRONG_INLINE Packet8f half2float(
const Packet8h& a) {
return _mm256_cvtxph_ps(a); }
114EIGEN_STRONG_INLINE Packet16h float2half(
const Packet16f& a) {
return _mm512_cvtxps_ph(a); }
116EIGEN_STRONG_INLINE Packet8h float2half(
const Packet8f& a) {
return _mm256_cvtxps_ph(a); }
123EIGEN_STRONG_INLINE Packet32h pset1<Packet32h>(
const Eigen::half& from) {
124 return _mm512_set1_ph(from.x);
128EIGEN_STRONG_INLINE Packet16h pset1<Packet16h>(
const Eigen::half& from) {
129 return _mm256_set1_ph(from.x);
133EIGEN_STRONG_INLINE Packet8h pset1<Packet8h>(
const Eigen::half& from) {
134 return _mm_set1_ph(from.x);
138EIGEN_STRONG_INLINE Packet32h pzero(
const Packet32h& ) {
139 return _mm512_setzero_ph();
143EIGEN_STRONG_INLINE Packet16h pzero(
const Packet16h& ) {
144 return _mm256_setzero_ph();
148EIGEN_STRONG_INLINE Packet8h pzero(
const Packet8h& ) {
149 return _mm_setzero_ph();
154EIGEN_STRONG_INLINE Packet32h pset1frombits<Packet32h>(
unsigned short from) {
155 return _mm512_castsi512_ph(_mm512_set1_epi16(from));
159EIGEN_STRONG_INLINE Packet16h pset1frombits<Packet16h>(
unsigned short from) {
160 return _mm256_castsi256_ph(_mm256_set1_epi16(from));
164EIGEN_STRONG_INLINE Packet8h pset1frombits<Packet8h>(
unsigned short from) {
165 return _mm_castsi128_ph(_mm_set1_epi16(from));
171EIGEN_STRONG_INLINE Eigen::half pfirst<Packet32h>(
const Packet32h& from) {
172 return Eigen::half(_mm512_cvtsh_h(from));
176EIGEN_STRONG_INLINE Eigen::half pfirst<Packet16h>(
const Packet16h& from) {
177 return Eigen::half(_mm256_cvtsh_h(from));
181EIGEN_STRONG_INLINE Eigen::half pfirst<Packet8h>(
const Packet8h& from) {
182 return Eigen::half(_mm_cvtsh_h(from));
188EIGEN_STRONG_INLINE Packet32h pload<Packet32h>(
const Eigen::half* from) {
189 EIGEN_DEBUG_ALIGNED_LOAD
return _mm512_load_ph(from);
193EIGEN_STRONG_INLINE Packet16h pload<Packet16h>(
const Eigen::half* from) {
194 EIGEN_DEBUG_ALIGNED_LOAD
return _mm256_load_ph(from);
198EIGEN_STRONG_INLINE Packet8h pload<Packet8h>(
const Eigen::half* from) {
199 EIGEN_DEBUG_ALIGNED_LOAD
return _mm_load_ph(from);
205EIGEN_STRONG_INLINE Packet32h ploadu<Packet32h>(
const Eigen::half* from) {
206 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm512_loadu_ph(from);
210EIGEN_STRONG_INLINE Packet16h ploadu<Packet16h>(
const Eigen::half* from) {
211 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm256_loadu_ph(from);
215EIGEN_STRONG_INLINE Packet8h ploadu<Packet8h>(
const Eigen::half* from) {
216 EIGEN_DEBUG_UNALIGNED_LOAD
return _mm_loadu_ph(from);
222EIGEN_STRONG_INLINE
void pstore<half>(Eigen::half* to,
const Packet32h& from) {
223 EIGEN_DEBUG_ALIGNED_STORE _mm512_store_ph(to, from);
227EIGEN_STRONG_INLINE
void pstore<half>(Eigen::half* to,
const Packet16h& from) {
228 EIGEN_DEBUG_ALIGNED_STORE _mm256_store_ph(to, from);
232EIGEN_STRONG_INLINE
void pstore<half>(Eigen::half* to,
const Packet8h& from) {
233 EIGEN_DEBUG_ALIGNED_STORE _mm_store_ph(to, from);
239EIGEN_STRONG_INLINE
void pstoreu<half>(Eigen::half* to,
const Packet32h& from) {
240 EIGEN_DEBUG_UNALIGNED_STORE _mm512_storeu_ph(to, from);
244EIGEN_STRONG_INLINE
void pstoreu<half>(Eigen::half* to,
const Packet16h& from) {
245 EIGEN_DEBUG_UNALIGNED_STORE _mm256_storeu_ph(to, from);
249EIGEN_STRONG_INLINE
void pstoreu<half>(Eigen::half* to,
const Packet8h& from) {
250 EIGEN_DEBUG_UNALIGNED_STORE _mm_storeu_ph(to, from);
255EIGEN_STRONG_INLINE Packet32h ploaddup<Packet32h>(
const Eigen::half* from) {
256 __m512h a = _mm512_castph256_ph512(_mm256_loadu_ph(from));
257 return _mm512_permutexvar_ph(_mm512_set_epi16(15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 6, 6,
258 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0),
263EIGEN_STRONG_INLINE Packet16h ploaddup<Packet16h>(
const Eigen::half* from) {
264 __m256h a = _mm256_castph128_ph256(_mm_loadu_ph(from));
265 return _mm256_permutexvar_ph(_mm256_set_epi16(7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0), a);
269EIGEN_STRONG_INLINE Packet8h ploaddup<Packet8h>(
const Eigen::half* from) {
270 return _mm_set_ph(from[3].x, from[3].x, from[2].x, from[2].x, from[1].x, from[1].x, from[0].x, from[0].x);
275EIGEN_STRONG_INLINE Packet32h ploadquad<Packet32h>(
const Eigen::half* from) {
276 __m512h a = _mm512_castph128_ph512(_mm_loadu_ph(from));
277 return _mm512_permutexvar_ph(
278 _mm512_set_epi16(7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0),
283EIGEN_STRONG_INLINE Packet16h ploadquad<Packet16h>(
const Eigen::half* from) {
284 return _mm256_set_ph(from[3].x, from[3].x, from[3].x, from[3].x, from[2].x, from[2].x, from[2].x, from[2].x,
285 from[1].x, from[1].x, from[1].x, from[1].x, from[0].x, from[0].x, from[0].x, from[0].x);
289EIGEN_STRONG_INLINE Packet8h ploadquad<Packet8h>(
const Eigen::half* from) {
290 return _mm_set_ph(from[1].x, from[1].x, from[1].x, from[1].x, from[0].x, from[0].x, from[0].x, from[0].x);
296EIGEN_STRONG_INLINE Packet32h pabs<Packet32h>(
const Packet32h& a) {
297 return _mm512_abs_ph(a);
301EIGEN_STRONG_INLINE Packet16h pabs<Packet16h>(
const Packet16h& a) {
302 return _mm256_abs_ph(a);
306EIGEN_STRONG_INLINE Packet8h pabs<Packet8h>(
const Packet8h& a) {
307 return _mm_abs_ph(a);
313EIGEN_STRONG_INLINE Packet32h psignbit<Packet32h>(
const Packet32h& a) {
314 return _mm512_castsi512_ph(_mm512_srai_epi16(_mm512_castph_si512(a), 15));
318EIGEN_STRONG_INLINE Packet16h psignbit<Packet16h>(
const Packet16h& a) {
319 return _mm256_castsi256_ph(_mm256_srai_epi16(_mm256_castph_si256(a), 15));
323EIGEN_STRONG_INLINE Packet8h psignbit<Packet8h>(
const Packet8h& a) {
324 return _mm_castsi128_ph(_mm_srai_epi16(_mm_castph_si128(a), 15));
330EIGEN_STRONG_INLINE Packet32h pmin<Packet32h>(
const Packet32h& a,
const Packet32h& b) {
331 return _mm512_min_ph(a, b);
335EIGEN_STRONG_INLINE Packet16h pmin<Packet16h>(
const Packet16h& a,
const Packet16h& b) {
336 return _mm256_min_ph(a, b);
340EIGEN_STRONG_INLINE Packet8h pmin<Packet8h>(
const Packet8h& a,
const Packet8h& b) {
341 return _mm_min_ph(a, b);
347EIGEN_STRONG_INLINE Packet32h pmax<Packet32h>(
const Packet32h& a,
const Packet32h& b) {
348 return _mm512_max_ph(a, b);
352EIGEN_STRONG_INLINE Packet16h pmax<Packet16h>(
const Packet16h& a,
const Packet16h& b) {
353 return _mm256_max_ph(a, b);
357EIGEN_STRONG_INLINE Packet8h pmax<Packet8h>(
const Packet8h& a,
const Packet8h& b) {
358 return _mm_max_ph(a, b);
363EIGEN_STRONG_INLINE Packet32h plset<Packet32h>(
const half& a) {
364 return _mm512_add_ph(pset1<Packet32h>(a), _mm512_set_ph(31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
365 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
369EIGEN_STRONG_INLINE Packet16h plset<Packet16h>(
const half& a) {
370 return _mm256_add_ph(pset1<Packet16h>(a), _mm256_set_ph(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
374EIGEN_STRONG_INLINE Packet8h plset<Packet8h>(
const half& a) {
375 return _mm_add_ph(pset1<Packet8h>(a), _mm_set_ph(7, 6, 5, 4, 3, 2, 1, 0));
381EIGEN_STRONG_INLINE Packet32h por(
const Packet32h& a,
const Packet32h& b) {
382 return _mm512_castsi512_ph(_mm512_or_si512(_mm512_castph_si512(a), _mm512_castph_si512(b)));
386EIGEN_STRONG_INLINE Packet16h por(
const Packet16h& a,
const Packet16h& b) {
387 return _mm256_castsi256_ph(_mm256_or_si256(_mm256_castph_si256(a), _mm256_castph_si256(b)));
391EIGEN_STRONG_INLINE Packet8h por(
const Packet8h& a,
const Packet8h& b) {
392 return _mm_castsi128_ph(_mm_or_si128(_mm_castph_si128(a), _mm_castph_si128(b)));
398EIGEN_STRONG_INLINE Packet32h pxor(
const Packet32h& a,
const Packet32h& b) {
399 return _mm512_castsi512_ph(_mm512_xor_si512(_mm512_castph_si512(a), _mm512_castph_si512(b)));
403EIGEN_STRONG_INLINE Packet16h pxor(
const Packet16h& a,
const Packet16h& b) {
404 return _mm256_castsi256_ph(_mm256_xor_si256(_mm256_castph_si256(a), _mm256_castph_si256(b)));
408EIGEN_STRONG_INLINE Packet8h pxor(
const Packet8h& a,
const Packet8h& b) {
409 return _mm_castsi128_ph(_mm_xor_si128(_mm_castph_si128(a), _mm_castph_si128(b)));
415EIGEN_STRONG_INLINE Packet32h pand(
const Packet32h& a,
const Packet32h& b) {
416 return _mm512_castsi512_ph(_mm512_and_si512(_mm512_castph_si512(a), _mm512_castph_si512(b)));
420EIGEN_STRONG_INLINE Packet16h pand(
const Packet16h& a,
const Packet16h& b) {
421 return _mm256_castsi256_ph(_mm256_and_si256(_mm256_castph_si256(a), _mm256_castph_si256(b)));
425EIGEN_STRONG_INLINE Packet8h pand(
const Packet8h& a,
const Packet8h& b) {
426 return _mm_castsi128_ph(_mm_and_si128(_mm_castph_si128(a), _mm_castph_si128(b)));
432EIGEN_STRONG_INLINE Packet32h pandnot(
const Packet32h& a,
const Packet32h& b) {
433 return _mm512_castsi512_ph(_mm512_andnot_si512(_mm512_castph_si512(b), _mm512_castph_si512(a)));
437EIGEN_STRONG_INLINE Packet16h pandnot(
const Packet16h& a,
const Packet16h& b) {
438 return _mm256_castsi256_ph(_mm256_andnot_si256(_mm256_castph_si256(b), _mm256_castph_si256(a)));
442EIGEN_STRONG_INLINE Packet8h pandnot(
const Packet8h& a,
const Packet8h& b) {
443 return _mm_castsi128_ph(_mm_andnot_si128(_mm_castph_si128(b), _mm_castph_si128(a)));
449EIGEN_DEVICE_FUNC
inline Packet32h pselect(
const Packet32h& mask,
const Packet32h& a,
const Packet32h& b) {
450 __mmask32 mask32 = _mm512_cmp_epi16_mask(_mm512_castph_si512(mask), _mm512_setzero_epi32(), _MM_CMPINT_EQ);
451 return _mm512_mask_blend_ph(mask32, a, b);
455EIGEN_DEVICE_FUNC
inline Packet16h pselect(
const Packet16h& mask,
const Packet16h& a,
const Packet16h& b) {
456 __mmask16 mask16 = _mm256_cmp_epi16_mask(_mm256_castph_si256(mask), _mm256_setzero_si256(), _MM_CMPINT_EQ);
457 return _mm256_mask_blend_ph(mask16, a, b);
461EIGEN_DEVICE_FUNC
inline Packet8h pselect(
const Packet8h& mask,
const Packet8h& a,
const Packet8h& b) {
462 __mmask8 mask8 = _mm_cmp_epi16_mask(_mm_castph_si128(mask), _mm_setzero_si128(), _MM_CMPINT_EQ);
463 return _mm_mask_blend_ph(mask8, a, b);
469EIGEN_STRONG_INLINE Packet32h pcmp_eq(
const Packet32h& a,
const Packet32h& b) {
470 __mmask32 mask = _mm512_cmp_ph_mask(a, b, _CMP_EQ_OQ);
471 return _mm512_castsi512_ph(_mm512_mask_set1_epi16(_mm512_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
475EIGEN_STRONG_INLINE Packet16h pcmp_eq(
const Packet16h& a,
const Packet16h& b) {
476 __mmask16 mask = _mm256_cmp_ph_mask(a, b, _CMP_EQ_OQ);
477 return _mm256_castsi256_ph(_mm256_mask_set1_epi16(_mm256_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
481EIGEN_STRONG_INLINE Packet8h pcmp_eq(
const Packet8h& a,
const Packet8h& b) {
482 __mmask8 mask = _mm_cmp_ph_mask(a, b, _CMP_EQ_OQ);
483 return _mm_castsi128_ph(_mm_mask_set1_epi16(_mm_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
489EIGEN_STRONG_INLINE Packet32h pcmp_le(
const Packet32h& a,
const Packet32h& b) {
490 __mmask32 mask = _mm512_cmp_ph_mask(a, b, _CMP_LE_OQ);
491 return _mm512_castsi512_ph(_mm512_mask_set1_epi16(_mm512_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
495EIGEN_STRONG_INLINE Packet16h pcmp_le(
const Packet16h& a,
const Packet16h& b) {
496 __mmask16 mask = _mm256_cmp_ph_mask(a, b, _CMP_LE_OQ);
497 return _mm256_castsi256_ph(_mm256_mask_set1_epi16(_mm256_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
501EIGEN_STRONG_INLINE Packet8h pcmp_le(
const Packet8h& a,
const Packet8h& b) {
502 __mmask8 mask = _mm_cmp_ph_mask(a, b, _CMP_LE_OQ);
503 return _mm_castsi128_ph(_mm_mask_set1_epi16(_mm_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
509EIGEN_STRONG_INLINE Packet32h pcmp_lt(
const Packet32h& a,
const Packet32h& b) {
510 __mmask32 mask = _mm512_cmp_ph_mask(a, b, _CMP_LT_OQ);
511 return _mm512_castsi512_ph(_mm512_mask_set1_epi16(_mm512_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
515EIGEN_STRONG_INLINE Packet16h pcmp_lt(
const Packet16h& a,
const Packet16h& b) {
516 __mmask16 mask = _mm256_cmp_ph_mask(a, b, _CMP_LT_OQ);
517 return _mm256_castsi256_ph(_mm256_mask_set1_epi16(_mm256_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
521EIGEN_STRONG_INLINE Packet8h pcmp_lt(
const Packet8h& a,
const Packet8h& b) {
522 __mmask8 mask = _mm_cmp_ph_mask(a, b, _CMP_LT_OQ);
523 return _mm_castsi128_ph(_mm_mask_set1_epi16(_mm_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
529EIGEN_STRONG_INLINE Packet32h pcmp_lt_or_nan(
const Packet32h& a,
const Packet32h& b) {
530 __mmask32 mask = _mm512_cmp_ph_mask(a, b, _CMP_NGE_UQ);
531 return _mm512_castsi512_ph(_mm512_mask_set1_epi16(_mm512_set1_epi16(0), mask,
static_cast<short>(0xffffu)));
535EIGEN_STRONG_INLINE Packet16h pcmp_lt_or_nan(
const Packet16h& a,
const Packet16h& b) {
536 __mmask16 mask = _mm256_cmp_ph_mask(a, b, _CMP_NGE_UQ);
537 return _mm256_castsi256_ph(_mm256_mask_set1_epi16(_mm256_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
541EIGEN_STRONG_INLINE Packet8h pcmp_lt_or_nan(
const Packet8h& a,
const Packet8h& b) {
542 __mmask8 mask = _mm_cmp_ph_mask(a, b, _CMP_NGE_UQ);
543 return _mm_castsi128_ph(_mm_mask_set1_epi16(_mm_set1_epi32(0), mask,
static_cast<short>(0xffffu)));
549EIGEN_STRONG_INLINE Packet32h padd<Packet32h>(
const Packet32h& a,
const Packet32h& b) {
550 return _mm512_add_ph(a, b);
554EIGEN_STRONG_INLINE Packet16h padd<Packet16h>(
const Packet16h& a,
const Packet16h& b) {
555 return _mm256_add_ph(a, b);
559EIGEN_STRONG_INLINE Packet8h padd<Packet8h>(
const Packet8h& a,
const Packet8h& b) {
560 return _mm_add_ph(a, b);
566EIGEN_STRONG_INLINE Packet32h psub<Packet32h>(
const Packet32h& a,
const Packet32h& b) {
567 return _mm512_sub_ph(a, b);
571EIGEN_STRONG_INLINE Packet16h psub<Packet16h>(
const Packet16h& a,
const Packet16h& b) {
572 return _mm256_sub_ph(a, b);
576EIGEN_STRONG_INLINE Packet8h psub<Packet8h>(
const Packet8h& a,
const Packet8h& b) {
577 return _mm_sub_ph(a, b);
583EIGEN_STRONG_INLINE Packet32h pmul<Packet32h>(
const Packet32h& a,
const Packet32h& b) {
584 return _mm512_mul_ph(a, b);
588EIGEN_STRONG_INLINE Packet16h pmul<Packet16h>(
const Packet16h& a,
const Packet16h& b) {
589 return _mm256_mul_ph(a, b);
593EIGEN_STRONG_INLINE Packet8h pmul<Packet8h>(
const Packet8h& a,
const Packet8h& b) {
594 return _mm_mul_ph(a, b);
600EIGEN_STRONG_INLINE Packet32h pdiv<Packet32h>(
const Packet32h& a,
const Packet32h& b) {
601 return _mm512_div_ph(a, b);
605EIGEN_STRONG_INLINE Packet16h pdiv<Packet16h>(
const Packet16h& a,
const Packet16h& b) {
606 return _mm256_div_ph(a, b);
610EIGEN_STRONG_INLINE Packet8h pdiv<Packet8h>(
const Packet8h& a,
const Packet8h& b) {
611 return _mm_div_ph(a, b);
618EIGEN_STRONG_INLINE Packet32h pround<Packet32h>(
const Packet32h& a) {
622 const Packet32h signMask =
623 pset1frombits<Packet32h>(
static_cast<numext::uint16_t
>(
static_cast<std::uint16_t
>(0x8000u)));
625 const Packet32h prev0dot5 = pset1frombits<Packet32h>(
static_cast<numext::uint16_t
>(0x37FFu));
627 return _mm512_roundscale_ph(padd(por(pand(a, signMask), prev0dot5), a), _MM_FROUND_TO_ZERO);
631EIGEN_STRONG_INLINE Packet16h pround<Packet16h>(
const Packet16h& a) {
635 const Packet16h signMask =
636 pset1frombits<Packet16h>(
static_cast<numext::uint16_t
>(
static_cast<std::uint16_t
>(0x8000u)));
638 const Packet16h prev0dot5 = pset1frombits<Packet16h>(
static_cast<numext::uint16_t
>(0x37FFu));
640 return _mm256_roundscale_ph(padd(por(pand(a, signMask), prev0dot5), a), _MM_FROUND_TO_ZERO);
644EIGEN_STRONG_INLINE Packet8h pround<Packet8h>(
const Packet8h& a) {
648 const Packet8h signMask = pset1frombits<Packet8h>(
static_cast<numext::uint16_t
>(
static_cast<std::uint16_t
>(0x8000u)));
650 const Packet8h prev0dot5 = pset1frombits<Packet8h>(
static_cast<numext::uint16_t
>(0x37FFu));
652 return _mm_roundscale_ph(padd(por(pand(a, signMask), prev0dot5), a), _MM_FROUND_TO_ZERO);
658EIGEN_STRONG_INLINE Packet32h print<Packet32h>(
const Packet32h& a) {
659 return _mm512_roundscale_ph(a, _MM_FROUND_CUR_DIRECTION);
663EIGEN_STRONG_INLINE Packet16h print<Packet16h>(
const Packet16h& a) {
664 return _mm256_roundscale_ph(a, _MM_FROUND_CUR_DIRECTION);
668EIGEN_STRONG_INLINE Packet8h print<Packet8h>(
const Packet8h& a) {
669 return _mm_roundscale_ph(a, _MM_FROUND_CUR_DIRECTION);
675EIGEN_STRONG_INLINE Packet32h pceil<Packet32h>(
const Packet32h& a) {
676 return _mm512_roundscale_ph(a, _MM_FROUND_TO_POS_INF);
680EIGEN_STRONG_INLINE Packet16h pceil<Packet16h>(
const Packet16h& a) {
681 return _mm256_roundscale_ph(a, _MM_FROUND_TO_POS_INF);
685EIGEN_STRONG_INLINE Packet8h pceil<Packet8h>(
const Packet8h& a) {
686 return _mm_roundscale_ph(a, _MM_FROUND_TO_POS_INF);
692EIGEN_STRONG_INLINE Packet32h pfloor<Packet32h>(
const Packet32h& a) {
693 return _mm512_roundscale_ph(a, _MM_FROUND_TO_NEG_INF);
697EIGEN_STRONG_INLINE Packet16h pfloor<Packet16h>(
const Packet16h& a) {
698 return _mm256_roundscale_ph(a, _MM_FROUND_TO_NEG_INF);
702EIGEN_STRONG_INLINE Packet8h pfloor<Packet8h>(
const Packet8h& a) {
703 return _mm_roundscale_ph(a, _MM_FROUND_TO_NEG_INF);
709EIGEN_STRONG_INLINE Packet32h ptrunc<Packet32h>(
const Packet32h& a) {
710 return _mm512_roundscale_ph(a, _MM_FROUND_TO_ZERO);
714EIGEN_STRONG_INLINE Packet16h ptrunc<Packet16h>(
const Packet16h& a) {
715 return _mm256_roundscale_ph(a, _MM_FROUND_TO_ZERO);
719EIGEN_STRONG_INLINE Packet8h ptrunc<Packet8h>(
const Packet8h& a) {
720 return _mm_roundscale_ph(a, _MM_FROUND_TO_ZERO);
725EIGEN_STRONG_INLINE half predux<Packet32h>(
const Packet32h& a) {
726 return half(_mm512_reduce_add_ph(a));
730EIGEN_STRONG_INLINE half predux<Packet16h>(
const Packet16h& a) {
731 return half(_mm256_reduce_add_ph(a));
735EIGEN_STRONG_INLINE half predux<Packet8h>(
const Packet8h& a) {
736 return half(_mm_reduce_add_ph(a));
741EIGEN_STRONG_INLINE Packet16h predux_half_dowto4<Packet32h>(
const Packet32h& a) {
742 const __m512i bits = _mm512_castph_si512(a);
743 Packet16h lo = _mm256_castsi256_ph(_mm512_castsi512_si256(bits));
744 Packet16h hi = _mm256_castsi256_ph(_mm512_extracti64x4_epi64(bits, 1));
749EIGEN_STRONG_INLINE Packet8h predux_half_dowto4<Packet16h>(
const Packet16h& a) {
750 Packet8h lo = _mm_castsi128_ph(_mm256_castsi256_si128(_mm256_castph_si256(a)));
751 Packet8h hi = _mm_castps_ph(_mm256_extractf128_ps(_mm256_castph_ps(a), 1));
758EIGEN_STRONG_INLINE half predux_max<Packet32h>(
const Packet32h& a) {
759 return half(_mm512_reduce_max_ph(a));
763EIGEN_STRONG_INLINE half predux_max<Packet16h>(
const Packet16h& a) {
764 return half(_mm256_reduce_max_ph(a));
768EIGEN_STRONG_INLINE half predux_max<Packet8h>(
const Packet8h& a) {
769 return half(_mm_reduce_max_ph(a));
775EIGEN_STRONG_INLINE half predux_min<Packet32h>(
const Packet32h& a) {
776 return half(_mm512_reduce_min_ph(a));
780EIGEN_STRONG_INLINE half predux_min<Packet16h>(
const Packet16h& a) {
781 return half(_mm256_reduce_min_ph(a));
785EIGEN_STRONG_INLINE half predux_min<Packet8h>(
const Packet8h& a) {
786 return half(_mm_reduce_min_ph(a));
792EIGEN_STRONG_INLINE half predux_mul<Packet32h>(
const Packet32h& a) {
793 return half(_mm512_reduce_mul_ph(a));
797EIGEN_STRONG_INLINE half predux_mul<Packet16h>(
const Packet16h& a) {
798 return half(_mm256_reduce_mul_ph(a));
802EIGEN_STRONG_INLINE half predux_mul<Packet8h>(
const Packet8h& a) {
803 return half(_mm_reduce_mul_ph(a));
806#ifdef EIGEN_VECTORIZE_FMA
811EIGEN_STRONG_INLINE Packet32h pmadd(
const Packet32h& a,
const Packet32h& b,
const Packet32h& c) {
812 return _mm512_fmadd_ph(a, b, c);
816EIGEN_STRONG_INLINE Packet16h pmadd(
const Packet16h& a,
const Packet16h& b,
const Packet16h& c) {
817 return _mm256_fmadd_ph(a, b, c);
821EIGEN_STRONG_INLINE Packet8h pmadd(
const Packet8h& a,
const Packet8h& b,
const Packet8h& c) {
822 return _mm_fmadd_ph(a, b, c);
828EIGEN_STRONG_INLINE Packet32h pmsub(
const Packet32h& a,
const Packet32h& b,
const Packet32h& c) {
829 return _mm512_fmsub_ph(a, b, c);
833EIGEN_STRONG_INLINE Packet16h pmsub(
const Packet16h& a,
const Packet16h& b,
const Packet16h& c) {
834 return _mm256_fmsub_ph(a, b, c);
838EIGEN_STRONG_INLINE Packet8h pmsub(
const Packet8h& a,
const Packet8h& b,
const Packet8h& c) {
839 return _mm_fmsub_ph(a, b, c);
845EIGEN_STRONG_INLINE Packet32h pnmadd(
const Packet32h& a,
const Packet32h& b,
const Packet32h& c) {
846 return _mm512_fnmadd_ph(a, b, c);
850EIGEN_STRONG_INLINE Packet16h pnmadd(
const Packet16h& a,
const Packet16h& b,
const Packet16h& c) {
851 return _mm256_fnmadd_ph(a, b, c);
855EIGEN_STRONG_INLINE Packet8h pnmadd(
const Packet8h& a,
const Packet8h& b,
const Packet8h& c) {
856 return _mm_fnmadd_ph(a, b, c);
862EIGEN_STRONG_INLINE Packet32h pnmsub(
const Packet32h& a,
const Packet32h& b,
const Packet32h& c) {
863 return _mm512_fnmsub_ph(a, b, c);
867EIGEN_STRONG_INLINE Packet16h pnmsub(
const Packet16h& a,
const Packet16h& b,
const Packet16h& c) {
868 return _mm256_fnmsub_ph(a, b, c);
872EIGEN_STRONG_INLINE Packet8h pnmsub(
const Packet8h& a,
const Packet8h& b,
const Packet8h& c) {
873 return _mm_fnmsub_ph(a, b, c);
881EIGEN_STRONG_INLINE Packet32h pnegate<Packet32h>(
const Packet32h& a) {
882 return _mm512_castsi512_ph(
883 _mm512_xor_si512(_mm512_castph_si512(a), _mm512_set1_epi16(
static_cast<std::uint16_t
>(0x8000u))));
887EIGEN_STRONG_INLINE Packet16h pnegate<Packet16h>(
const Packet16h& a) {
888 return _mm256_castsi256_ph(
889 _mm256_xor_si256(_mm256_castph_si256(a), _mm256_set1_epi16(
static_cast<std::uint16_t
>(0x8000u))));
893EIGEN_STRONG_INLINE Packet8h pnegate<Packet8h>(
const Packet8h& a) {
894 return _mm_castsi128_ph(_mm_xor_si128(_mm_castph_si128(a), _mm_set1_epi16(
static_cast<std::uint16_t
>(0x8000u))));
904EIGEN_STRONG_INLINE Packet32h psqrt<Packet32h>(
const Packet32h& a) {
905 return generic_sqrt_newton_step<Packet32h>::run(a, _mm512_rsqrt_ph(a));
909EIGEN_STRONG_INLINE Packet16h psqrt<Packet16h>(
const Packet16h& a) {
910 return generic_sqrt_newton_step<Packet16h>::run(a, _mm256_rsqrt_ph(a));
914EIGEN_STRONG_INLINE Packet8h psqrt<Packet8h>(
const Packet8h& a) {
915 return generic_sqrt_newton_step<Packet8h>::run(a, _mm_rsqrt_ph(a));
921EIGEN_STRONG_INLINE Packet32h prsqrt<Packet32h>(
const Packet32h& a) {
922 return generic_rsqrt_newton_step<Packet32h, 1>::run(a, _mm512_rsqrt_ph(a));
926EIGEN_STRONG_INLINE Packet16h prsqrt<Packet16h>(
const Packet16h& a) {
927 return generic_rsqrt_newton_step<Packet16h, 1>::run(a, _mm256_rsqrt_ph(a));
931EIGEN_STRONG_INLINE Packet8h prsqrt<Packet8h>(
const Packet8h& a) {
932 return generic_rsqrt_newton_step<Packet8h, 1>::run(a, _mm_rsqrt_ph(a));
938EIGEN_STRONG_INLINE Packet32h preciprocal<Packet32h>(
const Packet32h& a) {
939 return generic_reciprocal_newton_step<Packet32h, 1>::run(a, _mm512_rcp_ph(a));
943EIGEN_STRONG_INLINE Packet16h preciprocal<Packet16h>(
const Packet16h& a) {
944 return generic_reciprocal_newton_step<Packet16h, 1>::run(a, _mm256_rcp_ph(a));
948EIGEN_STRONG_INLINE Packet8h preciprocal<Packet8h>(
const Packet8h& a) {
949 return generic_reciprocal_newton_step<Packet8h, 1>::run(a, _mm_rcp_ph(a));
954EIGEN_DEVICE_FUNC
inline void ptranspose(PacketBlock<Packet32h, 32>& a) {
958 for (
int i = 0; i < 16; i++) {
959 t[2 * i] = _mm512_unpacklo_epi16(_mm512_castph_si512(a.packet[2 * i]), _mm512_castph_si512(a.packet[2 * i + 1]));
961 _mm512_unpackhi_epi16(_mm512_castph_si512(a.packet[2 * i]), _mm512_castph_si512(a.packet[2 * i + 1]));
967 for (
int i = 0; i < 8; i++) {
968 p[4 * i] = _mm512_unpacklo_epi32(t[4 * i], t[4 * i + 2]);
969 p[4 * i + 1] = _mm512_unpackhi_epi32(t[4 * i], t[4 * i + 2]);
970 p[4 * i + 2] = _mm512_unpacklo_epi32(t[4 * i + 1], t[4 * i + 3]);
971 p[4 * i + 3] = _mm512_unpackhi_epi32(t[4 * i + 1], t[4 * i + 3]);
977 for (
int i = 0; i < 4; i++) {
978 q[8 * i] = _mm512_unpacklo_epi64(p[8 * i], p[8 * i + 4]);
979 q[8 * i + 1] = _mm512_unpackhi_epi64(p[8 * i], p[8 * i + 4]);
980 q[8 * i + 2] = _mm512_unpacklo_epi64(p[8 * i + 1], p[8 * i + 5]);
981 q[8 * i + 3] = _mm512_unpackhi_epi64(p[8 * i + 1], p[8 * i + 5]);
982 q[8 * i + 4] = _mm512_unpacklo_epi64(p[8 * i + 2], p[8 * i + 6]);
983 q[8 * i + 5] = _mm512_unpackhi_epi64(p[8 * i + 2], p[8 * i + 6]);
984 q[8 * i + 6] = _mm512_unpacklo_epi64(p[8 * i + 3], p[8 * i + 7]);
985 q[8 * i + 7] = _mm512_unpackhi_epi64(p[8 * i + 3], p[8 * i + 7]);
990#define PACKET32H_TRANSPOSE_HELPER(X, Y) \
992 f[Y * 8] = _mm512_inserti32x4(f[Y * 8], _mm512_extracti32x4_epi32(q[X * 8], Y), X); \
993 f[Y * 8 + 1] = _mm512_inserti32x4(f[Y * 8 + 1], _mm512_extracti32x4_epi32(q[X * 8 + 1], Y), X); \
994 f[Y * 8 + 2] = _mm512_inserti32x4(f[Y * 8 + 2], _mm512_extracti32x4_epi32(q[X * 8 + 2], Y), X); \
995 f[Y * 8 + 3] = _mm512_inserti32x4(f[Y * 8 + 3], _mm512_extracti32x4_epi32(q[X * 8 + 3], Y), X); \
996 f[Y * 8 + 4] = _mm512_inserti32x4(f[Y * 8 + 4], _mm512_extracti32x4_epi32(q[X * 8 + 4], Y), X); \
997 f[Y * 8 + 5] = _mm512_inserti32x4(f[Y * 8 + 5], _mm512_extracti32x4_epi32(q[X * 8 + 5], Y), X); \
998 f[Y * 8 + 6] = _mm512_inserti32x4(f[Y * 8 + 6], _mm512_extracti32x4_epi32(q[X * 8 + 6], Y), X); \
999 f[Y * 8 + 7] = _mm512_inserti32x4(f[Y * 8 + 7], _mm512_extracti32x4_epi32(q[X * 8 + 7], Y), X); \
1002 PACKET32H_TRANSPOSE_HELPER(0, 0);
1003 PACKET32H_TRANSPOSE_HELPER(1, 1);
1004 PACKET32H_TRANSPOSE_HELPER(2, 2);
1005 PACKET32H_TRANSPOSE_HELPER(3, 3);
1007 PACKET32H_TRANSPOSE_HELPER(1, 0);
1008 PACKET32H_TRANSPOSE_HELPER(2, 0);
1009 PACKET32H_TRANSPOSE_HELPER(3, 0);
1010 PACKET32H_TRANSPOSE_HELPER(2, 1);
1011 PACKET32H_TRANSPOSE_HELPER(3, 1);
1012 PACKET32H_TRANSPOSE_HELPER(3, 2);
1014 PACKET32H_TRANSPOSE_HELPER(0, 1);
1015 PACKET32H_TRANSPOSE_HELPER(0, 2);
1016 PACKET32H_TRANSPOSE_HELPER(0, 3);
1017 PACKET32H_TRANSPOSE_HELPER(1, 2);
1018 PACKET32H_TRANSPOSE_HELPER(1, 3);
1019 PACKET32H_TRANSPOSE_HELPER(2, 3);
1021#undef PACKET32H_TRANSPOSE_HELPER
1024 for (
int i = 0; i < 32; i++) {
1025 a.packet[i] = _mm512_castsi512_ph(f[i]);
1029EIGEN_DEVICE_FUNC
inline void ptranspose(PacketBlock<Packet32h, 4>& a) {
1030 __m512i p0, p1, p2, p3, t0, t1, t2, t3, a0, a1, a2, a3;
1031 t0 = _mm512_unpacklo_epi16(_mm512_castph_si512(a.packet[0]), _mm512_castph_si512(a.packet[1]));
1032 t1 = _mm512_unpackhi_epi16(_mm512_castph_si512(a.packet[0]), _mm512_castph_si512(a.packet[1]));
1033 t2 = _mm512_unpacklo_epi16(_mm512_castph_si512(a.packet[2]), _mm512_castph_si512(a.packet[3]));
1034 t3 = _mm512_unpackhi_epi16(_mm512_castph_si512(a.packet[2]), _mm512_castph_si512(a.packet[3]));
1036 p0 = _mm512_unpacklo_epi32(t0, t2);
1037 p1 = _mm512_unpackhi_epi32(t0, t2);
1038 p2 = _mm512_unpacklo_epi32(t1, t3);
1039 p3 = _mm512_unpackhi_epi32(t1, t3);
1046 a0 = _mm512_inserti32x4(a0, _mm512_extracti32x4_epi32(p1, 0), 1);
1047 a1 = _mm512_inserti32x4(a1, _mm512_extracti32x4_epi32(p0, 1), 0);
1049 a0 = _mm512_inserti32x4(a0, _mm512_extracti32x4_epi32(p2, 0), 2);
1050 a2 = _mm512_inserti32x4(a2, _mm512_extracti32x4_epi32(p0, 2), 0);
1052 a0 = _mm512_inserti32x4(a0, _mm512_extracti32x4_epi32(p3, 0), 3);
1053 a3 = _mm512_inserti32x4(a3, _mm512_extracti32x4_epi32(p0, 3), 0);
1055 a1 = _mm512_inserti32x4(a1, _mm512_extracti32x4_epi32(p2, 1), 2);
1056 a2 = _mm512_inserti32x4(a2, _mm512_extracti32x4_epi32(p1, 2), 1);
1058 a2 = _mm512_inserti32x4(a2, _mm512_extracti32x4_epi32(p3, 2), 3);
1059 a3 = _mm512_inserti32x4(a3, _mm512_extracti32x4_epi32(p2, 3), 2);
1061 a1 = _mm512_inserti32x4(a1, _mm512_extracti32x4_epi32(p3, 1), 3);
1062 a3 = _mm512_inserti32x4(a3, _mm512_extracti32x4_epi32(p1, 3), 1);
1064 a.packet[0] = _mm512_castsi512_ph(a0);
1065 a.packet[1] = _mm512_castsi512_ph(a1);
1066 a.packet[2] = _mm512_castsi512_ph(a2);
1067 a.packet[3] = _mm512_castsi512_ph(a3);
1070EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet16h, 16>& kernel) {
1071 __m256i a = _mm256_castph_si256(kernel.packet[0]);
1072 __m256i b = _mm256_castph_si256(kernel.packet[1]);
1073 __m256i c = _mm256_castph_si256(kernel.packet[2]);
1074 __m256i d = _mm256_castph_si256(kernel.packet[3]);
1075 __m256i e = _mm256_castph_si256(kernel.packet[4]);
1076 __m256i f = _mm256_castph_si256(kernel.packet[5]);
1077 __m256i g = _mm256_castph_si256(kernel.packet[6]);
1078 __m256i h = _mm256_castph_si256(kernel.packet[7]);
1079 __m256i i = _mm256_castph_si256(kernel.packet[8]);
1080 __m256i j = _mm256_castph_si256(kernel.packet[9]);
1081 __m256i k = _mm256_castph_si256(kernel.packet[10]);
1082 __m256i l = _mm256_castph_si256(kernel.packet[11]);
1083 __m256i m = _mm256_castph_si256(kernel.packet[12]);
1084 __m256i n = _mm256_castph_si256(kernel.packet[13]);
1085 __m256i o = _mm256_castph_si256(kernel.packet[14]);
1086 __m256i p = _mm256_castph_si256(kernel.packet[15]);
1088 __m256i ab_07 = _mm256_unpacklo_epi16(a, b);
1089 __m256i cd_07 = _mm256_unpacklo_epi16(c, d);
1090 __m256i ef_07 = _mm256_unpacklo_epi16(e, f);
1091 __m256i gh_07 = _mm256_unpacklo_epi16(g, h);
1092 __m256i ij_07 = _mm256_unpacklo_epi16(i, j);
1093 __m256i kl_07 = _mm256_unpacklo_epi16(k, l);
1094 __m256i mn_07 = _mm256_unpacklo_epi16(m, n);
1095 __m256i op_07 = _mm256_unpacklo_epi16(o, p);
1097 __m256i ab_8f = _mm256_unpackhi_epi16(a, b);
1098 __m256i cd_8f = _mm256_unpackhi_epi16(c, d);
1099 __m256i ef_8f = _mm256_unpackhi_epi16(e, f);
1100 __m256i gh_8f = _mm256_unpackhi_epi16(g, h);
1101 __m256i ij_8f = _mm256_unpackhi_epi16(i, j);
1102 __m256i kl_8f = _mm256_unpackhi_epi16(k, l);
1103 __m256i mn_8f = _mm256_unpackhi_epi16(m, n);
1104 __m256i op_8f = _mm256_unpackhi_epi16(o, p);
1106 __m256i abcd_03 = _mm256_unpacklo_epi32(ab_07, cd_07);
1107 __m256i abcd_47 = _mm256_unpackhi_epi32(ab_07, cd_07);
1108 __m256i efgh_03 = _mm256_unpacklo_epi32(ef_07, gh_07);
1109 __m256i efgh_47 = _mm256_unpackhi_epi32(ef_07, gh_07);
1110 __m256i ijkl_03 = _mm256_unpacklo_epi32(ij_07, kl_07);
1111 __m256i ijkl_47 = _mm256_unpackhi_epi32(ij_07, kl_07);
1112 __m256i mnop_03 = _mm256_unpacklo_epi32(mn_07, op_07);
1113 __m256i mnop_47 = _mm256_unpackhi_epi32(mn_07, op_07);
1115 __m256i abcd_8b = _mm256_unpacklo_epi32(ab_8f, cd_8f);
1116 __m256i abcd_cf = _mm256_unpackhi_epi32(ab_8f, cd_8f);
1117 __m256i efgh_8b = _mm256_unpacklo_epi32(ef_8f, gh_8f);
1118 __m256i efgh_cf = _mm256_unpackhi_epi32(ef_8f, gh_8f);
1119 __m256i ijkl_8b = _mm256_unpacklo_epi32(ij_8f, kl_8f);
1120 __m256i ijkl_cf = _mm256_unpackhi_epi32(ij_8f, kl_8f);
1121 __m256i mnop_8b = _mm256_unpacklo_epi32(mn_8f, op_8f);
1122 __m256i mnop_cf = _mm256_unpackhi_epi32(mn_8f, op_8f);
1124 __m256i abcdefgh_01 = _mm256_unpacklo_epi64(abcd_03, efgh_03);
1125 __m256i abcdefgh_23 = _mm256_unpackhi_epi64(abcd_03, efgh_03);
1126 __m256i ijklmnop_01 = _mm256_unpacklo_epi64(ijkl_03, mnop_03);
1127 __m256i ijklmnop_23 = _mm256_unpackhi_epi64(ijkl_03, mnop_03);
1128 __m256i abcdefgh_45 = _mm256_unpacklo_epi64(abcd_47, efgh_47);
1129 __m256i abcdefgh_67 = _mm256_unpackhi_epi64(abcd_47, efgh_47);
1130 __m256i ijklmnop_45 = _mm256_unpacklo_epi64(ijkl_47, mnop_47);
1131 __m256i ijklmnop_67 = _mm256_unpackhi_epi64(ijkl_47, mnop_47);
1132 __m256i abcdefgh_89 = _mm256_unpacklo_epi64(abcd_8b, efgh_8b);
1133 __m256i abcdefgh_ab = _mm256_unpackhi_epi64(abcd_8b, efgh_8b);
1134 __m256i ijklmnop_89 = _mm256_unpacklo_epi64(ijkl_8b, mnop_8b);
1135 __m256i ijklmnop_ab = _mm256_unpackhi_epi64(ijkl_8b, mnop_8b);
1136 __m256i abcdefgh_cd = _mm256_unpacklo_epi64(abcd_cf, efgh_cf);
1137 __m256i abcdefgh_ef = _mm256_unpackhi_epi64(abcd_cf, efgh_cf);
1138 __m256i ijklmnop_cd = _mm256_unpacklo_epi64(ijkl_cf, mnop_cf);
1139 __m256i ijklmnop_ef = _mm256_unpackhi_epi64(ijkl_cf, mnop_cf);
1142 __m256i a_p_0 = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x20);
1143 __m256i a_p_1 = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x20);
1144 __m256i a_p_2 = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x20);
1145 __m256i a_p_3 = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x20);
1146 __m256i a_p_4 = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x20);
1147 __m256i a_p_5 = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x20);
1148 __m256i a_p_6 = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x20);
1149 __m256i a_p_7 = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x20);
1150 __m256i a_p_8 = _mm256_permute2x128_si256(abcdefgh_01, ijklmnop_01, 0x31);
1151 __m256i a_p_9 = _mm256_permute2x128_si256(abcdefgh_23, ijklmnop_23, 0x31);
1152 __m256i a_p_a = _mm256_permute2x128_si256(abcdefgh_45, ijklmnop_45, 0x31);
1153 __m256i a_p_b = _mm256_permute2x128_si256(abcdefgh_67, ijklmnop_67, 0x31);
1154 __m256i a_p_c = _mm256_permute2x128_si256(abcdefgh_89, ijklmnop_89, 0x31);
1155 __m256i a_p_d = _mm256_permute2x128_si256(abcdefgh_ab, ijklmnop_ab, 0x31);
1156 __m256i a_p_e = _mm256_permute2x128_si256(abcdefgh_cd, ijklmnop_cd, 0x31);
1157 __m256i a_p_f = _mm256_permute2x128_si256(abcdefgh_ef, ijklmnop_ef, 0x31);
1159 kernel.packet[0] = _mm256_castsi256_ph(a_p_0);
1160 kernel.packet[1] = _mm256_castsi256_ph(a_p_1);
1161 kernel.packet[2] = _mm256_castsi256_ph(a_p_2);
1162 kernel.packet[3] = _mm256_castsi256_ph(a_p_3);
1163 kernel.packet[4] = _mm256_castsi256_ph(a_p_4);
1164 kernel.packet[5] = _mm256_castsi256_ph(a_p_5);
1165 kernel.packet[6] = _mm256_castsi256_ph(a_p_6);
1166 kernel.packet[7] = _mm256_castsi256_ph(a_p_7);
1167 kernel.packet[8] = _mm256_castsi256_ph(a_p_8);
1168 kernel.packet[9] = _mm256_castsi256_ph(a_p_9);
1169 kernel.packet[10] = _mm256_castsi256_ph(a_p_a);
1170 kernel.packet[11] = _mm256_castsi256_ph(a_p_b);
1171 kernel.packet[12] = _mm256_castsi256_ph(a_p_c);
1172 kernel.packet[13] = _mm256_castsi256_ph(a_p_d);
1173 kernel.packet[14] = _mm256_castsi256_ph(a_p_e);
1174 kernel.packet[15] = _mm256_castsi256_ph(a_p_f);
1177EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet16h, 8>& kernel) {
1178 EIGEN_ALIGN64 half in[8][16];
1179 pstore<half>(in[0], kernel.packet[0]);
1180 pstore<half>(in[1], kernel.packet[1]);
1181 pstore<half>(in[2], kernel.packet[2]);
1182 pstore<half>(in[3], kernel.packet[3]);
1183 pstore<half>(in[4], kernel.packet[4]);
1184 pstore<half>(in[5], kernel.packet[5]);
1185 pstore<half>(in[6], kernel.packet[6]);
1186 pstore<half>(in[7], kernel.packet[7]);
1188 EIGEN_ALIGN64 half out[8][16];
1190 for (
int i = 0; i < 8; ++i) {
1191 for (
int j = 0; j < 8; ++j) {
1192 out[i][j] = in[j][2 * i];
1194 for (
int j = 0; j < 8; ++j) {
1195 out[i][j + 8] = in[j][2 * i + 1];
1199 kernel.packet[0] = pload<Packet16h>(out[0]);
1200 kernel.packet[1] = pload<Packet16h>(out[1]);
1201 kernel.packet[2] = pload<Packet16h>(out[2]);
1202 kernel.packet[3] = pload<Packet16h>(out[3]);
1203 kernel.packet[4] = pload<Packet16h>(out[4]);
1204 kernel.packet[5] = pload<Packet16h>(out[5]);
1205 kernel.packet[6] = pload<Packet16h>(out[6]);
1206 kernel.packet[7] = pload<Packet16h>(out[7]);
1209EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet16h, 4>& kernel) {
1210 EIGEN_ALIGN64 half in[4][16];
1211 pstore<half>(in[0], kernel.packet[0]);
1212 pstore<half>(in[1], kernel.packet[1]);
1213 pstore<half>(in[2], kernel.packet[2]);
1214 pstore<half>(in[3], kernel.packet[3]);
1216 EIGEN_ALIGN64 half out[4][16];
1218 for (
int i = 0; i < 4; ++i) {
1219 for (
int j = 0; j < 4; ++j) {
1220 out[i][j] = in[j][4 * i];
1222 for (
int j = 0; j < 4; ++j) {
1223 out[i][j + 4] = in[j][4 * i + 1];
1225 for (
int j = 0; j < 4; ++j) {
1226 out[i][j + 8] = in[j][4 * i + 2];
1228 for (
int j = 0; j < 4; ++j) {
1229 out[i][j + 12] = in[j][4 * i + 3];
1233 kernel.packet[0] = pload<Packet16h>(out[0]);
1234 kernel.packet[1] = pload<Packet16h>(out[1]);
1235 kernel.packet[2] = pload<Packet16h>(out[2]);
1236 kernel.packet[3] = pload<Packet16h>(out[3]);
1239EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet8h, 8>& kernel) {
1240 __m128i a = _mm_castph_si128(kernel.packet[0]);
1241 __m128i b = _mm_castph_si128(kernel.packet[1]);
1242 __m128i c = _mm_castph_si128(kernel.packet[2]);
1243 __m128i d = _mm_castph_si128(kernel.packet[3]);
1244 __m128i e = _mm_castph_si128(kernel.packet[4]);
1245 __m128i f = _mm_castph_si128(kernel.packet[5]);
1246 __m128i g = _mm_castph_si128(kernel.packet[6]);
1247 __m128i h = _mm_castph_si128(kernel.packet[7]);
1249 __m128i a03b03 = _mm_unpacklo_epi16(a, b);
1250 __m128i c03d03 = _mm_unpacklo_epi16(c, d);
1251 __m128i e03f03 = _mm_unpacklo_epi16(e, f);
1252 __m128i g03h03 = _mm_unpacklo_epi16(g, h);
1253 __m128i a47b47 = _mm_unpackhi_epi16(a, b);
1254 __m128i c47d47 = _mm_unpackhi_epi16(c, d);
1255 __m128i e47f47 = _mm_unpackhi_epi16(e, f);
1256 __m128i g47h47 = _mm_unpackhi_epi16(g, h);
1258 __m128i a01b01c01d01 = _mm_unpacklo_epi32(a03b03, c03d03);
1259 __m128i a23b23c23d23 = _mm_unpackhi_epi32(a03b03, c03d03);
1260 __m128i e01f01g01h01 = _mm_unpacklo_epi32(e03f03, g03h03);
1261 __m128i e23f23g23h23 = _mm_unpackhi_epi32(e03f03, g03h03);
1262 __m128i a45b45c45d45 = _mm_unpacklo_epi32(a47b47, c47d47);
1263 __m128i a67b67c67d67 = _mm_unpackhi_epi32(a47b47, c47d47);
1264 __m128i e45f45g45h45 = _mm_unpacklo_epi32(e47f47, g47h47);
1265 __m128i e67f67g67h67 = _mm_unpackhi_epi32(e47f47, g47h47);
1267 __m128i a0b0c0d0e0f0g0h0 = _mm_unpacklo_epi64(a01b01c01d01, e01f01g01h01);
1268 __m128i a1b1c1d1e1f1g1h1 = _mm_unpackhi_epi64(a01b01c01d01, e01f01g01h01);
1269 __m128i a2b2c2d2e2f2g2h2 = _mm_unpacklo_epi64(a23b23c23d23, e23f23g23h23);
1270 __m128i a3b3c3d3e3f3g3h3 = _mm_unpackhi_epi64(a23b23c23d23, e23f23g23h23);
1271 __m128i a4b4c4d4e4f4g4h4 = _mm_unpacklo_epi64(a45b45c45d45, e45f45g45h45);
1272 __m128i a5b5c5d5e5f5g5h5 = _mm_unpackhi_epi64(a45b45c45d45, e45f45g45h45);
1273 __m128i a6b6c6d6e6f6g6h6 = _mm_unpacklo_epi64(a67b67c67d67, e67f67g67h67);
1274 __m128i a7b7c7d7e7f7g7h7 = _mm_unpackhi_epi64(a67b67c67d67, e67f67g67h67);
1276 kernel.packet[0] = _mm_castsi128_ph(a0b0c0d0e0f0g0h0);
1277 kernel.packet[1] = _mm_castsi128_ph(a1b1c1d1e1f1g1h1);
1278 kernel.packet[2] = _mm_castsi128_ph(a2b2c2d2e2f2g2h2);
1279 kernel.packet[3] = _mm_castsi128_ph(a3b3c3d3e3f3g3h3);
1280 kernel.packet[4] = _mm_castsi128_ph(a4b4c4d4e4f4g4h4);
1281 kernel.packet[5] = _mm_castsi128_ph(a5b5c5d5e5f5g5h5);
1282 kernel.packet[6] = _mm_castsi128_ph(a6b6c6d6e6f6g6h6);
1283 kernel.packet[7] = _mm_castsi128_ph(a7b7c7d7e7f7g7h7);
1286EIGEN_STRONG_INLINE
void ptranspose(PacketBlock<Packet8h, 4>& kernel) {
1287 EIGEN_ALIGN32 Eigen::half in[4][8];
1288 pstore<Eigen::half>(in[0], kernel.packet[0]);
1289 pstore<Eigen::half>(in[1], kernel.packet[1]);
1290 pstore<Eigen::half>(in[2], kernel.packet[2]);
1291 pstore<Eigen::half>(in[3], kernel.packet[3]);
1293 EIGEN_ALIGN32 Eigen::half out[4][8];
1295 for (
int i = 0; i < 4; ++i) {
1296 for (
int j = 0; j < 4; ++j) {
1297 out[i][j] = in[j][2 * i];
1299 for (
int j = 0; j < 4; ++j) {
1300 out[i][j + 4] = in[j][2 * i + 1];
1304 kernel.packet[0] = pload<Packet8h>(out[0]);
1305 kernel.packet[1] = pload<Packet8h>(out[1]);
1306 kernel.packet[2] = pload<Packet8h>(out[2]);
1307 kernel.packet[3] = pload<Packet8h>(out[3]);
1313EIGEN_STRONG_INLINE Packet32h preverse(
const Packet32h& a) {
1314 return _mm512_permutexvar_ph(_mm512_set_epi16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1315 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31),
1320EIGEN_STRONG_INLINE Packet16h preverse(
const Packet16h& a) {
1321 __m128i m = _mm_setr_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1);
1322 return _mm256_castsi256_ph(_mm256_insertf128_si256(
1323 _mm256_castsi128_si256(_mm_shuffle_epi8(_mm256_extractf128_si256(_mm256_castph_si256(a), 1), m)),
1324 _mm_shuffle_epi8(_mm256_extractf128_si256(_mm256_castph_si256(a), 0), m), 1));
1328EIGEN_STRONG_INLINE Packet8h preverse(
const Packet8h& a) {
1329 __m128i m = _mm_setr_epi8(14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1);
1330 return _mm_castsi128_ph(_mm_shuffle_epi8(_mm_castph_si128(a), m));
1336EIGEN_STRONG_INLINE
void pscatter<half, Packet32h>(half* to,
const Packet32h& from,
Index stride) {
1337 EIGEN_ALIGN64 half aux[32];
1341 for (
int i = 0; i < 32; i++) {
1342 to[stride * i] = aux[i];
1346EIGEN_STRONG_INLINE
void pscatter<half, Packet16h>(half* to,
const Packet16h& from,
Index stride) {
1347 EIGEN_ALIGN64 half aux[16];
1349 to[stride * 0] = aux[0];
1350 to[stride * 1] = aux[1];
1351 to[stride * 2] = aux[2];
1352 to[stride * 3] = aux[3];
1353 to[stride * 4] = aux[4];
1354 to[stride * 5] = aux[5];
1355 to[stride * 6] = aux[6];
1356 to[stride * 7] = aux[7];
1357 to[stride * 8] = aux[8];
1358 to[stride * 9] = aux[9];
1359 to[stride * 10] = aux[10];
1360 to[stride * 11] = aux[11];
1361 to[stride * 12] = aux[12];
1362 to[stride * 13] = aux[13];
1363 to[stride * 14] = aux[14];
1364 to[stride * 15] = aux[15];
1368EIGEN_STRONG_INLINE
void pscatter<Eigen::half, Packet8h>(Eigen::half* to,
const Packet8h& from,
Index stride) {
1369 EIGEN_ALIGN32 Eigen::half aux[8];
1371 to[stride * 0] = aux[0];
1372 to[stride * 1] = aux[1];
1373 to[stride * 2] = aux[2];
1374 to[stride * 3] = aux[3];
1375 to[stride * 4] = aux[4];
1376 to[stride * 5] = aux[5];
1377 to[stride * 6] = aux[6];
1378 to[stride * 7] = aux[7];
1384EIGEN_STRONG_INLINE Packet32h pgather<Eigen::half, Packet32h>(
const Eigen::half* from,
Index stride) {
1385 return _mm512_set_ph(from[31 * stride].x, from[30 * stride].x, from[29 * stride].x, from[28 * stride].x,
1386 from[27 * stride].x, from[26 * stride].x, from[25 * stride].x, from[24 * stride].x,
1387 from[23 * stride].x, from[22 * stride].x, from[21 * stride].x, from[20 * stride].x,
1388 from[19 * stride].x, from[18 * stride].x, from[17 * stride].x, from[16 * stride].x,
1389 from[15 * stride].x, from[14 * stride].x, from[13 * stride].x, from[12 * stride].x,
1390 from[11 * stride].x, from[10 * stride].x, from[9 * stride].x, from[8 * stride].x,
1391 from[7 * stride].x, from[6 * stride].x, from[5 * stride].x, from[4 * stride].x,
1392 from[3 * stride].x, from[2 * stride].x, from[1 * stride].x, from[0 * stride].x);
1396EIGEN_STRONG_INLINE Packet16h pgather<Eigen::half, Packet16h>(
const Eigen::half* from,
Index stride) {
1397 return _mm256_set_ph(from[15 * stride].x, from[14 * stride].x, from[13 * stride].x, from[12 * stride].x,
1398 from[11 * stride].x, from[10 * stride].x, from[9 * stride].x, from[8 * stride].x,
1399 from[7 * stride].x, from[6 * stride].x, from[5 * stride].x, from[4 * stride].x,
1400 from[3 * stride].x, from[2 * stride].x, from[1 * stride].x, from[0 * stride].x);
1404EIGEN_STRONG_INLINE Packet8h pgather<Eigen::half, Packet8h>(
const Eigen::half* from,
Index stride) {
1405 return _mm_set_ph(from[7 * stride].x, from[6 * stride].x, from[5 * stride].x, from[4 * stride].x, from[3 * stride].x,
1406 from[2 * stride].x, from[1 * stride].x, from[0 * stride].x);
@ Aligned64
Definition Constants.h:239
@ Aligned32
Definition Constants.h:238
@ Aligned16
Definition Constants.h:237
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82