Lines Matching +full:signed +full:- +full:integer +full:- +full:overflow
6 // This source code is licensed under the BSD-style license found in the
14 #include <xnnpack/requantization-stubs.h>
28 assert(scale >= 0x1.0p-32f); in xnn_qs8_requantize_gemmlowp__scalar()
39 const int32_t shift = 127 + 31 - 32 - (float_as_uint32(scale) >> 23); in xnn_qs8_requantize_gemmlowp__scalar()
44 const int32_t remainder_mask = (int32_t)((UINT32_C(1) << shift) - UINT32_C(1)); in xnn_qs8_requantize_gemmlowp__scalar()
46 const int32_t smin = (int32_t) qmin - (int32_t) zero_point; in xnn_qs8_requantize_gemmlowp__scalar()
47 const int32_t smax = (int32_t) qmax - (int32_t) zero_point; in xnn_qs8_requantize_gemmlowp__scalar()
48 for (; n != 0; n -= 4) { in xnn_qs8_requantize_gemmlowp__scalar()
55 // Compute full 64-bit product of signed 32-bit factors. in xnn_qs8_requantize_gemmlowp__scalar()
57 // Note: multiplier can be treated as either signed or unsigned. in xnn_qs8_requantize_gemmlowp__scalar()
63 // Get the Q31 multiplication result by extracting bits 31-62 of the product, with rounding up. in xnn_qs8_requantize_gemmlowp__scalar()
64 …// Add rounding value (0x40000000) and then shift right by 31 bits and extract the low 32-bit word. in xnn_qs8_requantize_gemmlowp__scalar()
66 …// Given the multiplier range, the result of Q31 multiplication is in [-2147483520, 2147483519] ra… in xnn_qs8_requantize_gemmlowp__scalar()
73 // Rounding is performed towards closest integer, with midpoints rounded away from zero. in xnn_qs8_requantize_gemmlowp__scalar()
75 …// Shift with correct rounding could be efficiently implemented by pre-adding rounding constant, b… in xnn_qs8_requantize_gemmlowp__scalar()
76 …// [-2147483520, 2147483519] range and rounding constant up to 2**30 we can't rule out overflow. T… in xnn_qs8_requantize_gemmlowp__scalar()
78 …// 1. Extend input to 64-bit signed integer, perform addition and shift on 64-bit integers, then t… in xnn_qs8_requantize_gemmlowp__scalar()
80 …// 2. Detect overflow and handle this situation separately. Note that overflow is possible only wh… in xnn_qs8_requantize_gemmlowp__scalar()
81 …// positive, and even when addition of a rounding constant overflows 32-bit signed integer, it … in xnn_qs8_requantize_gemmlowp__scalar()
82 …// overflow 32-bit unsigned integer. Thus, in case of signed overflow, we can compute the resul… in xnn_qs8_requantize_gemmlowp__scalar()
86 …// - input is positive, shift is non-zero, and remainder >= 2**(shift - 1), e.g. 10 >> 2 needs… in xnn_qs8_requantize_gemmlowp__scalar()
87 …// - input is negative, shift is non-zero, and remainder > 2**(shift - 1), e.g. -10 >> 2 doesn… in xnn_qs8_requantize_gemmlowp__scalar()
89 // remainder + (input <= 0) > 2**(shift - 1) in xnn_qs8_requantize_gemmlowp__scalar()
91 // remainder - (input < 0) > ((2**shift - 1) >> 1) in xnn_qs8_requantize_gemmlowp__scalar()
94 …ptions, option 3 is the most performant across the board, although option 1 is promising for 64-bit in xnn_qs8_requantize_gemmlowp__scalar()
96 const int32_t x_remainder = (x_q31product & remainder_mask) - (int32_t) (x_q31product < 0); in xnn_qs8_requantize_gemmlowp__scalar()
97 const int32_t y_remainder = (y_q31product & remainder_mask) - (int32_t) (y_q31product < 0); in xnn_qs8_requantize_gemmlowp__scalar()
98 const int32_t z_remainder = (z_q31product & remainder_mask) - (int32_t) (z_q31product < 0); in xnn_qs8_requantize_gemmlowp__scalar()
99 const int32_t w_remainder = (w_q31product & remainder_mask) - (int32_t) (w_q31product < 0); in xnn_qs8_requantize_gemmlowp__scalar()
106 // Clamp scaled value with zero point between (qmin - zero point) and (qmax - zero point). in xnn_qs8_requantize_gemmlowp__scalar()
115 …// This addition can be safely done before clamping, because scaled values are in [-2147483520, 21… in xnn_qs8_requantize_gemmlowp__scalar()
116 … range, so addition of zero point (which is in [-128, 127] range) can not overflow signed 32-bit i… in xnn_qs8_requantize_gemmlowp__scalar()