Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [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 | */ |
| 24 | #ifndef ARM_COMPUTE_HELPERS_ASYMM_H |
| 25 | #define ARM_COMPUTE_HELPERS_ASYMM_H |
| 26 | |
| 27 | #include "helpers.h" |
| 28 | |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 29 | #define CONVERT_DOWN_RTE_STR(x, type) (convert_##type##_rte((x))) |
| 30 | #define CONVERT_DOWN_RTE(x, type) CONVERT_DOWN_RTE_STR(x, type) |
| 31 | |
| 32 | /** Quantize a floating-point scalar value to 8-bit asymmetric |
| 33 | * |
| 34 | * @param[in] input Input value to quantize |
| 35 | * @param[in] offset Quantization offset |
| 36 | * @param[in] scale Quantization scale |
| 37 | * |
| 38 | * @return quantized value |
| 39 | */ |
| 40 | inline uchar quantize_qasymm8(float input, float offset, float scale) |
| 41 | { |
| 42 | float out_f32 = input / scale + offset; |
| 43 | uchar res_u8 = CONVERT_SAT(CONVERT_DOWN_RTE(out_f32, int), uchar); |
| 44 | return res_u8; |
| 45 | } |
| 46 | |
| 47 | /** Dequantize a scalar value from 8-bit asymmetric to floating-point |
| 48 | * |
| 49 | * @param[in] input Input value to quantize |
| 50 | * @param[in] offset Quantization offset |
| 51 | * @param[in] scale Quantization scale |
| 52 | * |
| 53 | * @return quantized value |
| 54 | */ |
| 55 | inline float dequantize_qasymm8(uchar input, float offset, float scale) |
| 56 | { |
| 57 | return ((float)input - offset) * scale; |
| 58 | } |
| 59 | |
| 60 | /** Quantize a vector of values from floating-point |
| 61 | * |
| 62 | * @param[in] type Output data type. |
| 63 | * @param[in] size Size of vector. |
| 64 | * |
| 65 | * @return quantized values |
| 66 | */ |
| 67 | #define QUANTIZE_IMPL(type, size) \ |
| 68 | inline VEC_DATA_TYPE(type, size) quantize_##type##size(VEC_DATA_TYPE(float, size) input, float offset, float scale) \ |
| 69 | { \ |
| 70 | VEC_DATA_TYPE(float, size) \ |
| 71 | out_f32 = input / (VEC_DATA_TYPE(float, size))(scale) + (VEC_DATA_TYPE(float, size))(offset); \ |
| 72 | VEC_DATA_TYPE(type, size) \ |
| 73 | res = CONVERT_SAT(CONVERT_DOWN_RTE(out_f32, VEC_DATA_TYPE(int, size)), VEC_DATA_TYPE(type, size)); \ |
| 74 | return res; \ |
| 75 | } |
| 76 | |
| 77 | /** Dequantize a vector of values to floating-point |
| 78 | * |
| 79 | * @param[in] type Input data type. |
| 80 | * @param[in] size Size of vector. |
| 81 | * |
| 82 | * @return dequantized values in floating point |
| 83 | */ |
| 84 | #define DEQUANTIZE_IMPL(type, size) \ |
| 85 | inline VEC_DATA_TYPE(float, size) dequantize_##type##size(VEC_DATA_TYPE(type, size) input, float offset, float scale) \ |
| 86 | { \ |
| 87 | return (CONVERT(input, VEC_DATA_TYPE(float, 4)) - offset) * scale; \ |
| 88 | } |
| 89 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 90 | /** Correctly-rounded-to-nearest division by a power-of-two. |
| 91 | * |
| 92 | * @param[in] size Size of vector. |
| 93 | * |
| 94 | * @return Correctly-rounded-to-nearest division by a power-of-two. |
| 95 | */ |
| 96 | #define ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL(size) \ |
| 97 | inline VEC_DATA_TYPE(int, size) asymm_rounding_divide_by_POW2_##size(VEC_DATA_TYPE(int, size) x, int exponent) \ |
| 98 | { \ |
| 99 | VEC_DATA_TYPE(int, size) \ |
| 100 | mask = (1 << exponent) - 1; \ |
| 101 | const VEC_DATA_TYPE(int, size) zero = 0; \ |
| 102 | const VEC_DATA_TYPE(int, size) one = 1; \ |
| 103 | VEC_DATA_TYPE(int, size) \ |
| 104 | threshold = (mask >> 1) + select(zero, one, x < 0); \ |
| 105 | return (x >> exponent) + select(zero, one, (x & mask) > threshold); \ |
| 106 | } |
| 107 | |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 108 | /** Product of two numbers, interpreting them as fixed-point values in the interval [-1, 1), |
| 109 | * rounding to the nearest value, and saturating -1 * -1 to the maximum value. |
| 110 | * |
| 111 | * @param[in] size Size of vector. |
| 112 | * |
| 113 | * @return Product of two fixed-point numbers. |
| 114 | */ |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 115 | #define ASYMM_MULT_IMPL(size) \ |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 116 | inline VEC_DATA_TYPE(int, size) asymm_mult##size(VEC_DATA_TYPE(int, size) a, VEC_DATA_TYPE(int, size) b) \ |
| 117 | { \ |
| 118 | VEC_DATA_TYPE(int, size) \ |
| 119 | overflow = a == b && a == INT_MIN; \ |
| 120 | VEC_DATA_TYPE(long, size) \ |
| 121 | a_64 = convert_long##size(a); \ |
| 122 | VEC_DATA_TYPE(long, size) \ |
| 123 | b_64 = convert_long##size(b); \ |
| 124 | VEC_DATA_TYPE(long, size) \ |
| 125 | ab_64 = a_64 * b_64; \ |
Giorgio Arena | 6232d04 | 2018-02-12 14:46:00 +0000 | [diff] [blame] | 126 | /* COMPMID-907 */ \ |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 127 | VEC_DATA_TYPE(int, size) \ |
Giorgio Arena | 6232d04 | 2018-02-12 14:46:00 +0000 | [diff] [blame] | 128 | ab_x2_high32 = convert_int##size(((ab_64 + (1 << 30)) >> 31)); \ |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 129 | return select(ab_x2_high32, INT_MAX, overflow); \ |
| 130 | } |
| 131 | |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 132 | /** Calculates \f$ exp(x) \f$ for x in [-1/4, 0). |
| 133 | * |
| 134 | * @param[in] size Size of vector. |
| 135 | * |
| 136 | * @return Result in fixed-point format Q0. |
| 137 | */ |
| 138 | #define ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL(size) \ |
| 139 | inline VEC_DATA_TYPE(int, size) asymm_exp_on_interval_between_negative_one_quarter_and_0_excl##size(VEC_DATA_TYPE(int, size) a) \ |
| 140 | { \ |
| 141 | const VEC_DATA_TYPE(int, size) constant_term = 1895147668; \ |
| 142 | const VEC_DATA_TYPE(int, size) constant_1_over_3 = 715827883; \ |
| 143 | const int k_fractional_bits = 31; \ |
| 144 | VEC_DATA_TYPE(int, size) \ |
| 145 | x = a + (1 << (k_fractional_bits - 3)); \ |
| 146 | VEC_DATA_TYPE(int, size) \ |
| 147 | x2 = ASYMM_MULT(x, x, size); \ |
| 148 | VEC_DATA_TYPE(int, size) \ |
| 149 | x3 = ASYMM_MULT(x2, x, size); \ |
| 150 | VEC_DATA_TYPE(int, size) \ |
| 151 | x4 = ASYMM_MULT(x2, x2, size); \ |
| 152 | VEC_DATA_TYPE(int, size) \ |
| 153 | x4_over_4 = ASYMM_ROUNDING_DIVIDE_BY_POW2(x4, 2, size); \ |
| 154 | VEC_DATA_TYPE(int, size) \ |
| 155 | x4_over_24_plus_x3_over_6_plus_x2 = ASYMM_MULT((x4_over_4 + x3), constant_1_over_3, size) + x2; \ |
| 156 | VEC_DATA_TYPE(int, size) \ |
| 157 | x4_over_24_plus_x3_over_6_plus_x2_over_2 = ASYMM_ROUNDING_DIVIDE_BY_POW2(x4_over_24_plus_x3_over_6_plus_x2, 1, size); \ |
| 158 | return constant_term + ASYMM_MULT(constant_term, x + x4_over_24_plus_x3_over_6_plus_x2_over_2, size); \ |
| 159 | } |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 160 | |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 161 | /** Each bit of the result is set to the corresponding bit of either then_val or |
| 162 | * else_val depending on whether the corresponding bit of if_mask is set. |
| 163 | * Equivalent to the VBSL instruction in ARM NEON. |
| 164 | * |
| 165 | * @param[in] size Size of vector. |
| 166 | * |
| 167 | * @returns Result contaning bits from @p then_val or from @p else_val depending on corresponding bit in @p if_mask is set or not. |
| 168 | */ |
| 169 | #define ASYMM_SELECT_USING_MASK_IMPL(size) \ |
| 170 | inline VEC_DATA_TYPE(int, size) asymm_select_using_mask##size(VEC_DATA_TYPE(int, size) if_mask, VEC_DATA_TYPE(int, size) then_val, VEC_DATA_TYPE(int, size) else_val) \ |
| 171 | { \ |
| 172 | return (if_mask & then_val) ^ (~if_mask & else_val); \ |
| 173 | } |
| 174 | |
| 175 | /** For each element of input vector, the corresponding bits of the result item are set |
| 176 | * if the input item is zero. |
| 177 | * |
| 178 | * @param[in] size Size of vector. |
| 179 | * |
| 180 | * @returns Output vector with bits set when corresponding bit in @p a is zero. |
| 181 | */ |
| 182 | #define ASYMM_MASK_IF_ZERO_IMPL(size) \ |
| 183 | inline VEC_DATA_TYPE(int, size) asymm_mask_if_zero##size(VEC_DATA_TYPE(int, size) a) \ |
| 184 | { \ |
| 185 | const VEC_DATA_TYPE(int, size) all_zeros = 0; \ |
| 186 | const VEC_DATA_TYPE(int, size) all_ones = ~0; \ |
| 187 | return select(all_zeros, all_ones, a == 0); \ |
| 188 | } |
| 189 | |
| 190 | /** For each element of input vector, the corresponding bits of the result item are set |
| 191 | * if the input item is non-zero. |
| 192 | * |
| 193 | * @param[in] size Size of vector. |
| 194 | * |
| 195 | * @returns Output vector with bits set when corresponding bit in @p a is non zero. |
| 196 | */ |
| 197 | #define ASYMM_MASK_IF_NON_ZERO_IMPL(size) \ |
| 198 | inline VEC_DATA_TYPE(int, size) asymm_mask_if_non_zero##size(VEC_DATA_TYPE(int, size) a) \ |
| 199 | { \ |
| 200 | const VEC_DATA_TYPE(int, size) all_zeros = 0; \ |
| 201 | const VEC_DATA_TYPE(int, size) all_ones = ~0; \ |
| 202 | return select(all_zeros, all_ones, a != 0); \ |
| 203 | } |
| 204 | |
| 205 | #define EXP_BARREL_SHIFTER_IMPL(size) \ |
| 206 | inline VEC_DATA_TYPE(int, size) exp_barrel_shifter##size(VEC_DATA_TYPE(int, size) result, int exponent, int fp_multiplier, int k_integer_bits, int k_fractional_bits, VEC_DATA_TYPE(int, size) remainder) \ |
| 207 | { \ |
| 208 | if(k_integer_bits > exponent) \ |
| 209 | { \ |
| 210 | const int k_shift_amount = k_integer_bits > exponent ? k_fractional_bits + exponent : 0; \ |
| 211 | return ASYMM_SELECT_USING_MASK( \ |
| 212 | ASYMM_MASK_IF_NON_ZERO(remainder & (1 << k_shift_amount), size), \ |
| 213 | ASYMM_MULT(result, fp_multiplier, size), result, size); \ |
| 214 | } \ |
| 215 | \ |
| 216 | return result; \ |
| 217 | } |
| 218 | |
| 219 | /** Calculates \f$ exp(x) \f$ for x < 0. |
| 220 | * |
| 221 | * @param[in] size Size of vector. |
| 222 | * |
| 223 | * @return Result in fixed-point format Q0. |
| 224 | */ |
| 225 | #define ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL(size) \ |
| 226 | inline VEC_DATA_TYPE(int, size) asymm_exp_on_negative_values##size(VEC_DATA_TYPE(int, size) a, int k_integer_bits) \ |
| 227 | { \ |
| 228 | const int k_fractional_bits = 31 - k_integer_bits; \ |
| 229 | VEC_DATA_TYPE(int, size) \ |
| 230 | k_one_quarter = 1 << (k_fractional_bits - 2); \ |
| 231 | VEC_DATA_TYPE(int, size) \ |
| 232 | mask = k_one_quarter - 1; \ |
| 233 | VEC_DATA_TYPE(int, size) \ |
| 234 | a_mod_quarter_minus_one_quarter = (a & mask) - k_one_quarter; \ |
| 235 | VEC_DATA_TYPE(int, size) \ |
| 236 | a_mod_quarter_minus_one_quarter_scaled = a_mod_quarter_minus_one_quarter << k_integer_bits; \ |
| 237 | VEC_DATA_TYPE(int, size) \ |
| 238 | result = ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL(a_mod_quarter_minus_one_quarter_scaled, size); \ |
| 239 | VEC_DATA_TYPE(int, size) \ |
| 240 | remainder = a_mod_quarter_minus_one_quarter - a; \ |
| 241 | \ |
| 242 | result = EXP_BARREL_SHIFTER(result, -2, 1672461947, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 243 | result = EXP_BARREL_SHIFTER(result, -1, 1302514674, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 244 | result = EXP_BARREL_SHIFTER(result, +0, 790015084, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 245 | result = EXP_BARREL_SHIFTER(result, +1, 290630308, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 246 | result = EXP_BARREL_SHIFTER(result, +2, 39332535, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 247 | result = EXP_BARREL_SHIFTER(result, +3, 720401, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 248 | result = EXP_BARREL_SHIFTER(result, +4, 242, k_integer_bits, k_fractional_bits, remainder, size); \ |
| 249 | \ |
| 250 | if(k_integer_bits > 5) \ |
| 251 | { \ |
| 252 | const VEC_DATA_TYPE(int, size) clamp = -(1 << (k_fractional_bits + 5)); \ |
| 253 | result = ASYMM_SELECT_USING_MASK(ASYMM_MASK_IF_NON_ZERO(a < clamp, size), 0, result, size); \ |
| 254 | } \ |
| 255 | \ |
| 256 | const VEC_DATA_TYPE(int, size) Q0_one = INT_MAX; \ |
| 257 | return ASYMM_SELECT_USING_MASK(ASYMM_MASK_IF_ZERO(a, size), Q0_one, result, size); \ |
| 258 | } |
| 259 | |
| 260 | /** Calculates the product of a integer value by a power of two, with either a positive exponent |
| 261 | * (equivalent to an arithmetic left shift, saturating) or a negative exponent |
| 262 | * (equivalent to an arithmetic right shift, rounding to nearest). |
| 263 | * |
| 264 | * @param[in] size Size of vector. |
| 265 | * |
| 266 | * @return Arithmetic left or right shift. |
| 267 | */ |
| 268 | #define ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL(size) \ |
| 269 | inline VEC_DATA_TYPE(int, size) asymm_saturating_rounding_mult_by_pow2##size(VEC_DATA_TYPE(int, size) x, int exponent) \ |
| 270 | { \ |
| 271 | if(exponent < 0) \ |
| 272 | { \ |
| 273 | return ASYMM_ROUNDING_DIVIDE_BY_POW2(x, -exponent, size); \ |
| 274 | } \ |
| 275 | \ |
| 276 | const VEC_DATA_TYPE(int, size) min = INT_MIN; \ |
| 277 | const VEC_DATA_TYPE(int, size) max = INT_MAX; \ |
| 278 | int threshold = ((1 << (31 - exponent)) - 1); \ |
| 279 | VEC_DATA_TYPE(int, size) \ |
| 280 | positive_mask = ASYMM_MASK_IF_NON_ZERO(x > threshold, size); \ |
| 281 | VEC_DATA_TYPE(int, size) \ |
| 282 | negative_mask = ASYMM_MASK_IF_NON_ZERO(x < -threshold, size); \ |
| 283 | VEC_DATA_TYPE(int, size) \ |
| 284 | result = x << exponent; \ |
| 285 | result = ASYMM_SELECT_USING_MASK(positive_mask, max, result, size); \ |
| 286 | result = ASYMM_SELECT_USING_MASK(negative_mask, min, result, size); \ |
| 287 | return result; \ |
| 288 | } |
| 289 | |
| 290 | /** Calculates (a+b)/2, rounded to the nearest integer. |
| 291 | * Equivalent to VRHADD in the ARM NEON instruction set. |
| 292 | * |
| 293 | * @param[in] size Size of vector. |
| 294 | * |
| 295 | * @return (a+b)/2, rounded to the nearest integer. |
| 296 | */ |
| 297 | #define ASYMM_ROUNDING_HALF_SUM_IMPL(size) \ |
| 298 | inline VEC_DATA_TYPE(int, size) asymm_rounding_half_sum##size(VEC_DATA_TYPE(int, size) a, VEC_DATA_TYPE(int, size) b) \ |
| 299 | { \ |
| 300 | VEC_DATA_TYPE(long, size) \ |
| 301 | a64 = convert_long##size(a); \ |
| 302 | VEC_DATA_TYPE(long, size) \ |
| 303 | b64 = convert_long##size(b); \ |
| 304 | VEC_DATA_TYPE(long, size) \ |
| 305 | sum = a64 + b64; \ |
| 306 | const VEC_DATA_TYPE(long, size) one = 1; \ |
| 307 | const VEC_DATA_TYPE(long, size) minus_one = -1; \ |
| 308 | VEC_DATA_TYPE(long, size) \ |
| 309 | sign = select(minus_one, one, sum >= 0); \ |
| 310 | return convert_int##size((sum + sign) / 2); \ |
| 311 | } |
| 312 | |
| 313 | /** Calculates \f$ 1 / (1 + x) \f$ for x in (0, 1). |
| 314 | * |
| 315 | * @param[in] size Size of vector. |
| 316 | * |
| 317 | * @return Result in fixed-point format Q0. |
| 318 | */ |
| 319 | #define ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL(size) \ |
| 320 | inline VEC_DATA_TYPE(int, size) asymm_one_over_one_plus_x_for_x_in_0_1##size(VEC_DATA_TYPE(int, size) a) \ |
| 321 | { \ |
| 322 | const VEC_DATA_TYPE(int, size) Q0_one = INT_MAX; \ |
| 323 | const VEC_DATA_TYPE(int, size) Q2_one = 1 << (31 - 2); \ |
| 324 | VEC_DATA_TYPE(int, size) \ |
| 325 | half_denominator = ASYMM_ROUNDING_HALF_SUM(a, Q0_one, size); \ |
| 326 | const VEC_DATA_TYPE(int, size) Q2_48_over_17 = 1515870810; \ |
| 327 | const VEC_DATA_TYPE(int, size) Q2_neg_32_over_17 = -1010580540; \ |
| 328 | VEC_DATA_TYPE(int, size) \ |
| 329 | x = Q2_48_over_17 + ASYMM_MULT(half_denominator, Q2_neg_32_over_17, size); \ |
| 330 | for(int i = 0; i < 3; i++) \ |
| 331 | { \ |
| 332 | VEC_DATA_TYPE(int, size) \ |
| 333 | half_denominator_times_x = ASYMM_MULT(half_denominator, x, size); \ |
| 334 | VEC_DATA_TYPE(int, size) \ |
| 335 | one_minus_half_denominator_times_x = Q2_one - half_denominator_times_x; \ |
| 336 | VEC_DATA_TYPE(int, size) \ |
| 337 | tmp = ASYMM_MULT(x, one_minus_half_denominator_times_x, size); \ |
| 338 | x = x + ASYMM_SATURATING_ROUNDING_MULT_BY_POW2(tmp, 2, size); \ |
| 339 | } \ |
| 340 | return ASYMM_SATURATING_ROUNDING_MULT_BY_POW2(x, 1, size); \ |
| 341 | } |
| 342 | |
| 343 | /** Considering the integer value as fixed-point, change the number of integer bits and update value accordingly. |
| 344 | * |
| 345 | * @param[in] size Size of vector. |
| 346 | * |
| 347 | * @return Rescaled value. |
| 348 | */ |
| 349 | #define ASYMM_RESCALE_IMPL(size) \ |
| 350 | inline VEC_DATA_TYPE(int, size) asymm_rescale##size(VEC_DATA_TYPE(int, size) value, int src_integer_bits, int dst_integer_bits) \ |
| 351 | { \ |
| 352 | int exponent = src_integer_bits - dst_integer_bits; \ |
| 353 | return ASYMM_SATURATING_ROUNDING_MULT_BY_POW2(value, exponent, size); \ |
| 354 | } |
| 355 | |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 356 | #define QUANTIZE_STR(input, offset, scale, type, size) quantize_##type##size(input, offset, scale) |
| 357 | #define QUANTIZE(input, offset, scale, type, size) QUANTIZE_STR(input, offset, scale, type, size) |
| 358 | #define DEQUANTIZE_STR(input, offset, scale, type, size) dequantize_##type##size(input, offset, scale) |
| 359 | #define DEQUANTIZE(input, offset, scale, type, size) DEQUANTIZE_STR(input, offset, scale, type, size) |
| 360 | |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 361 | #define ASYMM_ROUNDING_DIVIDE_BY_POW2(x, exponent, size) asymm_rounding_divide_by_POW2_##size(x, exponent) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 362 | #define ASYMM_MULT(a, b, size) asymm_mult##size(a, b) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 363 | #define ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(x, quantized_multiplier, right_shift, size) \ |
| 364 | ASYMM_ROUNDING_DIVIDE_BY_POW2(ASYMM_MULT(x, quantized_multiplier, size), right_shift, size) |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 365 | #define ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL(a, size) asymm_exp_on_interval_between_negative_one_quarter_and_0_excl##size(a) |
| 366 | #define ASYMM_SELECT_USING_MASK(if_mask, then_val, else_val, size) asymm_select_using_mask##size(if_mask, then_val, else_val) |
| 367 | #define ASYMM_MASK_IF_ZERO(a, size) asymm_mask_if_zero##size(a) |
| 368 | #define ASYMM_MASK_IF_NON_ZERO(a, size) asymm_mask_if_non_zero##size(a) |
| 369 | #define EXP_BARREL_SHIFTER(result, exponent, fp_multiplier, k_integer_bits, k_fractional_bits, remainder, size) exp_barrel_shifter##size(result, exponent, fp_multiplier, k_integer_bits, k_fractional_bits, remainder) |
| 370 | #define ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, size) asymm_exp_on_negative_values##size(a, k_integer_bits) |
| 371 | #define ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1(a, size) asymm_one_over_one_plus_x_for_x_in_0_1##size(a) |
| 372 | #define ASYMM_SATURATING_ROUNDING_MULT_BY_POW2(x, exponent, size) asymm_saturating_rounding_mult_by_pow2##size(x, exponent) |
| 373 | #define ASYMM_ROUNDING_HALF_SUM(a, b, size) asymm_rounding_half_sum##size(a, b) |
| 374 | #define ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, size) asymm_rescale##size(value, src_integer_bits, dst_integer_bits) |
Chunosov | d621bca | 2017-11-03 17:33:15 +0700 | [diff] [blame] | 375 | |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 376 | QUANTIZE_IMPL(uchar, 4) |
| 377 | QUANTIZE_IMPL(ushort, 4) |
| 378 | |
| 379 | DEQUANTIZE_IMPL(uchar, 4) |
| 380 | DEQUANTIZE_IMPL(ushort, 4) |
| 381 | |
Giorgio Arena | b99f00d | 2018-02-14 10:40:16 +0000 | [diff] [blame] | 382 | ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL(2) |
| 383 | ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL(4) |
| 384 | ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL(8) |
| 385 | ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL(16) |
| 386 | |
| 387 | ASYMM_MULT_IMPL(2) |
| 388 | ASYMM_MULT_IMPL(4) |
| 389 | ASYMM_MULT_IMPL(8) |
| 390 | ASYMM_MULT_IMPL(16) |
| 391 | |
| 392 | ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL(2) |
| 393 | ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL(4) |
| 394 | ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL(8) |
| 395 | ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL(16) |
| 396 | |
| 397 | ASYMM_SELECT_USING_MASK_IMPL(2) |
| 398 | ASYMM_SELECT_USING_MASK_IMPL(4) |
| 399 | ASYMM_SELECT_USING_MASK_IMPL(8) |
| 400 | ASYMM_SELECT_USING_MASK_IMPL(16) |
| 401 | |
| 402 | ASYMM_MASK_IF_ZERO_IMPL(2) |
| 403 | ASYMM_MASK_IF_ZERO_IMPL(4) |
| 404 | ASYMM_MASK_IF_ZERO_IMPL(8) |
| 405 | ASYMM_MASK_IF_ZERO_IMPL(16) |
| 406 | |
| 407 | ASYMM_MASK_IF_NON_ZERO_IMPL(2) |
| 408 | ASYMM_MASK_IF_NON_ZERO_IMPL(4) |
| 409 | ASYMM_MASK_IF_NON_ZERO_IMPL(8) |
| 410 | ASYMM_MASK_IF_NON_ZERO_IMPL(16) |
| 411 | |
| 412 | EXP_BARREL_SHIFTER_IMPL(2) |
| 413 | EXP_BARREL_SHIFTER_IMPL(4) |
| 414 | EXP_BARREL_SHIFTER_IMPL(8) |
| 415 | EXP_BARREL_SHIFTER_IMPL(16) |
| 416 | |
| 417 | ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL(2) |
| 418 | ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL(4) |
| 419 | ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL(8) |
| 420 | ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL(16) |
| 421 | |
| 422 | ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL(2) |
| 423 | ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL(4) |
| 424 | ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL(8) |
| 425 | ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL(16) |
| 426 | |
| 427 | ASYMM_ROUNDING_HALF_SUM_IMPL(2) |
| 428 | ASYMM_ROUNDING_HALF_SUM_IMPL(4) |
| 429 | ASYMM_ROUNDING_HALF_SUM_IMPL(8) |
| 430 | ASYMM_ROUNDING_HALF_SUM_IMPL(16) |
| 431 | |
| 432 | ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL(2) |
| 433 | ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL(4) |
| 434 | ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL(8) |
| 435 | ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL(16) |
| 436 | |
| 437 | ASYMM_RESCALE_IMPL(2) |
| 438 | ASYMM_RESCALE_IMPL(4) |
| 439 | ASYMM_RESCALE_IMPL(8) |
| 440 | ASYMM_RESCALE_IMPL(16) |
| 441 | |
Michele Di Giorgio | 4aff98f | 2019-08-28 16:27:26 +0100 | [diff] [blame] | 442 | #endif // ARM_COMPUTE_HELPERS_ASYMM_H |