blob: 39f0c3bf776a9d12a8309cde315e72b41fd2939a [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_NEMATH_H__
25#define __ARM_COMPUTE_NEMATH_H__
26
27#include <arm_neon.h>
28
29namespace arm_compute
30{
31/** Calculate inverse square root.
32 *
33 * @param[in] x Input value.
34 *
35 * @return The calculated inverse square root.
36 */
37float32x4_t vinvsqrtq_f32(float32x4_t x);
38
Pablo Tello8fda1cb2017-07-05 15:20:38 +010039#ifdef ARM_COMPUTE_ENABLE_FP16
40/** Calculate inverse square root.
41 *
42 * @param[in] x Input value.
43 *
44 * @return The calculated inverse square root.
45 */
46float16x8_t vinvsqrtq_f16(float16x8_t x);
47#endif /* ARM_COMPUTE_ENABLE_FP16 */
48
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049/** Calculate reciprocal.
50 *
51 * @param[in] x Input value.
52 *
53 * @return The calculated reciprocal.
54 */
55float32x4_t vinvq_f32(float32x4_t x);
56
57/** Perform a 7th degree polynomial approximation using Estrin's method.
58 *
59 * @param[in] x Input vector value in F32 format.
60 * @param[in] coeffs Polynomial coefficients table.
61 *
62 * @return The calculated approximation.
63 */
64float32x4_t vtaylor_polyq_f32(float32x4_t x, const std::array<float32x4_t, 8> &coeffs);
65
66/** Calculate exponential
67 *
68 * @param[in] x Input vector value in F32 format.
69 *
70 * @return The calculated exponent.
71 */
72float32x4_t vexpq_f32(float32x4_t x);
73
74/** Calculate logarithm
75 *
76 * @param[in] x Input vector value in F32 format.
77 *
78 * @return The calculated logarithm.
79 */
80float32x4_t vlogq_f32(float32x4_t x);
81
82/** Calculate hyperbolic tangent.
83 *
84 * tanh(x) = (e^2x - 1)/(e^2x + 1)
85 *
86 * @note We clamp x to [-5,5] to avoid overflowing issues.
87 *
88 * @param[in] val Input vector value in F32 format.
89 *
90 * @return The calculated Hyperbolic Tangent.
91 */
92float32x4_t vtanhq_f32(float32x4_t val);
93
94/** Calculate n power of a number.
95 *
96 * pow(x,n) = e^(n*log(x))
97 *
98 * @param[in] val Input vector value in F32 format.
99 * @param[in] n Powers to raise the input to.
100 *
101 * @return The calculated power.
102 */
103float32x4_t vpowq_f32(float32x4_t val, float32x4_t n);
Pablo Tellodf246182017-07-03 16:25:09 +0100104
105#ifdef ARM_COMPUTE_ENABLE_FP16
Pablo Tello91654c42017-07-05 11:32:17 +0100106/** Calculate hyperbolic tangent.
107 *
108 * tanh(x) = (e^2x - 1)/(e^2x + 1)
109 *
110 * @note We clamp x to [-5,5] to avoid overflowing issues.
111 *
112 * @param[in] val Input vector value in F32 format.
113 *
114 * @return The calculated Hyperbolic Tangent.
115 */
116float16x8_t vtanhq_f16(float16x8_t val);
117/** Calculate inverse square root.
118 *
119 * @param[in] x Input value.
120 *
121 * @return The calculated inverse square root.
122 */
123float16x8_t vinvsqrtq_f16(float16x8_t x);
Pablo Tellodf246182017-07-03 16:25:09 +0100124/** Calculate exponential
125 *
126 * @param[in] x Input vector value in F16 format.
127 *
128 * @return The calculated exponent.
129 */
130float16x8_t vexpq_f16(float16x8_t x);
131/** Calculate n power of a number.
132 *
133 * pow(x,n) = e^(n*log(x))
134 *
135 * @param[in] val Input vector value in F16 format.
136 * @param[in] n Powers to raise the input to.
137 *
138 * @return The calculated power.
139 */
140float16x8_t vpowq_f16(float16x8_t val, float16x8_t n);
141#endif /* ARM_COMPUTE_ENABLE_FP16 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142}
143#include "arm_compute/core/NEON/NEMath.inl"
144#endif /* __ARM_COMPUTE_NEMATH_H__ */