Eigen  5.0.1
 
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) 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// SPDX-License-Identifier: MPL-2.0
12
13#ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H
14#define EIGEN_MATH_FUNCTIONS_ALTIVEC_H
15
16// IWYU pragma: private
17#include "../../InternalHeaderCheck.h"
18
19namespace Eigen {
20
21namespace internal {
22
23EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet4f)
24#ifdef EIGEN_VECTORIZE_VSX
25EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(Packet2d)
26#endif
27
28#ifdef EIGEN_VECTORIZE_VSX
29template <>
30EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4f psqrt<Packet4f>(const Packet4f& x) {
31 return vec_sqrt(x);
32}
33
34template <>
35EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet2d psqrt<Packet2d>(const Packet2d& x) {
36 return vec_sqrt(x);
37}
38
39#if !EIGEN_COMP_CLANG
40template <>
41EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4f prsqrt<Packet4f>(const Packet4f& x) {
42 return pset1<Packet4f>(1.0f) / psqrt<Packet4f>(x);
43 // vec_rsqrt returns different results from the generic version
44 // return vec_rsqrt(x);
45}
46
47template <>
48EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet2d prsqrt<Packet2d>(const Packet2d& x) {
49 return pset1<Packet2d>(1.0) / psqrt<Packet2d>(x);
50 // vec_rsqrt returns different results from the generic version
51 // return vec_rsqrt(x);
52}
53
54#endif
55
56template <>
57EIGEN_STRONG_INLINE Packet8bf psqrt<Packet8bf>(const Packet8bf& a) {
58 BF16_TO_F32_UNARY_OP_WRAPPER(psqrt<Packet4f>, a);
59}
60
61#if !EIGEN_COMP_CLANG
62template <>
63EIGEN_STRONG_INLINE Packet8bf prsqrt<Packet8bf>(const Packet8bf& a) {
64 BF16_TO_F32_UNARY_OP_WRAPPER(prsqrt<Packet4f>, a);
65}
66#endif
67#else
68template <>
69EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS Packet4f psqrt<Packet4f>(const Packet4f& x) {
70 Packet4f a;
71 for (Index i = 0; i < packet_traits<float>::size; i++) {
72 a[i] = numext::sqrt(x[i]);
73 }
74 return a;
75}
76#endif
77
78} // end namespace internal
79
80} // end namespace Eigen
81
82#endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H