$darkmode
Eigen  5.0.1-dev
MathFunctions.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com)
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 THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
11 #define THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
12 
13 // IWYU pragma: private
14 #include "../../InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet16f)
20 EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(Packet8d)
21 
22 template <>
23 EIGEN_STRONG_INLINE Packet16h pfrexp(const Packet16h& a, Packet16h& exponent) {
24  Packet16f fexponent;
25  const Packet16h out = float2half(pfrexp<Packet16f>(half2float(a), fexponent));
26  exponent = float2half(fexponent);
27  return out;
28 }
29 
30 template <>
31 EIGEN_STRONG_INLINE Packet16h pldexp(const Packet16h& a, const Packet16h& exponent) {
32  return float2half(pldexp<Packet16f>(half2float(a), half2float(exponent)));
33 }
34 
35 template <>
36 EIGEN_STRONG_INLINE Packet16bf pfrexp(const Packet16bf& a, Packet16bf& exponent) {
37  Packet16f fexponent;
38  const Packet16bf out = F32ToBf16(pfrexp<Packet16f>(Bf16ToF32(a), fexponent));
39  exponent = F32ToBf16(fexponent);
40  return out;
41 }
42 
43 template <>
44 EIGEN_STRONG_INLINE Packet16bf pldexp(const Packet16bf& a, const Packet16bf& exponent) {
45  return F32ToBf16(pldexp<Packet16f>(Bf16ToF32(a), Bf16ToF32(exponent)));
46 }
47 
48 #if EIGEN_FAST_MATH
49 template <>
50 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet16f psqrt<Packet16f>(const Packet16f& x) {
51  return generic_sqrt_newton_step<Packet16f>::run(x, _mm512_rsqrt14_ps(x));
52 }
53 
54 template <>
55 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet8d psqrt<Packet8d>(const Packet8d& x) {
56 #ifdef EIGEN_VECTORIZE_AVX512ER
57  return generic_sqrt_newton_step<Packet8d, /*Steps=*/1>::run(x, _mm512_rsqrt28_pd(x));
58 #else
59  return generic_sqrt_newton_step<Packet8d, /*Steps=*/2>::run(x, _mm512_rsqrt14_pd(x));
60 #endif
61 }
62 #else
63 template <>
64 EIGEN_STRONG_INLINE Packet16f psqrt<Packet16f>(const Packet16f& x) {
65  return _mm512_sqrt_ps(x);
66 }
67 
68 template <>
69 EIGEN_STRONG_INLINE Packet8d psqrt<Packet8d>(const Packet8d& x) {
70  return _mm512_sqrt_pd(x);
71 }
72 #endif
73 
74 // prsqrt for float.
75 #if defined(EIGEN_VECTORIZE_AVX512ER)
76 template <>
77 EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) {
78  return _mm512_rsqrt28_ps(x);
79 }
80 #elif EIGEN_FAST_MATH
81 
82 template <>
83 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet16f prsqrt<Packet16f>(const Packet16f& x) {
84  return generic_rsqrt_newton_step<Packet16f, /*Steps=*/1>::run(x, _mm512_rsqrt14_ps(x));
85 }
86 #endif
87 
88 // prsqrt for double.
89 #if EIGEN_FAST_MATH
90 template <>
91 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet8d prsqrt<Packet8d>(const Packet8d& x) {
92 #ifdef EIGEN_VECTORIZE_AVX512ER
93  return generic_rsqrt_newton_step<Packet8d, /*Steps=*/1>::run(x, _mm512_rsqrt28_pd(x));
94 #else
95  return generic_rsqrt_newton_step<Packet8d, /*Steps=*/2>::run(x, _mm512_rsqrt14_pd(x));
96 #endif
97 }
98 
99 template <>
100 EIGEN_STRONG_INLINE Packet16f preciprocal<Packet16f>(const Packet16f& a) {
101 #ifdef EIGEN_VECTORIZE_AVX512ER
102  return _mm512_rcp28_ps(a);
103 #else
104  return generic_reciprocal_newton_step<Packet16f, /*Steps=*/1>::run(a, _mm512_rcp14_ps(a));
105 #endif
106 }
107 #endif
108 
109 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pcos)
110 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexp)
111 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexp2)
112 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexpm1)
113 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog)
114 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog1p)
115 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog2)
116 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, preciprocal)
117 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, prsqrt)
118 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, psin)
119 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, psqrt)
120 BF16_PACKET_FUNCTION(Packet16f, Packet16bf, ptanh)
121 
122 #ifndef EIGEN_VECTORIZE_AVX512FP16
123 F16_PACKET_FUNCTION(Packet16f, Packet16h, pcos)
124 F16_PACKET_FUNCTION(Packet16f, Packet16h, pexp)
125 F16_PACKET_FUNCTION(Packet16f, Packet16h, pexp2)
126 F16_PACKET_FUNCTION(Packet16f, Packet16h, pexpm1)
127 F16_PACKET_FUNCTION(Packet16f, Packet16h, plog)
128 F16_PACKET_FUNCTION(Packet16f, Packet16h, plog1p)
129 F16_PACKET_FUNCTION(Packet16f, Packet16h, plog2)
130 F16_PACKET_FUNCTION(Packet16f, Packet16h, preciprocal)
131 F16_PACKET_FUNCTION(Packet16f, Packet16h, prsqrt)
132 F16_PACKET_FUNCTION(Packet16f, Packet16h, psin)
133 F16_PACKET_FUNCTION(Packet16f, Packet16h, psqrt)
134 F16_PACKET_FUNCTION(Packet16f, Packet16h, ptanh)
135 #endif // EIGEN_VECTORIZE_AVX512FP16
136 
137 } // end namespace internal
138 
139 } // end namespace Eigen
140 
141 #endif // THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1