diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2022-03-23 15:32:34 +0000 |
---|---|---|
committer | Jeremy Johnson <jeremy.johnson@arm.com> | 2022-03-24 09:13:35 +0000 |
commit | 81ee53d65a6e3e7d454eda967e6f9f157cae69f1 (patch) | |
tree | a35d19a9fb64345f561277880fe476a2491e6dcb /reference_model | |
parent | 25669b31bae45b16d4e96ec13fa9cdeb417975f6 (diff) | |
download | reference_model-81ee53d65a6e3e7d454eda967e6f9f157cae69f1.tar.gz |
Add missing REQUIRE to NEGATE op
And update test generation to create values in predictable range
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: I4ba1ff445bf6caeec9f8782902fc45929fe0ee77
Diffstat (limited to 'reference_model')
-rw-r--r-- | reference_model/src/ops/ewise_unary.cc | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/reference_model/src/ops/ewise_unary.cc b/reference_model/src/ops/ewise_unary.cc index 13e517b..0f38056 100644 --- a/reference_model/src/ops/ewise_unary.cc +++ b/reference_model/src/ops/ewise_unary.cc @@ -229,15 +229,30 @@ int OpNegate<Rank, Dtype>::register_fcn() break; case DType_INT16: case DType_INT32: - this->fcn = [](InEigenType a) -> OutEigenType { - InEigenType result = -(a); - return result; + this->fcn = [this](InEigenType a) -> OutEigenType { + int64_t res_in_64 = 0L - a; + int64_t max_in_64, min_in_64; + if (Dtype == DType_INT16) { + max_in_64 = static_cast<int64_t>(std::numeric_limits<int16_t>::max()); + min_in_64 = static_cast<int64_t>(std::numeric_limits<int16_t>::min()); + } + else + { + max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max()); + min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min()); + } + REQUIRE(res_in_64 <= max_in_64 && res_in_64 >= min_in_64, "OpNegate: result not in input type range"); + return static_cast<InEigenType>(res_in_64); }; break; case DType_INT8: this->fcn = [this](InEigenType a) -> OutEigenType { - InEigenType result = -(a - this->qinfo->input_zp()) + this->qinfo->output_zp(); - result = std::min(std::max(result, static_cast<InEigenType>(QMin)), static_cast<InEigenType>(QMax)); + int32_t res_in_32 = 0 - (a - this->qinfo->input_zp()); + int32_t max_in_32 = static_cast<int32_t>(std::numeric_limits<int8_t>::max()); + int32_t min_in_32 = static_cast<int32_t>(std::numeric_limits<int8_t>::min()); + REQUIRE(res_in_32 <= max_in_32 && res_in_32 >= min_in_32, "OpNegate: result not in i8 range"); + res_in_32 += this->qinfo->output_zp(); + InEigenType result = static_cast<InEigenType>(std::min(std::max(res_in_32, static_cast<int32_t>(QMin)), static_cast<int32_t>(QMax))); return result; }; break; |