From d511f9e604c3e2b915d6f6b7a4975b23ac06041d Mon Sep 17 00:00:00 2001 From: Jerry Ge Date: Fri, 12 Aug 2022 16:12:40 -0700 Subject: Enabled 16-bit TABLE REQUIRE statement Signed-off-by: Jerry Ge Signed-off-by: Jeremy Johnson Change-Id: Ib6e81814e022f33e45430e47ca99d6d9f9e0e101 --- reference_model/src/ops/ewise_binary.cc | 8 ++++++-- 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::eval() index = std::min(std::max(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::max() && slope >= std::numeric_limits::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( ( "", -- cgit v1.2.1