24 #ifndef ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H
25 #define ARM_COMPUTE_TEST_VALIDATION_UTILS_QUANTIZED_ASYMM_H
39 inline int64_t to_int64(int32_t val)
41 return static_cast<int64_t
>(val) | ((val < 0) ? (((1ll << 32) - 1) << 32) : 0);
44 inline int64_t to_int64(int32_t val)
46 return static_cast<int64_t
>(val);
54 const int32_t mask = (1 << exponent) - 1;
55 const int32_t threshold = (mask >> 1) + (x < 0 ? 1 : 0);
56 return (x >> exponent) + ((x & mask) > threshold ? 1 : 0);
62 const bool overflow = a ==
b && a == std::numeric_limits<int32_t>::min();
63 const int64_t a_64 = to_int64(a);
64 const int64_t b_64 = to_int64(
b);
65 const int64_t ab_64 = a_64 * b_64;
66 const int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30));
67 const int32_t ab_x2_high32 =
static_cast<int32_t
>((ab_64 + nudge) / (1ll << 31));
68 return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32;
73 int32_t result_offset_after_shift, int32_t min, int32_t max)
78 res =
asymm_int_mult(val * (1 << (-result_shift)), result_mult_int);
84 res += result_offset_after_shift;
85 res = utility::clamp<int32_t>(res, min, max);