diff options
author | Kevin Cheng <kevin.cheng@arm.com> | 2021-06-29 15:32:19 -0700 |
---|---|---|
committer | Kevin Cheng <kevin.cheng@arm.com> | 2021-08-20 18:07:06 +0100 |
commit | acb550f4410ae861e53cae27a9feb4b11d45769f (patch) | |
tree | ae2f4ec558c2cdf1afa020b80a09d7ab4be5ef6d /reference_model/src/quant_util.h | |
parent | 68e7aee65bda5ac03fa7def753b7dc7462554793 (diff) | |
download | reference_model-acb550f4410ae861e53cae27a9feb4b11d45769f.tar.gz |
Replace node level check ASSERT_MSG_NODE()/FATAL_ERROR_NODE() with REQUIRE() or ERROR_IF()
- Adding return code enum class: {VALID, UNPREDICTABLE, ERROR}
- Runtime errors (e.g. memory allocation failure) will abort immediately, or will return one of the three return codes
Part of the codes are re-written to pass REQUIRE() to the top-level (e.g. apply_scale_32/16())
- Update setExpectedFailure() to setExpectedReturnCode() on test generation script
- Update test regression script to interface with reference model change
Signed-off-by: Kevin Cheng <kevin.cheng@arm.com>
Change-Id: Ia063c936bcb2a54d6e379a5bb6801aa72d1186f1
Diffstat (limited to 'reference_model/src/quant_util.h')
-rw-r--r-- | reference_model/src/quant_util.h | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/reference_model/src/quant_util.h b/reference_model/src/quant_util.h index c595869..4f6a525 100644 --- a/reference_model/src/quant_util.h +++ b/reference_model/src/quant_util.h @@ -44,9 +44,17 @@ public: static int32_t apply_scale_32(int32_t value, int32_t multiplier, int32_t shift, bool double_round = true) { - ASSERT_MSG(multiplier >= 0, "apply_scale_32() error: multiplier should >= 0 but is %d", multiplier); - ASSERT_MSG(shift >= 2 && shift <= 62, "apply_scale_32() error: shift should be within [2, 62] but is %d", - shift); + if (multiplier < 0) + { + std::string desc = "apply_scale_32() error: multiplier should >= 0 but is " + std::to_string(multiplier); + throw desc; + } + if (shift < 2 || shift > 62) + { + std::string desc = + "apply_scale_32(): shift value should stay within [2, 62] but is " + std::to_string(shift); + throw desc; + } int64_t round = 1L << (shift - 1); if (double_round) { @@ -57,21 +65,35 @@ public: } int64_t result = (int64_t)value * multiplier + round; result = result >> shift; - ASSERT_MSG(result >= -(1L << 31) && result < (1L << 31), - "apply_scale_32() error: scaled result exceed int32 numeric range"); + if (result < -(1L << 31) || result >= (1L << 31)) + { + std::string desc = "apply_scale_32() error: scaled result exceeds int32 numeric range"; + throw desc; + } return static_cast<int32_t>(result); } static int32_t apply_scale_16(int64_t value, int16_t multiplier, int32_t shift) { - ASSERT_MSG(multiplier >= 0, "apply_scale_16() error: multiplier should >= 0 but is %d", multiplier); - ASSERT_MSG(shift >= 2 && shift <= 62, "apply_scale_16() error: shift should be within [2, 62] but is %d", - shift); + if (multiplier < 0) + { + std::string desc = "apply_scale_16() error: multiplier should >= 0 but is " + std::to_string(multiplier); + throw desc; + } + if (shift < 2 || shift > 62) + { + std::string desc = + "apply_scale_16(): shift value should stay within [2, 62] but is " + std::to_string(shift); + throw desc; + } int64_t round = 1L << (shift - 1); int64_t result = value * (int64_t)multiplier + round; result = result >> shift; - ASSERT_MSG(result >= -(1L << 31) && result < (1L << 31), - "apply_scale_16() error: scaled result exceed int32 numeric range"); + if (result < -(1L << 31) || result >= (1L << 31)) + { + std::string desc = "apply_scale_16() error: scaled result exceeds int32 numeric range"; + throw desc; + } return static_cast<int32_t>(result); } }; |