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;
             });
diff --git a/verif/generator/tosa_arg_gen.py b/verif/generator/tosa_arg_gen.py
index 2181735..2596bec 100644
--- a/verif/generator/tosa_arg_gen.py
+++ b/verif/generator/tosa_arg_gen.py
@@ -1879,7 +1879,16 @@
             table = np.int32(
                 testGen.rng.integers(low=-32768, high=32768, size=[513])
             ).tolist()
-
+            # Make sure all slopes are within REQUIRE min/max 16-bit int
+            for idx in range(len(table) - 1):
+                slope = table[idx + 1] - table[idx]
+                # Alter the next table entry to force the slope to be ok
+                if slope > 32767:
+                    table[idx + 1] -= slope - 32767
+                if slope < -32768:
+                    table[idx + 1] -= slope + 32768
+                slope = table[idx + 1] - table[idx]
+                assert slope <= 32767 and slope >= -32768
         arg_list.append(
             (
                 "",