blob: 8593059b1a9b8cf491b35d7f64a327518fe82190 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Usama Arif0a5a57a2019-05-23 14:20:33 +01002 * Copyright (c) 2016-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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
Usama Arif0a5a57a2019-05-23 14:20:33 +010039/** Calculate round value of a vector to nearest with ties to even.
40 *
41 * @param[in] val Input vector value in F32 format.
42 *
43 * @return The calculated round vector.
44 */
45float32x4_t vroundq_rte_f32(float32x4_t val);
46
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 +010053float32x2_t vinvsqrt_f32(float32x2_t x);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054
Pablo Tello8fda1cb2017-07-05 15:20:38 +010055/** Calculate inverse square root.
56 *
57 * @param[in] x Input value.
58 *
59 * @return The calculated inverse square root.
60 */
Georgios Pinitascdf51452017-08-31 14:21:36 +010061float32x4_t vinvsqrtq_f32(float32x4_t x);
62
63/** Calculate reciprocal.
64 *
65 * @param[in] x Input value.
66 *
67 * @return The calculated reciprocal.
68 */
69float32x2_t vinv_f32(float32x2_t x);
Pablo Tello8fda1cb2017-07-05 15:20:38 +010070
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071/** Calculate reciprocal.
72 *
73 * @param[in] x Input value.
74 *
75 * @return The calculated reciprocal.
76 */
77float32x4_t vinvq_f32(float32x4_t x);
78
79/** Perform a 7th degree polynomial approximation using Estrin's method.
80 *
81 * @param[in] x Input vector value in F32 format.
82 * @param[in] coeffs Polynomial coefficients table.
83 *
84 * @return The calculated approximation.
85 */
86float32x4_t vtaylor_polyq_f32(float32x4_t x, const std::array<float32x4_t, 8> &coeffs);
87
88/** Calculate exponential
89 *
90 * @param[in] x Input vector value in F32 format.
91 *
92 * @return The calculated exponent.
93 */
94float32x4_t vexpq_f32(float32x4_t x);
95
96/** Calculate logarithm
97 *
98 * @param[in] x Input vector value in F32 format.
99 *
100 * @return The calculated logarithm.
101 */
102float32x4_t vlogq_f32(float32x4_t x);
103
104/** Calculate hyperbolic tangent.
105 *
106 * tanh(x) = (e^2x - 1)/(e^2x + 1)
107 *
108 * @note We clamp x to [-5,5] to avoid overflowing issues.
109 *
110 * @param[in] val Input vector value in F32 format.
111 *
112 * @return The calculated Hyperbolic Tangent.
113 */
114float32x4_t vtanhq_f32(float32x4_t val);
115
116/** Calculate n power of a number.
117 *
118 * pow(x,n) = e^(n*log(x))
119 *
120 * @param[in] val Input vector value in F32 format.
121 * @param[in] n Powers to raise the input to.
122 *
123 * @return The calculated power.
124 */
125float32x4_t vpowq_f32(float32x4_t val, float32x4_t n);
Pablo Tellodf246182017-07-03 16:25:09 +0100126
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100127/** Round to the nearest division by a power-of-two using exponent
128 *
129 * @note This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent
130 *
131 * @param[in] x Vector of 4 elements
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +0100132 * @param[in] exponent Vector of 4 elements with integer value used to round to nearest division by a power-of-two
133 *
134 * @return the nearest division by a power-of-two using exponent
135 */
136int32x4_t rounding_divide_by_pow2(int32x4_t x, int32x4_t exponent);
137
138/** Round to the nearest division by a power-of-two using exponent
139 *
140 * @note This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent
141 *
142 * @param[in] x Vector of 4 elements
Manuel Bottini7bb56c62019-06-26 15:17:09 +0100143 * @param[in] exponent Integer value used to round to nearest division by a power-of-two
144 *
145 * @return the nearest division by a power-of-two using exponent
146 */
147int32x4_t rounding_divide_by_pow2(int32x4_t x, int exponent);
148
149/** Round to the nearest division by a power-of-two using exponent
150 *
151 * @note This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent
152 *
153 * @param[in] x Element to divide.
154 * @param[in] exponent Integer value used to round to nearest division by a power-of-two
155 *
156 * @return the nearest division by a power-of-two using exponent
157 */
158int32_t rounding_divide_by_pow2(int32_t x, int exponent);
159
Manuel Bottinied753262019-05-15 15:30:47 +0100160/** Calculate sine.
161 *
162 * @param[in] val Input vector value in radians, F32 format.
163 *
164 * @return The calculated sine.
165 */
166float32x4_t vsinq_f32(float32x4_t val);
167
168/** Calculate sine.
169 *
170 * @param[in] val Input vector value in radians, F32 format.
171 *
172 * @return The calculated sine.
173 */
174float32x2_t vsin_f32(float32x2_t val);
175
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000176#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Pablo Tello91654c42017-07-05 11:32:17 +0100177/** Calculate hyperbolic tangent.
178 *
179 * tanh(x) = (e^2x - 1)/(e^2x + 1)
180 *
181 * @note We clamp x to [-5,5] to avoid overflowing issues.
182 *
Usama Arif0a5a57a2019-05-23 14:20:33 +0100183 * @param[in] val Input vector value in F16 format.
Pablo Tello91654c42017-07-05 11:32:17 +0100184 *
185 * @return The calculated Hyperbolic Tangent.
186 */
187float16x8_t vtanhq_f16(float16x8_t val);
Georgios Pinitascdf51452017-08-31 14:21:36 +0100188
Usama Arif0a5a57a2019-05-23 14:20:33 +0100189/** Calculate round value of a vector to nearest with ties to even.
190 *
191 * @param[in] val Input vector value in F16 format.
192 *
193 * @return The calculated round vector.
194 */
195float16x8_t vroundq_rte_f16(float16x8_t val);
196
Georgios Pinitascdf51452017-08-31 14:21:36 +0100197/** Calculate reciprocal.
198 *
199 * @param[in] x Input value.
200 *
201 * @return The calculated reciprocal.
202 */
203float16x4_t vinv_f16(float16x4_t x);
204
205/** Calculate reciprocal.
206 *
207 * @param[in] x Input value.
208 *
209 * @return The calculated reciprocal.
210 */
211float16x8_t vinvq_f16(float16x8_t x);
212
213/** Calculate inverse square root.
214 *
215 * @param[in] x Input value.
216 *
217 * @return The calculated inverse square root.
218 */
219float16x4_t vinvsqrt_f16(float16x4_t x);
220
Pablo Tello91654c42017-07-05 11:32:17 +0100221/** Calculate inverse square root.
222 *
223 * @param[in] x Input value.
224 *
225 * @return The calculated inverse square root.
226 */
227float16x8_t vinvsqrtq_f16(float16x8_t x);
Georgios Pinitascdf51452017-08-31 14:21:36 +0100228
Pablo Tellodf246182017-07-03 16:25:09 +0100229/** Calculate exponential
230 *
231 * @param[in] x Input vector value in F16 format.
232 *
233 * @return The calculated exponent.
234 */
235float16x8_t vexpq_f16(float16x8_t x);
Georgios Pinitascdf51452017-08-31 14:21:36 +0100236
Pablo Tellodf246182017-07-03 16:25:09 +0100237/** Calculate n power of a number.
238 *
239 * pow(x,n) = e^(n*log(x))
240 *
241 * @param[in] val Input vector value in F16 format.
242 * @param[in] n Powers to raise the input to.
243 *
244 * @return The calculated power.
245 */
246float16x8_t vpowq_f16(float16x8_t val, float16x8_t n);
Manuel Bottinied753262019-05-15 15:30:47 +0100247
248/** Calculate sine.
249 *
250 * @param[in] val Input vector value in radians, F16 format.
251 *
252 * @return The calculated sine.
253 */
254float16x8_t vsinq_f16(float16x8_t val);
255
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000256#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100257} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258#include "arm_compute/core/NEON/NEMath.inl"
259#endif /* __ARM_COMPUTE_NEMATH_H__ */