blob: 1fc0d5c0b8c6f550c58ca77cf18be0f189f932a6 [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{
Georgios Pinitasd8e765b2017-08-02 13:44:33 +010031/** Calculate floor of a vector.
32 *
33 * @param[in] val Input vector value in F32 format.
34 *
35 * @return The calculated floor vector.
36 */
37float32x4_t vfloorq_f32(float32x4_t val);
38
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039/** Calculate inverse square root.
40 *
41 * @param[in] x Input value.
42 *
43 * @return The calculated inverse square root.
44 */
Georgios Pinitascdf51452017-08-31 14:21:36 +010045float32x2_t vinvsqrt_f32(float32x2_t x);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046
Pablo Tello8fda1cb2017-07-05 15:20:38 +010047/** Calculate inverse square root.
48 *
49 * @param[in] x Input value.
50 *
51 * @return The calculated inverse square root.
52 */
Georgios Pinitascdf51452017-08-31 14:21:36 +010053float32x4_t vinvsqrtq_f32(float32x4_t x);
54
55/** Calculate reciprocal.
56 *
57 * @param[in] x Input value.
58 *
59 * @return The calculated reciprocal.
60 */
61float32x2_t vinv_f32(float32x2_t x);
Pablo Tello8fda1cb2017-07-05 15:20:38 +010062
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063/** Calculate reciprocal.
64 *
65 * @param[in] x Input value.
66 *
67 * @return The calculated reciprocal.
68 */
69float32x4_t vinvq_f32(float32x4_t x);
70
71/** Perform a 7th degree polynomial approximation using Estrin's method.
72 *
73 * @param[in] x Input vector value in F32 format.
74 * @param[in] coeffs Polynomial coefficients table.
75 *
76 * @return The calculated approximation.
77 */
78float32x4_t vtaylor_polyq_f32(float32x4_t x, const std::array<float32x4_t, 8> &coeffs);
79
80/** Calculate exponential
81 *
82 * @param[in] x Input vector value in F32 format.
83 *
84 * @return The calculated exponent.
85 */
86float32x4_t vexpq_f32(float32x4_t x);
87
88/** Calculate logarithm
89 *
90 * @param[in] x Input vector value in F32 format.
91 *
92 * @return The calculated logarithm.
93 */
94float32x4_t vlogq_f32(float32x4_t x);
95
96/** Calculate hyperbolic tangent.
97 *
98 * tanh(x) = (e^2x - 1)/(e^2x + 1)
99 *
100 * @note We clamp x to [-5,5] to avoid overflowing issues.
101 *
102 * @param[in] val Input vector value in F32 format.
103 *
104 * @return The calculated Hyperbolic Tangent.
105 */
106float32x4_t vtanhq_f32(float32x4_t val);
107
108/** Calculate n power of a number.
109 *
110 * pow(x,n) = e^(n*log(x))
111 *
112 * @param[in] val Input vector value in F32 format.
113 * @param[in] n Powers to raise the input to.
114 *
115 * @return The calculated power.
116 */
117float32x4_t vpowq_f32(float32x4_t val, float32x4_t n);
Pablo Tellodf246182017-07-03 16:25:09 +0100118
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100119#ifdef ARM_COMPUTE_AARCH64_V8_2
Pablo Tello91654c42017-07-05 11:32:17 +0100120/** Calculate hyperbolic tangent.
121 *
122 * tanh(x) = (e^2x - 1)/(e^2x + 1)
123 *
124 * @note We clamp x to [-5,5] to avoid overflowing issues.
125 *
126 * @param[in] val Input vector value in F32 format.
127 *
128 * @return The calculated Hyperbolic Tangent.
129 */
130float16x8_t vtanhq_f16(float16x8_t val);
Georgios Pinitascdf51452017-08-31 14:21:36 +0100131
132/** Calculate reciprocal.
133 *
134 * @param[in] x Input value.
135 *
136 * @return The calculated reciprocal.
137 */
138float16x4_t vinv_f16(float16x4_t x);
139
140/** Calculate reciprocal.
141 *
142 * @param[in] x Input value.
143 *
144 * @return The calculated reciprocal.
145 */
146float16x8_t vinvq_f16(float16x8_t x);
147
148/** Calculate inverse square root.
149 *
150 * @param[in] x Input value.
151 *
152 * @return The calculated inverse square root.
153 */
154float16x4_t vinvsqrt_f16(float16x4_t x);
155
Pablo Tello91654c42017-07-05 11:32:17 +0100156/** Calculate inverse square root.
157 *
158 * @param[in] x Input value.
159 *
160 * @return The calculated inverse square root.
161 */
162float16x8_t vinvsqrtq_f16(float16x8_t x);
Georgios Pinitascdf51452017-08-31 14:21:36 +0100163
Pablo Tellodf246182017-07-03 16:25:09 +0100164/** Calculate exponential
165 *
166 * @param[in] x Input vector value in F16 format.
167 *
168 * @return The calculated exponent.
169 */
170float16x8_t vexpq_f16(float16x8_t x);
Georgios Pinitascdf51452017-08-31 14:21:36 +0100171
Pablo Tellodf246182017-07-03 16:25:09 +0100172/** Calculate n power of a number.
173 *
174 * pow(x,n) = e^(n*log(x))
175 *
176 * @param[in] val Input vector value in F16 format.
177 * @param[in] n Powers to raise the input to.
178 *
179 * @return The calculated power.
180 */
181float16x8_t vpowq_f16(float16x8_t val, float16x8_t n);
Ioan-Cristian Szabo33fd07b2017-10-26 15:42:24 +0100182#endif /* ARM_COMPUTE_AARCH64_V8_2 */
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100183} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184#include "arm_compute/core/NEON/NEMath.inl"
185#endif /* __ARM_COMPUTE_NEMATH_H__ */