Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
arch/AVX/MathFunctions.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2014 Pedro Gonnet ([email protected])
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_AVX_H
11#define EIGEN_MATH_FUNCTIONS_AVX_H
12
13/* The sin and cos functions of this file are loosely derived from
14 * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/
15 */
16
17// IWYU pragma: private
18#include "../../InternalHeaderCheck.h"
19
20namespace Eigen {
21
22namespace internal {
23
24EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet8f)
25
26EIGEN_DOUBLE_PACKET_FUNCTION(atan, Packet4d)
27EIGEN_DOUBLE_PACKET_FUNCTION(log, Packet4d)
28EIGEN_DOUBLE_PACKET_FUNCTION(log2, Packet4d)
29EIGEN_DOUBLE_PACKET_FUNCTION(exp, Packet4d)
30#ifdef EIGEN_VECTORIZE_AVX2
31EIGEN_DOUBLE_PACKET_FUNCTION(sin, Packet4d)
32EIGEN_DOUBLE_PACKET_FUNCTION(cos, Packet4d)
33#endif
34
35// Notice that for newer processors, it is counterproductive to use Newton
36// iteration for square root. In particular, Skylake and Zen2 processors
37// have approximately doubled throughput of the _mm_sqrt_ps instruction
38// compared to their predecessors.
39template <>
40EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet8f psqrt<Packet8f>(const Packet8f& _x) {
41 return _mm256_sqrt_ps(_x);
42}
43template <>
44EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4d psqrt<Packet4d>(const Packet4d& _x) {
45 return _mm256_sqrt_pd(_x);
46}
47
48// Even on Skylake, using Newton iteration is a win for reciprocal square root.
49#if EIGEN_FAST_MATH
50template <>
51EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet8f prsqrt<Packet8f>(const Packet8f& a) {
52 // _mm256_rsqrt_ps returns -inf for negative denormals.
53 // _mm512_rsqrt**_ps returns -NaN for negative denormals. We may want
54 // consistency here.
55 // const Packet8f rsqrt = pselect(pcmp_lt(a, pzero(a)),
56 // pset1<Packet8f>(-NumTraits<float>::quiet_NaN()),
57 // _mm256_rsqrt_ps(a));
58 return generic_rsqrt_newton_step<Packet8f, /*Steps=*/1>::run(a, _mm256_rsqrt_ps(a));
59}
60
61template <>
62EIGEN_STRONG_INLINE Packet8f preciprocal<Packet8f>(const Packet8f& a) {
63 return generic_reciprocal_newton_step<Packet8f, /*Steps=*/1>::run(a, _mm256_rcp_ps(a));
64}
65
66#endif
67
68template <>
69EIGEN_STRONG_INLINE Packet8h pfrexp(const Packet8h& a, Packet8h& exponent) {
70 Packet8f fexponent;
71 const Packet8h out = float2half(pfrexp<Packet8f>(half2float(a), fexponent));
72 exponent = float2half(fexponent);
73 return out;
74}
75
76template <>
77EIGEN_STRONG_INLINE Packet8h pldexp(const Packet8h& a, const Packet8h& exponent) {
78 return float2half(pldexp<Packet8f>(half2float(a), half2float(exponent)));
79}
80
81template <>
82EIGEN_STRONG_INLINE Packet8bf pfrexp(const Packet8bf& a, Packet8bf& exponent) {
83 Packet8f fexponent;
84 const Packet8bf out = F32ToBf16(pfrexp<Packet8f>(Bf16ToF32(a), fexponent));
85 exponent = F32ToBf16(fexponent);
86 return out;
87}
88
89template <>
90EIGEN_STRONG_INLINE Packet8bf pldexp(const Packet8bf& a, const Packet8bf& exponent) {
91 return F32ToBf16(pldexp<Packet8f>(Bf16ToF32(a), Bf16ToF32(exponent)));
92}
93
94BF16_PACKET_FUNCTION(Packet8f, Packet8bf, pcos)
95BF16_PACKET_FUNCTION(Packet8f, Packet8bf, pexp)
96BF16_PACKET_FUNCTION(Packet8f, Packet8bf, pexpm1)
97BF16_PACKET_FUNCTION(Packet8f, Packet8bf, plog)
98BF16_PACKET_FUNCTION(Packet8f, Packet8bf, plog1p)
99BF16_PACKET_FUNCTION(Packet8f, Packet8bf, plog2)
100BF16_PACKET_FUNCTION(Packet8f, Packet8bf, preciprocal)
101BF16_PACKET_FUNCTION(Packet8f, Packet8bf, prsqrt)
102BF16_PACKET_FUNCTION(Packet8f, Packet8bf, psin)
103BF16_PACKET_FUNCTION(Packet8f, Packet8bf, psqrt)
104BF16_PACKET_FUNCTION(Packet8f, Packet8bf, ptanh)
105F16_PACKET_FUNCTION(Packet8f, Packet8h, pcos)
106F16_PACKET_FUNCTION(Packet8f, Packet8h, pexp)
107F16_PACKET_FUNCTION(Packet8f, Packet8h, pexpm1)
108F16_PACKET_FUNCTION(Packet8f, Packet8h, plog)
109F16_PACKET_FUNCTION(Packet8f, Packet8h, plog1p)
110F16_PACKET_FUNCTION(Packet8f, Packet8h, plog2)
111F16_PACKET_FUNCTION(Packet8f, Packet8h, preciprocal)
112F16_PACKET_FUNCTION(Packet8f, Packet8h, prsqrt)
113F16_PACKET_FUNCTION(Packet8f, Packet8h, psin)
114F16_PACKET_FUNCTION(Packet8f, Packet8h, psqrt)
115F16_PACKET_FUNCTION(Packet8f, Packet8h, ptanh)
116
117} // end namespace internal
118
119} // end namespace Eigen
120
121#endif // EIGEN_MATH_FUNCTIONS_AVX_H
Namespace containing all symbols from the Eigen library.
Definition Core:137
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cos_op< typename Derived::Scalar >, const Derived > cos(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_exp_op< typename Derived::Scalar >, const Derived > exp(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log2_op< typename Derived::Scalar >, const Derived > log2(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_atan_op< typename Derived::Scalar >, const Derived > atan(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log_op< typename Derived::Scalar >, const Derived > log(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sin_op< typename Derived::Scalar >, const Derived > sin(const Eigen::ArrayBase< Derived > &x)