From 9dae3a68058631833f10ea57d32ab3907ffb1e2f Mon Sep 17 00:00:00 2001 From: Johan Gunnarsson Date: Mon, 24 Feb 2025 12:04:05 +0100 Subject: [PATCH] MLBEDSW-10297: ConvertHardSwishToLUT: Make sure shift is in range QuantizedScale can give us shifts in the range of [0, 63] but RoundingDivideByPOT can only handle shifts in the range of [0, 31], so try to move it into the smaller range before calling that function. Signed-off-by: Johan Gunnarsson Change-Id: I24e8b67a28550bb88c0a746add06484af1c240d1 --- ethosu/regor/compiler/tflite_graph_optimiser_tp.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ethosu/regor/compiler/tflite_graph_optimiser_tp.cpp b/ethosu/regor/compiler/tflite_graph_optimiser_tp.cpp index 9c814103..fe7676b6 100644 --- a/ethosu/regor/compiler/tflite_graph_optimiser_tp.cpp +++ b/ethosu/regor/compiler/tflite_graph_optimiser_tp.cpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2021, 2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2021, 2024-2025 Arm Limited and/or its affiliates // SPDX-FileCopyrightText: Copyright 2020 The TensorFlow Authors. All Rights Reserved. // // SPDX-License-Identifier: Apache-2.0 @@ -109,6 +109,13 @@ Operation *TFLiteGraphOptimiser::ConvertHardSwishToLUT(Graph *const graph, Opera reluValue = SaturatingLeftShift(reluValue, 1); } + // Try to get reluShift into the [-31, 0] range + if ( reluShift < -31 ) + { + reluValue = reluValue >> (-31 - reluShift); + reluShift = -31; + } + if ( reluShift < 0 ) { reluValue = gemmlowp::RoundingDivideByPOT(reluValue, -reluShift); -- GitLab