11#ifndef EIGEN_MATH_FUNCTIONS_FP16_AVX512_H
12#define EIGEN_MATH_FUNCTIONS_FP16_AVX512_H
15#include "../../InternalHeaderCheck.h"
20EIGEN_STRONG_INLINE Packet32h combine2Packet16h(
const Packet16h& a,
const Packet16h& b) {
21 __m512i result = _mm512_castsi256_si512(_mm256_castph_si256(a));
22 result = _mm512_inserti64x4(result, _mm256_castph_si256(b), 1);
23 return _mm512_castsi512_ph(result);
26EIGEN_STRONG_INLINE
void extract2Packet16h(
const Packet32h& x, Packet16h& a, Packet16h& b) {
27 a = _mm256_castsi256_ph(_mm512_castsi512_si256(_mm512_castph_si512(x)));
28 b = _mm256_castsi256_ph(_mm512_extracti64x4_epi64(_mm512_castph_si512(x), 1));
31#define _EIGEN_GENERATE_FP16_MATH_FUNCTION(func) \
33 EIGEN_STRONG_INLINE Packet8h func<Packet8h>(const Packet8h& a) { \
34 return float2half(func(half2float(a))); \
38 EIGEN_STRONG_INLINE Packet16h func<Packet16h>(const Packet16h& a) { \
39 return float2half(func(half2float(a))); \
43 EIGEN_STRONG_INLINE Packet32h func<Packet32h>(const Packet32h& a) { \
46 extract2Packet16h(a, low, high); \
47 return combine2Packet16h(func(low), func(high)); \
50_EIGEN_GENERATE_FP16_MATH_FUNCTION(psin)
51_EIGEN_GENERATE_FP16_MATH_FUNCTION(pcos)
52_EIGEN_GENERATE_FP16_MATH_FUNCTION(plog)
53_EIGEN_GENERATE_FP16_MATH_FUNCTION(plog2)
54_EIGEN_GENERATE_FP16_MATH_FUNCTION(plog1p)
55_EIGEN_GENERATE_FP16_MATH_FUNCTION(pexp)
56_EIGEN_GENERATE_FP16_MATH_FUNCTION(pexpm1)
57_EIGEN_GENERATE_FP16_MATH_FUNCTION(pexp2)
58_EIGEN_GENERATE_FP16_MATH_FUNCTION(ptanh)
59#undef _EIGEN_GENERATE_FP16_MATH_FUNCTION
63EIGEN_STRONG_INLINE Packet32h pfrexp<Packet32h>(
const Packet32h& a, Packet32h& exponent) {
64 return pfrexp_generic(a, exponent);
69EIGEN_STRONG_INLINE Packet32h pldexp<Packet32h>(
const Packet32h& a,
const Packet32h& exponent) {
71 const Packet32h max_exponent = pset1<Packet32h>(Eigen::half(41.0f));
72 const Packet32h e = pmin(pmax(exponent, pnegate(max_exponent)), max_exponent);
73 return _mm512_scalef_ph(a, _mm512_roundscale_ph(e, _MM_FROUND_TO_ZERO | _MM_FROUND_NO_EXC));