diff options
author | Giorgio Arena <giorgio.arena@arm.com> | 2021-10-28 15:48:35 +0100 |
---|---|---|
committer | Gunes Bayir <gunes.bayir@arm.com> | 2021-11-02 16:46:00 +0000 |
commit | 3f7414b1f2ae0fb0a25cf410d8264631f6f5c5c9 (patch) | |
tree | 996c8c72c3591a6f64bcb1dee7d792110136c545 /tests/validation/reference/UtilsQuantizedAsymm.h | |
parent | afa19725f7f3feb2c21a6aed02ade49d08e3097b (diff) | |
download | ComputeLibrary-3f7414b1f2ae0fb0a25cf410d8264631f6f5c5c9.tar.gz |
Fix clang issue when casting negative int32_t to int64_t
Resolve COMPMID-4898
Signed-off-by: Giorgio Arena <giorgio.arena@arm.com>
Change-Id: I657e53883c10dc50a59815e527159567315d0aeb
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/370574
Tested-by: bsgcomp <bsgcomp@arm.com>
Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
Comments-Addressed: bsgcomp <bsgcomp@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6546
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Pablo Marquez Tello <pablo.tello@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'tests/validation/reference/UtilsQuantizedAsymm.h')
-rw-r--r-- | tests/validation/reference/UtilsQuantizedAsymm.h | 28 |
1 files 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<int64_t>(val) | ((val < 0) ? (((1ll << 32) - 1) << 32) : 0); +} +#else // __clang__ +inline int64_t to_int64(int32_t val) +{ + return static_cast<int64_t>(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<int32_t>::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<int32_t>((ab_64 + nudge) / (1ll << 31)); + const bool overflow = a == b && a == std::numeric_limits<int32_t>::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<int32_t>((ab_64 + nudge) / (1ll << 31)); return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32; } |