Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | * of this software and associated documentation files (the "Software"), to |
| 6 | * deal in the Software without restriction, including without limitation the |
| 7 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 8 | * sell copies of the Software, and to permit persons to whom the Software is |
| 9 | * furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in all |
| 12 | * copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | * SOFTWARE. |
| 21 | */ |
| 22 | #ifndef __ARM_COMPUTE_FIXEDPOINT_H__ |
| 23 | #define __ARM_COMPUTE_FIXEDPOINT_H__ |
| 24 | |
| 25 | #include <cstdint> |
| 26 | |
| 27 | namespace arm_compute |
| 28 | { |
| 29 | using qint8_t = int8_t; /**< 8 bit fixed point scalar value */ |
| 30 | using qint16_t = int16_t; /**< 16 bit fixed point scalar value */ |
| 31 | using qint32_t = int32_t; /**< 32 bit fixed point scalar value */ |
Georgios Pinitas | 9247c92 | 2017-06-28 18:29:47 +0100 | [diff] [blame] | 32 | using qint64_t = int64_t; /**< 64 bit fixed point scalar value */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | |
| 34 | /** 8 bit fixed point scalar saturating shift left |
| 35 | * |
| 36 | * @param[in] a First 8 bit fixed point input |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 37 | * @param[in] shift Shift amount (positive only values) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 38 | * |
| 39 | * @return The result of the 8 bit fixed point shift. The result is saturated in case of overflow |
| 40 | */ |
| 41 | qint8_t sqshl_qs8(qint8_t a, int shift); |
| 42 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 43 | /** 16 bit fixed point scalar saturating shift left |
| 44 | * |
| 45 | * @param[in] a First 16 bit fixed point input |
| 46 | * @param[in] shift Shift amount (positive only values) |
| 47 | * |
| 48 | * @return The result of the 16 bit fixed point shift. The result is saturated in case of overflow |
| 49 | */ |
| 50 | qint16_t sqshl_qs16(qint16_t a, int shift); |
| 51 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | /** 8 bit fixed point scalar absolute value |
| 53 | * |
| 54 | * @param[in] a 8 bit fixed point input |
| 55 | * |
| 56 | * @return The result of the 8 bit fixed point absolute value |
| 57 | */ |
| 58 | qint8_t sabs_qs8(qint8_t a); |
| 59 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 60 | /** 16 bit fixed point scalar absolute value |
| 61 | * |
| 62 | * @param[in] a 16 bit fixed point input |
| 63 | * |
| 64 | * @return The result of the 16 bit fixed point absolute value |
| 65 | */ |
| 66 | qint16_t sabs_qs16(qint16_t a); |
| 67 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | /** 8 bit fixed point scalar add |
| 69 | * |
| 70 | * @param[in] a First 8 bit fixed point input |
| 71 | * @param[in] b Second 8 bit fixed point input |
| 72 | * |
| 73 | * @return The result of the 8 bit fixed point addition |
| 74 | */ |
| 75 | qint8_t sadd_qs8(qint8_t a, qint8_t b); |
| 76 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 77 | /** 16 bit fixed point scalar add |
| 78 | * |
| 79 | * @param[in] a First 16 bit fixed point input |
| 80 | * @param[in] b Second 16 bit fixed point input |
| 81 | * |
| 82 | * @return The result of the 16 bit fixed point addition |
| 83 | */ |
| 84 | qint16_t sadd_qs16(qint16_t a, qint16_t b); |
| 85 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | /** 8 bit fixed point scalar saturating add |
| 87 | * |
| 88 | * @param[in] a First 8 bit fixed point input |
| 89 | * @param[in] b Second 8 bit fixed point input |
| 90 | * |
| 91 | * @return The result of the 8 bit fixed point addition. The result is saturated in case of overflow |
| 92 | */ |
| 93 | qint8_t sqadd_qs8(qint8_t a, qint8_t b); |
| 94 | |
| 95 | /** 16 bit fixed point scalar saturating add |
| 96 | * |
| 97 | * @param[in] a First 16 bit fixed point input |
| 98 | * @param[in] b Second 16 bit fixed point input |
| 99 | * |
| 100 | * @return The result of the 16 bit fixed point addition. The result is saturated in case of overflow |
| 101 | */ |
| 102 | qint16_t sqadd_qs16(qint16_t a, qint16_t b); |
| 103 | |
Georgios Pinitas | 9247c92 | 2017-06-28 18:29:47 +0100 | [diff] [blame] | 104 | /** 32 bit fixed point scalar saturating add |
| 105 | * |
| 106 | * @param[in] a First 32 bit fixed point input |
| 107 | * @param[in] b Second 32 bit fixed point input |
| 108 | * |
| 109 | * @return The result of the 32 bit fixed point addition. The result is saturated in case of overflow |
| 110 | */ |
| 111 | qint32_t sqadd_qs32(qint32_t a, qint32_t b); |
| 112 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | /** 8 bit fixed point scalar subtraction |
| 114 | * |
| 115 | * @param[in] a First 8 bit fixed point input |
| 116 | * @param[in] b Second 8 bit fixed point input |
| 117 | * |
| 118 | * @return The result of the 8 bit fixed point subtraction |
| 119 | */ |
| 120 | qint8_t ssub_qs8(qint8_t a, qint8_t b); |
| 121 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 122 | /** 16 bit fixed point scalar subtraction |
| 123 | * |
| 124 | * @param[in] a First 16 bit fixed point input |
| 125 | * @param[in] b Second 16 bit fixed point input |
| 126 | * |
| 127 | * @return The result of the 16 bit fixed point subtraction |
| 128 | */ |
| 129 | qint16_t ssub_qs16(qint16_t a, qint16_t b); |
| 130 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | /** 8 bit fixed point scalar saturating subtraction |
| 132 | * |
| 133 | * @param[in] a First 8 bit fixed point input |
| 134 | * @param[in] b Second 8 bit fixed point input |
| 135 | * |
| 136 | * @return The result of the 8 bit fixed point subtraction. The result is saturated in case of overflow |
| 137 | */ |
| 138 | qint8_t sqsub_qs8(qint8_t a, qint8_t b); |
| 139 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 140 | /** 16 bit fixed point scalar saturating subtraction |
| 141 | * |
| 142 | * @param[in] a First 16 bit fixed point input |
| 143 | * @param[in] b Second 16 bit fixed point input |
| 144 | * |
| 145 | * @return The result of the 16 bit fixed point subtraction. The result is saturated in case of overflow |
| 146 | */ |
| 147 | qint16_t sqsub_qs16(qint16_t a, qint16_t b); |
| 148 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 149 | /** 8 bit fixed point scalar multiply |
| 150 | * |
| 151 | * @param[in] a First 8 bit fixed point input |
| 152 | * @param[in] b Second 8 bit fixed point input |
| 153 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 154 | * |
| 155 | * @return The result of the 8 bit fixed point multiplication. |
| 156 | */ |
| 157 | qint8_t smul_qs8(qint8_t a, qint8_t b, int fixed_point_position); |
| 158 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 159 | /** 16 bit fixed point scalar multiply |
| 160 | * |
| 161 | * @param[in] a First 16 bit fixed point input |
| 162 | * @param[in] b Second 16 bit fixed point input |
| 163 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 164 | * |
| 165 | * @return The result of the 16 bit fixed point multiplication. |
| 166 | */ |
| 167 | qint16_t smul_qs16(qint16_t a, qint16_t b, int fixed_point_position); |
| 168 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 169 | /** 8 bit fixed point scalar saturating multiply |
| 170 | * |
| 171 | * @param[in] a First 8 bit fixed point input |
| 172 | * @param[in] b Second 8 bit fixed point input |
| 173 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 174 | * |
| 175 | * @return The result of the 8 bit fixed point multiplication. The result is saturated in case of overflow |
| 176 | */ |
| 177 | qint8_t sqmul_qs8(qint8_t a, qint8_t b, int fixed_point_position); |
| 178 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 179 | /** 16 bit fixed point scalar saturating multiply |
| 180 | * |
| 181 | * @param[in] a First 16 bit fixed point input |
| 182 | * @param[in] b Second 16 bit fixed point input |
| 183 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 184 | * |
| 185 | * @return The result of the 16 bit fixed point multiplication. The result is saturated in case of overflow |
| 186 | */ |
| 187 | qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position); |
| 188 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 189 | /** 8 bit fixed point scalar multiply long |
| 190 | * |
| 191 | * @param[in] a First 8 bit fixed point input |
| 192 | * @param[in] b Second 8 bit fixed point input |
| 193 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 194 | * |
| 195 | * @return The result of the 8 bit fixed point multiplication long. The result is saturated in case of overflow |
| 196 | */ |
| 197 | qint16_t sqmull_qs8(qint8_t a, qint8_t b, int fixed_point_position); |
| 198 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 199 | /** 16 bit fixed point scalar multiply long |
| 200 | * |
| 201 | * @param[in] a First 16 bit fixed point input |
| 202 | * @param[in] b Second 16 bit fixed point input |
| 203 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 204 | * |
| 205 | * @return The result of the 16 bit fixed point multiplication long. The result is saturated in case of overflow |
| 206 | */ |
| 207 | qint32_t sqmull_qs16(qint16_t a, qint16_t b, int fixed_point_position); |
| 208 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 209 | /** 16 bit fixed point scalar saturating multiply |
| 210 | * |
| 211 | * @param[in] a First 16 bit fixed point input |
| 212 | * @param[in] b Second 16 bit fixed point input |
| 213 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 214 | * |
| 215 | * @return The result of the 16 bit fixed point multiplication. The result is saturated in case of overflow |
| 216 | */ |
| 217 | qint16_t sqmul_qs16(qint16_t a, qint16_t b, int fixed_point_position); |
| 218 | |
| 219 | /** 8 bit fixed point scalar inverse square root |
| 220 | * |
| 221 | * @param[in] a 8 bit fixed point input |
| 222 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 223 | * |
| 224 | * @return The result of the 8 bit fixed point inverse square root. |
| 225 | */ |
| 226 | qint8_t sinvsqrt_qs8(qint8_t a, int fixed_point_position); |
| 227 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 228 | /** 16 bit fixed point scalar inverse square root |
| 229 | * |
| 230 | * @param[in] a 16 bit fixed point input |
| 231 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 232 | * |
| 233 | * @return The result of the 16 bit fixed point inverse square root. |
| 234 | */ |
| 235 | qint16_t sinvsqrt_qs16(qint16_t a, int fixed_point_position); |
| 236 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 237 | /** 8 bit fixed point scalar division |
| 238 | * |
| 239 | * @param[in] a First 8 bit fixed point input |
| 240 | * @param[in] b Second 8 bit fixed point input |
| 241 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 242 | * |
| 243 | * @return The result of the 8 bit fixed point division. |
| 244 | */ |
| 245 | qint8_t sdiv_qs8(qint8_t a, qint8_t b, int fixed_point_position); |
| 246 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 247 | /** 16 bit fixed point scalar division |
| 248 | * |
| 249 | * @param[in] a First 16 bit fixed point input |
| 250 | * @param[in] b Second 16 bit fixed point input |
| 251 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 252 | * |
| 253 | * @return The result of the 16 bit fixed point division. |
| 254 | */ |
| 255 | qint16_t sdiv_qs16(qint16_t a, qint16_t b, int fixed_point_position); |
| 256 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 257 | /** 8 bit fixed point scalar exponential |
| 258 | * |
| 259 | * @param[in] a 8 bit fixed point input |
| 260 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 261 | * |
| 262 | * @return The result of the 8 bit fixed point exponential. |
| 263 | */ |
Georgios Pinitas | ccc65d4 | 2017-06-27 17:39:11 +0100 | [diff] [blame] | 264 | qint8_t sqexp_qs8(qint8_t a, int fixed_point_position); |
| 265 | |
| 266 | /** 16 bit fixed point scalar exponential |
| 267 | * |
| 268 | * @param[in] a 16 bit fixed point input |
| 269 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 270 | * |
| 271 | * @return The result of the 16 bit fixed point exponential. |
| 272 | */ |
| 273 | qint16_t sqexp_qs16(qint16_t a, int fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 274 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 275 | /** 16 bit fixed point scalar exponential |
| 276 | * |
| 277 | * @param[in] a 16 bit fixed point input |
| 278 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 279 | * |
| 280 | * @return The result of the 16 bit fixed point exponential. |
| 281 | */ |
| 282 | qint16_t sexp_qs16(qint16_t a, int fixed_point_position); |
| 283 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 284 | /** 8 bit fixed point scalar logarithm |
| 285 | * |
| 286 | * @param[in] a 8 bit fixed point input |
| 287 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 288 | * |
| 289 | * @return The result of the 8 bit fixed point logarithm. |
| 290 | */ |
| 291 | qint8_t slog_qs8(qint8_t a, int fixed_point_position); |
| 292 | |
Michalis Spyrou | 0a8334c | 2017-06-14 18:00:05 +0100 | [diff] [blame] | 293 | /** 16 bit fixed point scalar logarithm |
| 294 | * |
| 295 | * @param[in] a 16 bit fixed point input |
| 296 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 297 | * |
| 298 | * @return The result of the 16 bit fixed point logarithm. |
| 299 | */ |
| 300 | qint16_t slog_qs16(qint16_t a, int fixed_point_position); |
| 301 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 302 | /** Convert an 8 bit fixed point to float |
| 303 | * |
| 304 | * @param[in] a Input to convert |
| 305 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 306 | * |
| 307 | * @return The result of the conversion 8 bit fixed point -> float |
| 308 | */ |
| 309 | float scvt_f32_qs8(qint8_t a, int fixed_point_position); |
| 310 | |
| 311 | /** Convert a float to 8 bit fixed point |
| 312 | * |
| 313 | * @param[in] a Input to convert |
| 314 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 315 | * |
| 316 | * @return The result of the conversion float -> 8 bit fixed point |
| 317 | */ |
Georgios Pinitas | 21efeb4 | 2017-07-04 12:47:17 +0100 | [diff] [blame] | 318 | qint8_t sqcvt_qs8_f32(float a, int fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 319 | |
| 320 | /** Convert a 16 bit fixed point to float |
| 321 | * |
| 322 | * @param[in] a Input to convert |
| 323 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 324 | * |
| 325 | * @return The result of the conversion 16 bit fixed point -> float |
| 326 | */ |
| 327 | float scvt_f32_qs16(qint16_t a, int fixed_point_position); |
| 328 | |
| 329 | /** Convert a float to 16 bit fixed point |
| 330 | * |
| 331 | * @param[in] a Input to convert |
| 332 | * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number |
| 333 | * |
| 334 | * @return The result of the conversion float -> 16 bit fixed point |
| 335 | */ |
Georgios Pinitas | 21efeb4 | 2017-07-04 12:47:17 +0100 | [diff] [blame] | 336 | qint16_t sqcvt_qs16_f32(float a, int fixed_point_position); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 337 | |
| 338 | /** Scalar saturating move and narrow. |
| 339 | * |
| 340 | * @param[in] a Input to convert to 8 bit fixed point |
| 341 | * |
| 342 | * @return The narrowing conversion to 8 bit |
| 343 | */ |
| 344 | qint8_t sqmovn_qs16(qint16_t a); |
Georgios Pinitas | 9247c92 | 2017-06-28 18:29:47 +0100 | [diff] [blame] | 345 | |
| 346 | /** Scalar saturating move and narrow. |
| 347 | * |
| 348 | * @param[in] a Input to convert to 16 bit fixed point |
| 349 | * |
| 350 | * @return The narrowing conversion to 16 bit |
| 351 | */ |
| 352 | qint16_t sqmovn_qs32(qint32_t a); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 353 | } |
| 354 | #include "arm_compute/core/FixedPoint.inl" |
| 355 | #endif /* __ARM_COMPUTE_FIXEDPOINT_H__ */ |