Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 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> |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
Georgios Pinitas | d8e765b | 2017-08-02 13:44:33 +0100 | [diff] [blame] | 31 | /** Calculate floor of a vector. |
| 32 | * |
| 33 | * @param[in] val Input vector value in F32 format. |
| 34 | * |
| 35 | * @return The calculated floor vector. |
| 36 | */ |
| 37 | float32x4_t vfloorq_f32(float32x4_t val); |
| 38 | |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 39 | /** 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 | */ |
| 45 | float32x4_t vroundq_rte_f32(float32x4_t val); |
| 46 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | /** Calculate inverse square root. |
| 48 | * |
| 49 | * @param[in] x Input value. |
| 50 | * |
| 51 | * @return The calculated inverse square root. |
| 52 | */ |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 53 | float32x2_t vinvsqrt_f32(float32x2_t x); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 54 | |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 55 | /** Calculate inverse square root. |
| 56 | * |
| 57 | * @param[in] x Input value. |
| 58 | * |
| 59 | * @return The calculated inverse square root. |
| 60 | */ |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 61 | float32x4_t vinvsqrtq_f32(float32x4_t x); |
| 62 | |
| 63 | /** Calculate reciprocal. |
| 64 | * |
| 65 | * @param[in] x Input value. |
| 66 | * |
| 67 | * @return The calculated reciprocal. |
| 68 | */ |
| 69 | float32x2_t vinv_f32(float32x2_t x); |
Pablo Tello | 8fda1cb | 2017-07-05 15:20:38 +0100 | [diff] [blame] | 70 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 71 | /** Calculate reciprocal. |
| 72 | * |
| 73 | * @param[in] x Input value. |
| 74 | * |
| 75 | * @return The calculated reciprocal. |
| 76 | */ |
| 77 | float32x4_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 | */ |
| 86 | float32x4_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 | */ |
| 94 | float32x4_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 | */ |
| 102 | float32x4_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 | */ |
| 114 | float32x4_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 | */ |
| 125 | float32x4_t vpowq_f32(float32x4_t val, float32x4_t n); |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 126 | |
Manuel Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 127 | /** 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 Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 132 | * @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 | */ |
| 136 | int32x4_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 Bottini | 7bb56c6 | 2019-06-26 15:17:09 +0100 | [diff] [blame] | 143 | * @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 | */ |
| 147 | int32x4_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 | */ |
| 158 | int32_t rounding_divide_by_pow2(int32_t x, int exponent); |
| 159 | |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 160 | /** Converts from uint8x16 to float32x4x4_t |
| 161 | * |
| 162 | * @param[in] in Vector of uint8 to be converted |
| 163 | * |
| 164 | * @return Converted vector of float |
| 165 | */ |
| 166 | float32x4x4_t convert_uint8x16_to_float32x4x4(const uint8x16_t &in); |
| 167 | |
Sang-Hoon Park | c3a7420 | 2019-11-22 16:05:46 +0000 | [diff] [blame] | 168 | /** Converts from int8x16 to float32x4x4_t |
| 169 | * |
| 170 | * @param[in] in Vector of int8 to be converted |
| 171 | * |
| 172 | * @return Converted vector of float |
| 173 | */ |
| 174 | float32x4x4_t convert_int8x16_to_float32x4x4(const int8x16_t &in); |
| 175 | |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 176 | /** Converts from two float32x4x3_t to just one uint8x8x3_t |
| 177 | * |
| 178 | * @param[in] in1 First input vector of float to be converted |
| 179 | * @param[in] in2 Second input vector of float to be converted |
| 180 | * @param[out] out Converted output vector uint8 to store the result |
| 181 | */ |
| 182 | void convert_float32x4x3_to_uint8x8x3(const float32x4x3_t &in1, const float32x4x3_t &in2, uint8x8x3_t &out); |
| 183 | |
| 184 | /** Converts from two float32x4x4_t to just one uint8x16_t |
| 185 | * |
| 186 | * @param[in] in Vector of float to be converted |
| 187 | * @param[out] out Converted vector of uint8 to store the result |
| 188 | */ |
Sang-Hoon Park | c3a7420 | 2019-11-22 16:05:46 +0000 | [diff] [blame] | 189 | void convert_float32x4x4_to_uint8x16(const float32x4x4_t &in, uint8x16_t &out); |
| 190 | |
| 191 | /** Converts from float32x4x4_t to just one int8x16_t |
| 192 | * |
| 193 | * @param[in] in Vector of float to be converted |
| 194 | * @param[out] out Converted vector of uint8 to store the result |
| 195 | */ |
| 196 | void convert_float32x4x4_to_int8x16(const float32x4x4_t &in, int8x16_t &out); |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 197 | |
Manuel Bottini | ed75326 | 2019-05-15 15:30:47 +0100 | [diff] [blame] | 198 | /** Calculate sine. |
| 199 | * |
| 200 | * @param[in] val Input vector value in radians, F32 format. |
| 201 | * |
| 202 | * @return The calculated sine. |
| 203 | */ |
| 204 | float32x4_t vsinq_f32(float32x4_t val); |
| 205 | |
| 206 | /** Calculate sine. |
| 207 | * |
| 208 | * @param[in] val Input vector value in radians, F32 format. |
| 209 | * |
| 210 | * @return The calculated sine. |
| 211 | */ |
| 212 | float32x2_t vsin_f32(float32x2_t val); |
| 213 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 214 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Pablo Tello | 91654c4 | 2017-07-05 11:32:17 +0100 | [diff] [blame] | 215 | /** Calculate hyperbolic tangent. |
| 216 | * |
| 217 | * tanh(x) = (e^2x - 1)/(e^2x + 1) |
| 218 | * |
| 219 | * @note We clamp x to [-5,5] to avoid overflowing issues. |
| 220 | * |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 221 | * @param[in] val Input vector value in F16 format. |
Pablo Tello | 91654c4 | 2017-07-05 11:32:17 +0100 | [diff] [blame] | 222 | * |
| 223 | * @return The calculated Hyperbolic Tangent. |
| 224 | */ |
| 225 | float16x8_t vtanhq_f16(float16x8_t val); |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 226 | |
Usama Arif | 0a5a57a | 2019-05-23 14:20:33 +0100 | [diff] [blame] | 227 | /** Calculate round value of a vector to nearest with ties to even. |
| 228 | * |
| 229 | * @param[in] val Input vector value in F16 format. |
| 230 | * |
| 231 | * @return The calculated round vector. |
| 232 | */ |
| 233 | float16x8_t vroundq_rte_f16(float16x8_t val); |
| 234 | |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 235 | /** Calculate reciprocal. |
| 236 | * |
| 237 | * @param[in] x Input value. |
| 238 | * |
| 239 | * @return The calculated reciprocal. |
| 240 | */ |
| 241 | float16x4_t vinv_f16(float16x4_t x); |
| 242 | |
| 243 | /** Calculate reciprocal. |
| 244 | * |
| 245 | * @param[in] x Input value. |
| 246 | * |
| 247 | * @return The calculated reciprocal. |
| 248 | */ |
| 249 | float16x8_t vinvq_f16(float16x8_t x); |
| 250 | |
| 251 | /** Calculate inverse square root. |
| 252 | * |
| 253 | * @param[in] x Input value. |
| 254 | * |
| 255 | * @return The calculated inverse square root. |
| 256 | */ |
| 257 | float16x4_t vinvsqrt_f16(float16x4_t x); |
| 258 | |
Pablo Tello | 91654c4 | 2017-07-05 11:32:17 +0100 | [diff] [blame] | 259 | /** Calculate inverse square root. |
| 260 | * |
| 261 | * @param[in] x Input value. |
| 262 | * |
| 263 | * @return The calculated inverse square root. |
| 264 | */ |
| 265 | float16x8_t vinvsqrtq_f16(float16x8_t x); |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 266 | |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 267 | /** Calculate exponential |
| 268 | * |
| 269 | * @param[in] x Input vector value in F16 format. |
| 270 | * |
| 271 | * @return The calculated exponent. |
| 272 | */ |
| 273 | float16x8_t vexpq_f16(float16x8_t x); |
Georgios Pinitas | cdf5145 | 2017-08-31 14:21:36 +0100 | [diff] [blame] | 274 | |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 275 | /** Calculate n power of a number. |
| 276 | * |
| 277 | * pow(x,n) = e^(n*log(x)) |
| 278 | * |
| 279 | * @param[in] val Input vector value in F16 format. |
| 280 | * @param[in] n Powers to raise the input to. |
| 281 | * |
| 282 | * @return The calculated power. |
| 283 | */ |
| 284 | float16x8_t vpowq_f16(float16x8_t val, float16x8_t n); |
Manuel Bottini | ed75326 | 2019-05-15 15:30:47 +0100 | [diff] [blame] | 285 | |
| 286 | /** Calculate sine. |
| 287 | * |
| 288 | * @param[in] val Input vector value in radians, F16 format. |
| 289 | * |
| 290 | * @return The calculated sine. |
| 291 | */ |
| 292 | float16x8_t vsinq_f16(float16x8_t val); |
| 293 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 294 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 295 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 296 | #include "arm_compute/core/NEON/NEMath.inl" |
Manuel Bottini | 21079dd | 2019-10-29 17:20:09 +0000 | [diff] [blame] | 297 | #endif /* ARM_COMPUTE_NEMATH_H */ |