Eigen  3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
 
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Loading...
Searching...
No Matches
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
16namespace Eigen {
17
18namespace internal {
19EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet16f)
20EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(Packet8d)
21
22template <>
23EIGEN_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
30template <>
31EIGEN_STRONG_INLINE Packet16h pldexp(const Packet16h& a, const Packet16h& exponent) {
32 return float2half(pldexp<Packet16f>(half2float(a), half2float(exponent)));
33}
34
35template <>
36EIGEN_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
43template <>
44EIGEN_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
49template <>
50EIGEN_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
54template <>
55EIGEN_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
63template <>
64EIGEN_STRONG_INLINE Packet16f psqrt<Packet16f>(const Packet16f& x) {
65 return _mm512_sqrt_ps(x);
66}
67
68template <>
69EIGEN_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)
76template <>
77EIGEN_STRONG_INLINE Packet16f prsqrt<Packet16f>(const Packet16f& x) {
78 return _mm512_rsqrt28_ps(x);
79}
80#elif EIGEN_FAST_MATH
81
82template <>
83EIGEN_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
90template <>
91EIGEN_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
99template <>
100EIGEN_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
109BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pcos)
110BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexp)
111BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexp2)
112BF16_PACKET_FUNCTION(Packet16f, Packet16bf, pexpm1)
113BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog)
114BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog1p)
115BF16_PACKET_FUNCTION(Packet16f, Packet16bf, plog2)
116BF16_PACKET_FUNCTION(Packet16f, Packet16bf, preciprocal)
117BF16_PACKET_FUNCTION(Packet16f, Packet16bf, prsqrt)
118BF16_PACKET_FUNCTION(Packet16f, Packet16bf, psin)
119BF16_PACKET_FUNCTION(Packet16f, Packet16bf, psqrt)
120BF16_PACKET_FUNCTION(Packet16f, Packet16bf, ptanh)
121F16_PACKET_FUNCTION(Packet16f, Packet16h, pcos)
122F16_PACKET_FUNCTION(Packet16f, Packet16h, pexp)
123F16_PACKET_FUNCTION(Packet16f, Packet16h, pexp2)
124F16_PACKET_FUNCTION(Packet16f, Packet16h, pexpm1)
125F16_PACKET_FUNCTION(Packet16f, Packet16h, plog)
126F16_PACKET_FUNCTION(Packet16f, Packet16h, plog1p)
127F16_PACKET_FUNCTION(Packet16f, Packet16h, plog2)
128F16_PACKET_FUNCTION(Packet16f, Packet16h, preciprocal)
129F16_PACKET_FUNCTION(Packet16f, Packet16h, prsqrt)
130F16_PACKET_FUNCTION(Packet16f, Packet16h, psin)
131F16_PACKET_FUNCTION(Packet16f, Packet16h, psqrt)
132F16_PACKET_FUNCTION(Packet16f, Packet16h, ptanh)
133
134} // end namespace internal
135
136} // end namespace Eigen
137
138#endif // THIRD_PARTY_EIGEN3_EIGEN_SRC_CORE_ARCH_AVX512_MATHFUNCTIONS_H_
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1