Eigen  5.0.1-dev+284dcc12
 
Loading...
Searching...
No Matches
MathFunctionsFP16.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2025 The Eigen Authors.
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_MATH_FUNCTIONS_FP16_AVX512_H
11#define EIGEN_MATH_FUNCTIONS_FP16_AVX512_H
12
13// IWYU pragma: private
14#include "../../InternalHeaderCheck.h"
15
16namespace Eigen {
17namespace internal {
18
19EIGEN_STRONG_INLINE Packet32h combine2Packet16h(const Packet16h& a, const Packet16h& b) {
20 __m512i result = _mm512_castsi256_si512(_mm256_castph_si256(a));
21 result = _mm512_inserti64x4(result, _mm256_castph_si256(b), 1);
22 return _mm512_castsi512_ph(result);
23}
24
25EIGEN_STRONG_INLINE void extract2Packet16h(const Packet32h& x, Packet16h& a, Packet16h& b) {
26 a = _mm256_castsi256_ph(_mm512_castsi512_si256(_mm512_castph_si512(x)));
27 b = _mm256_castsi256_ph(_mm512_extracti64x4_epi64(_mm512_castph_si512(x), 1));
28}
29
30#define _EIGEN_GENERATE_FP16_MATH_FUNCTION(func) \
31 template <> \
32 EIGEN_STRONG_INLINE Packet8h func<Packet8h>(const Packet8h& a) { \
33 return float2half(func(half2float(a))); \
34 } \
35 \
36 template <> \
37 EIGEN_STRONG_INLINE Packet16h func<Packet16h>(const Packet16h& a) { \
38 return float2half(func(half2float(a))); \
39 } \
40 \
41 template <> \
42 EIGEN_STRONG_INLINE Packet32h func<Packet32h>(const Packet32h& a) { \
43 Packet16h low; \
44 Packet16h high; \
45 extract2Packet16h(a, low, high); \
46 return combine2Packet16h(func(low), func(high)); \
47 }
48
49_EIGEN_GENERATE_FP16_MATH_FUNCTION(psin)
50_EIGEN_GENERATE_FP16_MATH_FUNCTION(pcos)
51_EIGEN_GENERATE_FP16_MATH_FUNCTION(plog)
52_EIGEN_GENERATE_FP16_MATH_FUNCTION(plog2)
53_EIGEN_GENERATE_FP16_MATH_FUNCTION(plog1p)
54_EIGEN_GENERATE_FP16_MATH_FUNCTION(pexp)
55_EIGEN_GENERATE_FP16_MATH_FUNCTION(pexpm1)
56_EIGEN_GENERATE_FP16_MATH_FUNCTION(pexp2)
57_EIGEN_GENERATE_FP16_MATH_FUNCTION(ptanh)
58#undef _EIGEN_GENERATE_FP16_MATH_FUNCTION
59
60// pfrexp
61template <>
62EIGEN_STRONG_INLINE Packet32h pfrexp<Packet32h>(const Packet32h& a, Packet32h& exponent) {
63 return pfrexp_generic(a, exponent);
64}
65
66// pldexp
67template <>
68EIGEN_STRONG_INLINE Packet32h pldexp<Packet32h>(const Packet32h& a, const Packet32h& exponent) {
69 return pldexp_generic(a, exponent);
70}
71
72} // end namespace internal
73} // end namespace Eigen
74
75#endif // EIGEN_MATH_FUNCTIONS_FP16_AVX512_H
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1