diff options
-rw-r--r-- | reference_model/src/ops/ewise_binary.cc | 8 | ||||
-rw-r--r-- | verif/generator/tosa_arg_gen.py | 11 |
2 files changed, 16 insertions, 3 deletions
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 @@ int OpTable<Rank, InDtype>::eval() 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 @@ class TosaArgGen: 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( ( "", |