From 3f7414b1f2ae0fb0a25cf410d8264631f6f5c5c9 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Thu, 28 Oct 2021 15:48:35 +0100 Subject: Fix clang issue when casting negative int32_t to int64_t Resolve COMPMID-4898 Signed-off-by: Giorgio Arena Change-Id: I657e53883c10dc50a59815e527159567315d0aeb Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/370574 Tested-by: bsgcomp Reviewed-by: Gunes Bayir Comments-Addressed: bsgcomp Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6546 Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez Tello Comments-Addressed: Arm Jenkins --- tests/validation/reference/UtilsQuantizedAsymm.h | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tests/validation/reference/UtilsQuantizedAsymm.h b/tests/validation/reference/UtilsQuantizedAsymm.h index 1f593bb696..e5ecc66545 100644 --- a/tests/validation/reference/UtilsQuantizedAsymm.h +++ b/tests/validation/reference/UtilsQuantizedAsymm.h @@ -32,6 +32,22 @@ namespace test { namespace validation { +namespace +{ +#if __clang__ +// This has been tested on clang 7.0.2 (__clang_major__ == 7 && __clang_minor__ == 0 && __clang_patchlevel__ == 2) +inline int64_t to_int64(int32_t val) +{ + return static_cast(val) | ((val < 0) ? (((1ll << 32) - 1) << 32) : 0); +} +#else // __clang__ +inline int64_t to_int64(int32_t val) +{ + return static_cast(val); +} +#endif // __clang__ +} // namespace + /** Rounded to nearest division by a power-of-two. */ inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent) { @@ -43,12 +59,12 @@ inline int32_t asymm_rounding_divide_by_pow2(int32_t x, int exponent) /** Multiplication of two integers. The same as ARMv7 Arm® Neon™ VQRDMULH instruction. */ inline int32_t asymm_int_mult(int32_t a, int32_t b) { - bool overflow = a == b && a == std::numeric_limits::min(); - int64_t a_64(a); - int64_t b_64(b); - int64_t ab_64 = a_64 * b_64; - int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); - int32_t ab_x2_high32 = static_cast((ab_64 + nudge) / (1ll << 31)); + const bool overflow = a == b && a == std::numeric_limits::min(); + const int64_t a_64 = to_int64(a); + const int64_t b_64 = to_int64(b); + const int64_t ab_64 = a_64 * b_64; + const int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); + const int32_t ab_x2_high32 = static_cast((ab_64 + nudge) / (1ll << 31)); return overflow ? std::numeric_limits::max() : ab_x2_high32; } -- cgit v1.2.1