Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEMATH_H |
| 25 | #define ARM_COMPUTE_NEMATH_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
| 27 | #include <arm_neon.h> |
morgolock | 3155f77 | 2020-05-11 16:00:04 +0100 | [diff] [blame] | 28 | #include <array> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | |
| 30 | namespace arm_compute |
| 31 | { |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 32 | /** Calculate floor of a vector. |
| 33 | * |
| 34 | * @param[in] val Input vector value in F32 format. |
| 35 | * |
| 36 | * @return The calculated floor vector. |
| 37 | */ |
| 38 | float32x4_t vfloorq_f32(float32x4_t val); |
| 39 | |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 40 | /** Calculate round value of a vector to nearest with ties to even. |
| 41 | * |
| 42 | * @param[in] val Input vector value in F32 format. |
| 43 | * |
| 44 | * @return The calculated round vector. |
| 45 | */ |
| 46 | float32x4_t vroundq_rte_f32(float32x4_t val); |
| 47 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 48 | /** Calculate inverse square root. |
| 49 | * |
| 50 | * @param[in] x Input value. |
| 51 | * |
| 52 | * @return The calculated inverse square root. |
| 53 | */ |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 54 | float32x2_t vinvsqrt_f32(float32x2_t x); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 56 | /** Calculate inverse square root. |
| 57 | * |
| 58 | * @param[in] x Input value. |
| 59 | * |
| 60 | * @return The calculated inverse square root. |
| 61 | */ |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 62 | float32x4_t vinvsqrtq_f32(float32x4_t x); |
| 63 | |
| 64 | /** Calculate reciprocal. |
| 65 | * |
| 66 | * @param[in] x Input value. |
| 67 | * |
| 68 | * @return The calculated reciprocal. |
| 69 | */ |
| 70 | float32x2_t vinv_f32(float32x2_t x); |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 71 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 72 | /** Calculate reciprocal. |
| 73 | * |
| 74 | * @param[in] x Input value. |
| 75 | * |
| 76 | * @return The calculated reciprocal. |
| 77 | */ |
| 78 | float32x4_t vinvq_f32(float32x4_t x); |
| 79 | |
| 80 | /** Perform a 7th degree polynomial approximation using Estrin's method. |
| 81 | * |
| 82 | * @param[in] x Input vector value in F32 format. |
| 83 | * @param[in] coeffs Polynomial coefficients table. |
| 84 | * |
| 85 | * @return The calculated approximation. |
| 86 | */ |
| 87 | float32x4_t vtaylor_polyq_f32(float32x4_t x, const std::array<float32x4_t, 8> &coeffs); |
| 88 | |
| 89 | /** Calculate exponential |
| 90 | * |
| 91 | * @param[in] x Input vector value in F32 format. |
| 92 | * |
| 93 | * @return The calculated exponent. |
| 94 | */ |
| 95 | float32x4_t vexpq_f32(float32x4_t x); |
| 96 | |
| 97 | /** Calculate logarithm |
| 98 | * |
| 99 | * @param[in] x Input vector value in F32 format. |
| 100 | * |
| 101 | * @return The calculated logarithm. |
| 102 | */ |
| 103 | float32x4_t vlogq_f32(float32x4_t x); |
| 104 | |
| 105 | /** Calculate hyperbolic tangent. |
| 106 | * |
| 107 | * tanh(x) = (e^2x - 1)/(e^2x + 1) |
| 108 | * |
| 109 | * @note We clamp x to [-5,5] to avoid overflowing issues. |
| 110 | * |
| 111 | * @param[in] val Input vector value in F32 format. |
| 112 | * |
| 113 | * @return The calculated Hyperbolic Tangent. |
| 114 | */ |
| 115 | float32x4_t vtanhq_f32(float32x4_t val); |
| 116 | |
| 117 | /** Calculate n power of a number. |
| 118 | * |
| 119 | * pow(x,n) = e^(n*log(x)) |
| 120 | * |
| 121 | * @param[in] val Input vector value in F32 format. |
| 122 | * @param[in] n Powers to raise the input to. |
| 123 | * |
| 124 | * @return The calculated power. |
| 125 | */ |
| 126 | float32x4_t vpowq_f32(float32x4_t val, float32x4_t n); |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 127 | |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 128 | /** Round to the nearest division by a power-of-two using exponent |
| 129 | * |
| 130 | * @note This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent |
| 131 | * |
| 132 | * @param[in] x Vector of 4 elements |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 133 | * @param[in] exponent Vector of 4 elements with integer value used to round to nearest division by a power-of-two |
| 134 | * |
| 135 | * @return the nearest division by a power-of-two using exponent |
| 136 | */ |
| 137 | int32x4_t rounding_divide_by_pow2(int32x4_t x, int32x4_t exponent); |
| 138 | |
| 139 | /** Round to the nearest division by a power-of-two using exponent |
| 140 | * |
| 141 | * @note This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent |
| 142 | * |
| 143 | * @param[in] x Vector of 4 elements |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 144 | * @param[in] exponent Integer value used to round to nearest division by a power-of-two |
| 145 | * |
| 146 | * @return the nearest division by a power-of-two using exponent |
| 147 | */ |
| 148 | int32x4_t rounding_divide_by_pow2(int32x4_t x, int exponent); |
| 149 | |
| 150 | /** Round to the nearest division by a power-of-two using exponent |
| 151 | * |
| 152 | * @note This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent |
| 153 | * |
| 154 | * @param[in] x Element to divide. |
| 155 | * @param[in] exponent Integer value used to round to nearest division by a power-of-two |
| 156 | * |
| 157 | * @return the nearest division by a power-of-two using exponent |
| 158 | */ |
| 159 | int32_t rounding_divide_by_pow2(int32_t x, int exponent); |
| 160 | |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 161 | /** Converts from uint8x16 to float32x4x4_t |
| 162 | * |
| 163 | * @param[in] in Vector of uint8 to be converted |
| 164 | * |
| 165 | * @return Converted vector of float |
| 166 | */ |
| 167 | float32x4x4_t convert_uint8x16_to_float32x4x4(const uint8x16_t &in); |
| 168 | |
Sang-Hoon Park | c3a7420 | 2019-11-22 16:05:46 +0000 | [diff] [blame] | 169 | /** Converts from int8x16 to float32x4x4_t |
| 170 | * |
| 171 | * @param[in] in Vector of int8 to be converted |
| 172 | * |
| 173 | * @return Converted vector of float |
| 174 | */ |
| 175 | float32x4x4_t convert_int8x16_to_float32x4x4(const int8x16_t &in); |
| 176 | |
Manuel Bottini | 4370cff | 2020-02-07 16:31:59 +0000 | [diff] [blame] | 177 | /** Converts to float32x4x4_t from the specified templated 16 elements vectors |
| 178 | * |
| 179 | * @param[in] in Vector of float to be converted |
| 180 | * |
| 181 | * @return Converted vector of float |
| 182 | */ |
| 183 | template <typename T> |
| 184 | float32x4x4_t convert_to_float32x4x4(const T &in); |
| 185 | |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 186 | /** Converts from two float32x4x3_t to just one uint8x8x3_t |
| 187 | * |
| 188 | * @param[in] in1 First input vector of float to be converted |
| 189 | * @param[in] in2 Second input vector of float to be converted |
| 190 | * @param[out] out Converted output vector uint8 to store the result |
| 191 | */ |
| 192 | void convert_float32x4x3_to_uint8x8x3(const float32x4x3_t &in1, const float32x4x3_t &in2, uint8x8x3_t &out); |
| 193 | |
| 194 | /** Converts from two float32x4x4_t to just one uint8x16_t |
| 195 | * |
| 196 | * @param[in] in Vector of float to be converted |
| 197 | * @param[out] out Converted vector of uint8 to store the result |
| 198 | */ |
Sang-Hoon Park | c3a7420 | 2019-11-22 16:05:46 +0000 | [diff] [blame] | 199 | void convert_float32x4x4_to_uint8x16(const float32x4x4_t &in, uint8x16_t &out); |
| 200 | |
| 201 | /** Converts from float32x4x4_t to just one int8x16_t |
| 202 | * |
| 203 | * @param[in] in Vector of float to be converted |
| 204 | * @param[out] out Converted vector of uint8 to store the result |
| 205 | */ |
| 206 | void convert_float32x4x4_to_int8x16(const float32x4x4_t &in, int8x16_t &out); |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 207 | |
Manuel Bottini | ed75326 | 2019-05-15 15:30:47 +0100 | [diff] [blame] | 208 | /** Calculate sine. |
| 209 | * |
| 210 | * @param[in] val Input vector value in radians, F32 format. |
| 211 | * |
| 212 | * @return The calculated sine. |
| 213 | */ |
| 214 | float32x4_t vsinq_f32(float32x4_t val); |
| 215 | |
| 216 | /** Calculate sine. |
| 217 | * |
| 218 | * @param[in] val Input vector value in radians, F32 format. |
| 219 | * |
| 220 | * @return The calculated sine. |
| 221 | */ |
| 222 | float32x2_t vsin_f32(float32x2_t val); |
| 223 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 224 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Pablo Tello | 91654c4 | 2017-07-05 11:32:17 +0100 | [diff] [blame] | 225 | /** Calculate hyperbolic tangent. |
| 226 | * |
| 227 | * tanh(x) = (e^2x - 1)/(e^2x + 1) |
| 228 | * |
| 229 | * @note We clamp x to [-5,5] to avoid overflowing issues. |
| 230 | * |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 231 | * @param[in] val Input vector value in F16 format. |
Pablo Tello | 91654c4 | 2017-07-05 11:32:17 +0100 | [diff] [blame] | 232 | * |
| 233 | * @return The calculated Hyperbolic Tangent. |
| 234 | */ |
| 235 | float16x8_t vtanhq_f16(float16x8_t val); |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 236 | |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 237 | /** Calculate round value of a vector to nearest with ties to even. |
| 238 | * |
| 239 | * @param[in] val Input vector value in F16 format. |
| 240 | * |
| 241 | * @return The calculated round vector. |
| 242 | */ |
| 243 | float16x8_t vroundq_rte_f16(float16x8_t val); |
| 244 | |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 245 | /** Calculate reciprocal. |
| 246 | * |
| 247 | * @param[in] x Input value. |
| 248 | * |
| 249 | * @return The calculated reciprocal. |
| 250 | */ |
| 251 | float16x4_t vinv_f16(float16x4_t x); |
| 252 | |
| 253 | /** Calculate reciprocal. |
| 254 | * |
| 255 | * @param[in] x Input value. |
| 256 | * |
| 257 | * @return The calculated reciprocal. |
| 258 | */ |
| 259 | float16x8_t vinvq_f16(float16x8_t x); |
| 260 | |
| 261 | /** Calculate inverse square root. |
| 262 | * |
| 263 | * @param[in] x Input value. |
| 264 | * |
| 265 | * @return The calculated inverse square root. |
| 266 | */ |
| 267 | float16x4_t vinvsqrt_f16(float16x4_t x); |
| 268 | |
Pablo Tello | 91654c4 | 2017-07-05 11:32:17 +0100 | [diff] [blame] | 269 | /** Calculate inverse square root. |
| 270 | * |
| 271 | * @param[in] x Input value. |
| 272 | * |
| 273 | * @return The calculated inverse square root. |
| 274 | */ |
| 275 | float16x8_t vinvsqrtq_f16(float16x8_t x); |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 276 | |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 277 | /** Calculate exponential |
| 278 | * |
| 279 | * @param[in] x Input vector value in F16 format. |
| 280 | * |
| 281 | * @return The calculated exponent. |
| 282 | */ |
| 283 | float16x8_t vexpq_f16(float16x8_t x); |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 284 | |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 285 | /** Calculate n power of a number. |
| 286 | * |
| 287 | * pow(x,n) = e^(n*log(x)) |
| 288 | * |
| 289 | * @param[in] val Input vector value in F16 format. |
| 290 | * @param[in] n Powers to raise the input to. |
| 291 | * |
| 292 | * @return The calculated power. |
| 293 | */ |
| 294 | float16x8_t vpowq_f16(float16x8_t val, float16x8_t n); |
Manuel Bottini | ed75326 | 2019-05-15 15:30:47 +0100 | [diff] [blame] | 295 | |
| 296 | /** Calculate sine. |
| 297 | * |
| 298 | * @param[in] val Input vector value in radians, F16 format. |
| 299 | * |
| 300 | * @return The calculated sine. |
| 301 | */ |
| 302 | float16x8_t vsinq_f16(float16x8_t val); |
| 303 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 304 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 305 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 306 | #include "arm_compute/core/NEON/NEMath.inl" |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 307 | #endif /* ARM_COMPUTE_NEMATH_H */ |