blob: f66d3e7064ba26d1810ae0b99a1bd186902c3ef5 [file] [log] [blame]
Chunosovd621bca2017-11-03 17:33:15 +07001/*
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +01002 * Copyright (c) 2017-2023 Arm Limited.
Chunosovd621bca2017-11-03 17:33:15 +07003 *
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#include "arm_compute/core/utils/quantization/AsymmHelpers.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010025
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +010026#include "arm_compute/core/Helpers.h"
SiCong Li91295492023-07-21 18:16:13 +010027#include "arm_compute/function_info/ActivationLayerInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Viet-Hoa Doa62129a2023-04-26 15:38:45 +010029#include "src/core/utils/quantization/AsymmHelpers.h"
SiCong Li91295492023-07-21 18:16:13 +010030#include "support/ToolchainSupport.h"
Chunosovd621bca2017-11-03 17:33:15 +070031
32#include <cmath>
33#include <limits>
34#include <numeric>
35
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +010036namespace arm_compute
37{
38namespace quantization
39{
Michalis Spyrou299fdd32019-05-01 13:03:59 +010040constexpr int64_t fixed_point_one_Q0 = (1LL << 31);
Gian Marco Iodice3139f032018-11-05 14:26:32 +000041constexpr float epsilon = 0.00001f;
Chunosovf450caa2017-11-08 16:09:35 +070042
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010043Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon)
Manuel Bottini07263982019-10-17 18:37:26 +010044{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010045 if (multiplier >= 1.f)
Manuel Bottini07263982019-10-17 18:37:26 +010046 {
47 Status status = calculate_quantized_multiplier_greater_than_one(multiplier, quant_multiplier, shift);
48 *shift *= -1;
49 return status;
50 }
51 else
52 {
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010053 return calculate_quantized_multiplier_less_than_one(multiplier, quant_multiplier, shift, ignore_epsilon);
Manuel Bottini07263982019-10-17 18:37:26 +010054 }
55}
56
Michalis Spyroue7be8a02019-12-12 16:16:09 +000057Status calculate_quantized_multiplier_less_than_one(float multiplier,
58 int32_t *quant_multiplier,
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010059 int32_t *right_shift,
60 bool ignore_epsilon)
Chunosovd621bca2017-11-03 17:33:15 +070061{
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010062 const float internal_epsilon = ignore_epsilon ? 0.0f : epsilon;
63
Chunosovd621bca2017-11-03 17:33:15 +070064 ARM_COMPUTE_RETURN_ERROR_ON(quant_multiplier == nullptr);
65 ARM_COMPUTE_RETURN_ERROR_ON(right_shift == nullptr);
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010066 ARM_COMPUTE_RETURN_ERROR_ON(multiplier < -internal_epsilon);
67 ARM_COMPUTE_RETURN_ERROR_ON(multiplier > 1.0f + internal_epsilon);
Gian Marco Iodice3139f032018-11-05 14:26:32 +000068
Michalis Spyroue7be8a02019-12-12 16:16:09 +000069 int shift_exp = 0;
70 const double q = std::frexp(multiplier, &shift_exp);
71 *right_shift = -1 * shift_exp;
72 auto q_fixed = static_cast<int64_t>(support::cpp11::round(q * fixed_point_one_Q0));
Chunosovf450caa2017-11-08 16:09:35 +070073 ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > fixed_point_one_Q0);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010074 if (q_fixed == fixed_point_one_Q0)
Chunosovd621bca2017-11-03 17:33:15 +070075 {
76 q_fixed /= 2;
77 --*right_shift;
78 }
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010079
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 if (ignore_epsilon && *right_shift > 31)
Sang-Hoon Park30b46a62020-04-18 01:40:57 +010081 {
82 *right_shift = 0;
83 q_fixed = 0;
84 }
85
Chunosovd621bca2017-11-03 17:33:15 +070086 ARM_COMPUTE_RETURN_ERROR_ON(*right_shift < 0);
87 ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > std::numeric_limits<int32_t>::max());
Chunosovf450caa2017-11-08 16:09:35 +070088 *quant_multiplier = static_cast<int32_t>(q_fixed);
Chunosovd621bca2017-11-03 17:33:15 +070089
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +010090 return Status{};
Chunosovf450caa2017-11-08 16:09:35 +070091}
92
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010093Status
94calculate_quantized_multiplier_greater_than_one(float multiplier, int32_t *quantized_multiplier, int32_t *left_shift)
Chunosovf450caa2017-11-08 16:09:35 +070095{
96 ARM_COMPUTE_RETURN_ERROR_ON(quantized_multiplier == nullptr);
97 ARM_COMPUTE_RETURN_ERROR_ON(left_shift == nullptr);
98 ARM_COMPUTE_RETURN_ERROR_ON(multiplier < 1.f);
Michalis Spyroue7be8a02019-12-12 16:16:09 +000099
100 int shift_exp = 0;
101 const double q = std::frexp(multiplier, &shift_exp);
102 *left_shift = shift_exp;
103 auto q_fixed = static_cast<int64_t>(support::cpp11::round(q * fixed_point_one_Q0));
Chunosovf450caa2017-11-08 16:09:35 +0700104 ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > fixed_point_one_Q0);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100105 if (q_fixed == fixed_point_one_Q0)
Chunosovf450caa2017-11-08 16:09:35 +0700106 {
107 q_fixed /= 2;
108 ++*left_shift;
109 }
110 ARM_COMPUTE_RETURN_ERROR_ON(*left_shift < 0);
111 ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > std::numeric_limits<int32_t>::max());
112 *quantized_multiplier = static_cast<int32_t>(q_fixed);
113
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100114 return Status{};
Chunosovf450caa2017-11-08 16:09:35 +0700115}
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +0100116
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100117arm_compute::Status calculate_quantized_multipliers(const QuantizationInfo &iq_info,
118 const QuantizationInfo &wq_info,
119 const QuantizationInfo &oq_info,
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +0000120 GEMMLowpOutputStageInfo &stage_info)
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +0100121{
122 ARM_COMPUTE_RETURN_ERROR_ON(iq_info.scale().empty());
123 ARM_COMPUTE_RETURN_ERROR_ON(wq_info.scale().empty());
124 ARM_COMPUTE_RETURN_ERROR_ON(oq_info.scale().empty());
125
126 const unsigned int size = wq_info.scale().size();
127
128 auto &quant_multipliers = stage_info.gemmlowp_multipliers;
129 auto &quant_shifts = stage_info.gemmlowp_shifts;
130 quant_multipliers.resize(size);
131 quant_shifts.resize(size);
132
133 const auto &w_scales = wq_info.scale();
134 const float i_scale = iq_info.scale().at(0);
135 const float o_scale = oq_info.scale().at(0);
136
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100137 for (unsigned int i = 0; i < size; ++i)
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +0100138 {
139 const float multiplier = i_scale * w_scales[i] / o_scale;
Michalis Spyroue7be8a02019-12-12 16:16:09 +0000140 int32_t quant_multiplier = 0;
141 int32_t quant_shift = 0;
Michele Di Giorgiof29d1b72019-10-29 10:58:13 +0000142 ARM_COMPUTE_RETURN_ON_ERROR(calculate_quantized_multiplier(multiplier, &quant_multiplier, &quant_shift));
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +0100143 quant_multipliers[i] = quant_multiplier;
144 quant_shifts[i] = quant_shift;
145 }
146
147 // Legacy part
148 stage_info.gemmlowp_shift = quant_shifts[0];
149 stage_info.gemmlowp_multiplier = quant_multipliers[0];
150
151 return Status{};
152}
153
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100154std::pair<int, int> get_min_max_values_from_quantized_data_type(DataType data_type)
155{
156 int min_quant_val = 0;
157 int max_quant_val = 0;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100158 switch (data_type)
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100159 {
160 case DataType::QASYMM8:
161 min_quant_val = std::numeric_limits<uint8_t>::min();
162 max_quant_val = std::numeric_limits<uint8_t>::max();
163 break;
164 case DataType::QSYMM8:
Manuel Bottini8481d832019-12-10 15:28:40 +0000165 case DataType::QASYMM8_SIGNED:
Michele Di Giorgiod87a7b22019-09-10 10:42:27 +0100166 min_quant_val = std::numeric_limits<int8_t>::min();
167 max_quant_val = std::numeric_limits<int8_t>::max();
168 break;
169 case DataType::QASYMM16:
170 min_quant_val = std::numeric_limits<uint16_t>::min();
171 max_quant_val = std::numeric_limits<uint16_t>::max();
172 break;
173 case DataType::QSYMM16:
174 min_quant_val = std::numeric_limits<int16_t>::min();
175 max_quant_val = std::numeric_limits<int16_t>::max();
176 break;
177 default:
178 ARM_COMPUTE_ERROR("Unsupported data type");
179 }
180 return std::make_pair(min_quant_val, max_quant_val);
181}
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100182
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100183std::tuple<int32_t, int32_t> get_quantized_asymmetric_output_min_max(const QuantizationInfo &q_info,
184 const ActivationLayerInfo &act_info,
185 DataType data_type)
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100186{
Viet-Hoa Doa62129a2023-04-26 15:38:45 +0100187 ARM_COMPUTE_ERROR_ON(data_type != DataType::QASYMM8 && data_type != DataType::QASYMM8_SIGNED);
188
189 const auto min_max = get_min_max(data_type);
190
191 int32_t type_min = std::get<0>(min_max).get<int32_t>();
192 int32_t type_max = std::get<1>(min_max).get<int32_t>();
193
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100194 const UniformQuantizationInfo q_unif = q_info.uniform();
195
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100196 if (act_info.enabled())
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100197 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100198 switch (act_info.activation())
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100199 {
200 case ActivationLayerInfo::ActivationFunction::RELU:
Viet-Hoa Doa62129a2023-04-26 15:38:45 +0100201 type_min = q_unif.offset;
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100202 break;
203 case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
Viet-Hoa Doa62129a2023-04-26 15:38:45 +0100204 type_min = q_unif.offset;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100205 type_max = (data_type == DataType::QASYMM8) ? quantize_qasymm8(act_info.a(), q_info)
206 : quantize_qasymm8_signed(act_info.a(), q_info);
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100207 break;
208 case ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100209 type_min = (data_type == DataType::QASYMM8) ? quantize_qasymm8(act_info.b(), q_info)
210 : quantize_qasymm8_signed(act_info.b(), q_info);
211 type_max = (data_type == DataType::QASYMM8) ? quantize_qasymm8(act_info.a(), q_info)
212 : quantize_qasymm8_signed(act_info.a(), q_info);
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100213 break;
214 default:
215 ARM_COMPUTE_ERROR("Activation function not supported.");
216 break;
217 }
218 }
219
Viet-Hoa Doa62129a2023-04-26 15:38:45 +0100220 return std::make_tuple(type_min, type_max);
Viet-Hoa Do9c7c2d22023-04-11 17:16:27 +0100221}
222
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000223void compute_quantized_multipliers_and_shifts(const ITensorInfo *input,
224 const ITensorInfo *weights,
225 const ITensorInfo *output,
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000226 int32_t *output_multipliers_ptr,
227 int32_t *output_shifts_ptr)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100228{
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000229 const UniformQuantizationInfo iq_info = input->quantization_info().uniform();
230 const QuantizationInfo wq_info = weights->quantization_info();
231 const UniformQuantizationInfo oq_info = output->quantization_info().uniform();
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100232
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +0000233 const unsigned int num_filters = wq_info.scale().size();
234
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100235 for (unsigned int i = 0; i < num_filters; ++i)
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100236 {
Michalis Spyroue7be8a02019-12-12 16:16:09 +0000237 int32_t output_multiplier = 0;
238 int32_t output_shift = 0;
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100239 const float multiplier = iq_info.scale * wq_info.scale()[i] / oq_info.scale;
Michele Di Giorgio14cbfb22019-10-23 10:53:10 +0100240 calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
Michele Di Giorgiodf4cf572019-10-09 15:32:39 +0100241
242 output_multipliers_ptr[i] = output_multiplier;
243 output_shifts_ptr[i] = output_shift;
244 }
245}
Sang-Hoon Park396cb952020-03-26 14:02:37 +0000246
247int32_t saturating_rounding_doubling_highmul(int32_t a, int32_t b)
248{
SiCong Li91295492023-07-21 18:16:13 +0100249 bool overflow = a == b && a == std::numeric_limits<int32_t>::min();
250 int64_t a_64(a);
251 int64_t b_64(b);
252 int64_t ab_64 = a_64 * b_64;
253 const bool is_positive_or_zero =
254 a == 0 || b == 0 || (std::signbit(static_cast<double>(a)) == std::signbit(static_cast<double>(b)));
255 int32_t nudge = is_positive_or_zero ? (1 << 30) : (1 - (1 << 30));
256 int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31));
Sang-Hoon Park396cb952020-03-26 14:02:37 +0000257 return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32;
258}
259
260inline int32_t rounding_divide_by_pow2(int32_t x, int exponent)
261{
262 const int32_t mask = (1 << exponent) - 1;
263 const int32_t threshold = (mask >> 1) + (x < 0 ? 1 : 0);
264 return (x >> exponent) + ((x & mask) > threshold ? 1 : 0);
265}
266
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000267int32_t multiply_by_quantized_multiplier(int32_t input, int32_t qmul, int32_t shift)
Sang-Hoon Park396cb952020-03-26 14:02:37 +0000268{
269 const auto left_shift = shift > 0 ? shift : 0;
270 const auto right_shift = shift > 0 ? 0 : -shift;
271 return rounding_divide_by_pow2(saturating_rounding_doubling_highmul(input * (1 << left_shift), qmul), right_shift);
272}
273
274int32_t saturating_rounding_multiply_by_pow2(int32_t exponent, int32_t v)
275{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100276 if (exponent == 0)
Sang-Hoon Park396cb952020-03-26 14:02:37 +0000277 {
278 return v;
279 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100280 else if (exponent < 0)
Sang-Hoon Park396cb952020-03-26 14:02:37 +0000281 {
282 return rounding_divide_by_pow2(v, -exponent);
283 }
284 else
285 {
286 constexpr auto min = std::numeric_limits<int32_t>::min();
287 constexpr auto max = std::numeric_limits<int32_t>::max();
288 const auto width = sizeof(int32_t) * 8;
289
290 const int32_t threshold = ((1 << (width - 1 - exponent)) - 1);
291 bool pos_mask = v > threshold;
292 bool neg_mask = v < -threshold;
293 int32_t result = v << exponent;
294 result = pos_mask ? max : result;
295 result = neg_mask ? min : result;
296 return result;
297 }
298}
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000299
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100300void get_invsqrt_quantized_multiplier_exp(int32_t input,
301 int32_t reverse_shift,
302 int32_t &output_inv_sqrt,
303 int32_t &output_shift)
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000304{
305 ARM_COMPUTE_ERROR_ON(input < 0);
306
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100307 if (input <= 1)
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000308 {
309 // dealing the inputs (0 and 1) separately to avoid overflow
310 output_inv_sqrt = std::numeric_limits<std::int32_t>::max();
311 output_shift = 0;
312 return;
313 }
314
315 // prepare input for fixed point operation and compute shift value
316 output_shift = 11;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100317 while (input >= (1 << 29))
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000318 {
319 input /= 4;
320 ++output_shift;
321 }
322
323 const uint32_t max_left_shift_bits = __builtin_clz(static_cast<uint32_t>(input)) - 1;
324 const uint32_t max_left_shift_bits_pairs = max_left_shift_bits / 2;
325 const uint32_t left_shift_bit_pairs = max_left_shift_bits_pairs - 1;
326 output_shift -= left_shift_bit_pairs;
327 input <<= 2 * left_shift_bit_pairs;
328
329 // Calculation in fixed point domain with 3 integer bits.
330 using FixedPointRawType = int32_t;
331 constexpr uint32_t fixedpoint_position = 3;
332 constexpr uint32_t fixedpoint_int_position = sizeof(FixedPointRawType) * 8 - 1 - fixedpoint_position;
333 using FixedPoint3 = FixedPointRawType;
334 using FixedPoint0 = FixedPointRawType;
335
336 // fixed point representation of input divided by 2 and 1.5 for Newton-Raphson iteration
337 const FixedPoint3 fixedpoint_input = (input >> 1);
338 const FixedPoint3 fixedpoint_half_input = rounding_divide_by_pow2(fixedpoint_input, 1);
339 const FixedPoint3 fixedpoint_half_three = (0x1 << fixedpoint_int_position) + (0x1 << (fixedpoint_int_position - 1));
340
341 // initial guess (1) in fixed point representation
342 FixedPoint3 x = 0x1 << fixedpoint_int_position;
343
344 // multiplication of two fixed point numbers, defined for readability
345 auto fixed_point_mul = [](FixedPointRawType a, FixedPointRawType b) -> FixedPointRawType
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100346 { return saturating_rounding_doubling_highmul(a, b); };
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000347
348 // rescaling of fixed point to have dst_bit integer bits, defined for readability
349 auto fixed_point_rescale = [](FixedPointRawType a, uint32_t src_bit, uint32_t dst_bit) -> FixedPointRawType
350 {
351 const uint32_t exponent = src_bit - dst_bit;
352 return saturating_rounding_multiply_by_pow2(exponent, a);
353 };
354
355 // 5 iterations of Newton-Raphson method for inverse square root - 1.5 * x_n = input/2 * (x_n)^3
356 constexpr int32_t num_iteration = 5;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100357 for (int32_t i = 0; i < num_iteration; ++i)
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000358 {
359 const auto x3 = fixed_point_rescale(fixed_point_mul(fixed_point_mul(x, x), x), 9, fixedpoint_position);
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100360 x = fixed_point_rescale(fixed_point_mul(fixedpoint_half_three, x) - fixed_point_mul(fixedpoint_half_input, x3),
361 6, fixedpoint_position);
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000362 }
363
364 // fixed point representation of sqrt(1/2)
365 const FixedPoint0 fixedpoint_half_sqrt_2 = 1518500250;
366 x = fixed_point_mul(fixedpoint_half_sqrt_2, x);
367 output_inv_sqrt = x;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100368 if (output_shift < 0)
Sang-Hoon Park0d008f72020-03-13 14:56:05 +0000369 {
370 output_inv_sqrt <<= -output_shift;
371 output_shift = 0;
372 }
373 // convert right shift to left shift
374 output_shift *= reverse_shift;
375}
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100376} // namespace quantization
377} // namespace arm_compute