Enabled 16-bit TABLE REQUIRE statement
Signed-off-by: Jerry Ge <jerry.ge@arm.com>
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: Ib6e81814e022f33e45430e47ca99d6d9f9e0e101
diff --git a/reference_model/src/ops/ewise_binary.cc b/reference_model/src/ops/ewise_binary.cc
index eadefaa..a5e1a20 100644
--- a/reference_model/src/ops/ewise_binary.cc
+++ b/reference_model/src/ops/ewise_binary.cc
@@ -554,10 +554,14 @@
index = std::min<int32_t>(std::max<int32_t>(index, 0), NumTableEntries - 1); // 9-bit index
int32_t frac = (input_truncated)&0x7F; // 7-bit fraction
- // 3. interpolate, generate 16.7 (23-bit) output
+ // 3. Add REQUIRE CHECK for extreme large/small slopes
int32_t base = table[index];
int32_t next = table[index + 1];
- int32_t value = (base << 7) + (next - base) * frac;
+ int32_t slope = next - base;
+ REQUIRE(slope <= std::numeric_limits<int16_t>::max() && slope >= std::numeric_limits<int16_t>::min(), "OpTable: slope out of int16_t range");
+
+ // 4. interpolate, generate 16.7 (23-bit) output
+ int32_t value = (base << 7) + (slope) * frac;
return value;
});