$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) 2007 Julien Pommier
5 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
6 // Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
7 //
8 // This Source Code Form is subject to the terms of the Mozilla
9 // Public License v. 2.0. If a copy of the MPL was not distributed
10 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 
12 #ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H
13 #define EIGEN_MATH_FUNCTIONS_ALTIVEC_H
14 
15 // IWYU pragma: private
16 #include "../../InternalHeaderCheck.h"
17 
18 namespace Eigen {
19 
20 namespace internal {
21 
22 EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet4f)
23 #ifdef EIGEN_VECTORIZE_VSX
24 EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(Packet2d)
25 #endif
26 
27 #ifdef EIGEN_VECTORIZE_VSX
28 template <>
29 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4f psqrt<Packet4f>(const Packet4f& x) {
30  return vec_sqrt(x);
31 }
32 
33 template <>
34 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet2d psqrt<Packet2d>(const Packet2d& x) {
35  return vec_sqrt(x);
36 }
37 
38 #if !EIGEN_COMP_CLANG
39 template <>
40 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4f prsqrt<Packet4f>(const Packet4f& x) {
41  return pset1<Packet4f>(1.0f) / psqrt<Packet4f>(x);
42  // vec_rsqrt returns different results from the generic version
43  // return vec_rsqrt(x);
44 }
45 
46 template <>
47 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet2d prsqrt<Packet2d>(const Packet2d& x) {
48  return pset1<Packet2d>(1.0) / psqrt<Packet2d>(x);
49  // vec_rsqrt returns different results from the generic version
50  // return vec_rsqrt(x);
51 }
52 
53 #endif
54 
55 template <>
56 EIGEN_STRONG_INLINE Packet8bf psqrt<Packet8bf>(const Packet8bf& a) {
57  BF16_TO_F32_UNARY_OP_WRAPPER(psqrt<Packet4f>, a);
58 }
59 
60 #if !EIGEN_COMP_CLANG
61 template <>
62 EIGEN_STRONG_INLINE Packet8bf prsqrt<Packet8bf>(const Packet8bf& a) {
63  BF16_TO_F32_UNARY_OP_WRAPPER(prsqrt<Packet4f>, a);
64 }
65 #endif
66 #else
67 template <>
68 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4f psqrt<Packet4f>(const Packet4f& x) {
69  Packet4f a;
70  for (Index i = 0; i < packet_traits<float>::size; i++) {
71  a[i] = numext::sqrt(x[i]);
72  }
73  return a;
74 }
75 #endif
76 
77 } // end namespace internal
78 
79 } // end namespace Eigen
80 
81 #endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82