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// This Source Code Form is subject to the terms of the Mozilla
5// Public License v. 2.0. If a copy of the MPL was not distributed
6// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
7// SPDX-FileCopyrightText: The Eigen Authors
8// SPDX-License-Identifier: MPL-2.0
9
10#ifndef EIGEN_MATH_FUNCTIONS_NEON_H
11#define EIGEN_MATH_FUNCTIONS_NEON_H
12
13// IWYU pragma: private
14#include "../../InternalHeaderCheck.h"
15
16namespace Eigen {
17
18namespace internal {
19
20EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet2f)
21EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_FLOAT(Packet4f)
22
23#if EIGEN_ARCH_ARM64 && EIGEN_HAS_ARM64_FP16
24template <>
25EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet4hf ptanh<Packet4hf>(const Packet4hf& x) {
26 // Convert to float, call the float ptanh, and then convert back.
27 return vcvt_f16_f32(ptanh<Packet4f>(vcvt_f32_f16(x)));
28}
29
30template <>
31EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Packet8hf ptanh<Packet8hf>(const Packet8hf& x) {
32 // Convert each 4 half types to float, call the float ptanh, and then convert back.
33 return vcombine_f16(vcvt_f16_f32(ptanh<Packet4f>(vcvt_f32_f16(vget_low_f16(x)))),
34 vcvt_f16_f32(ptanh<Packet4f>(vcvt_f32_f16(vget_high_f16(x)))));
35}
36#endif // EIGEN_ARCH_ARM64 && EIGEN_HAS_ARM64_FP16
37
38EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_BF16(Packet4f, Packet4bf)
39
40template <>
41EIGEN_STRONG_INLINE Packet4bf pfrexp(const Packet4bf& a, Packet4bf& exponent) {
42 // Both results are exact: the mantissa keeps the input's significand, and the exponent is a
43 // small integer.
44 Packet4f fexponent;
45 const Packet4bf out = F32ToBf16Truncate(pfrexp<Packet4f>(Bf16ToF32(a), fexponent));
46 exponent = F32ToBf16Truncate(fexponent);
47 return out;
48}
49
50template <>
51EIGEN_STRONG_INLINE Packet4bf pldexp(const Packet4bf& a, const Packet4bf& exponent) {
52 return F32ToBf16(pldexp<Packet4f>(Bf16ToF32(a), Bf16ToF32(exponent)));
53}
54
55//---------- double ----------
56
57#if EIGEN_ARCH_ARM64
58
59EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_DOUBLE(Packet2d)
60
61#endif
62
63} // end namespace internal
64
65} // end namespace Eigen
66
67#endif // EIGEN_MATH_FUNCTIONS_NEON_H