From a383a481eed123f91a0b8460c88122a7dbcbaaa1 Mon Sep 17 00:00:00 2001 From: Peng Sun Date: Wed, 24 May 2023 15:20:56 -0700 Subject: [PATCH] [mlir][tosa] Update the limit of 62 on shift. Aligns the shift requirement with the TOSA specification. Reviewed By: eric-k256 Differential Revision: https://reviews.llvm.org/D151113 --- mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp index 1c4ae1f..a164135 100644 --- a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp +++ b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp @@ -44,11 +44,13 @@ static void computeMultiplierAndShiftTosaScale16(double scale, multiplier = static_cast(shiftedM); - // Shifting tops out at 63 bits. Right shift to make 63 bits the max. - if (shift > 63) { + // Shifting tops out at 62 bits. Right shift to make 62 bits the max. + // The limit of 62 on shift allows the shift to be decomposed as + // two right shifts of 31. + if (shift > 62) { // Shifting the multiplier by more than 31-bits is unnecessary. - multiplier = multiplier >> std::min(31, shift - 63); - shift = 63; + multiplier = multiplier >> std::min(31, shift - 62); + shift = 62; } } @@ -79,11 +81,13 @@ static void computeMultiplierAndShiftTosaScale32(double scale, multiplier = static_cast(shiftedM); - // Shifting tops out at 63 bits. Right shift to make 63 bits the max. - if (shift > 63) { + // Shifting tops out at 62 bits. Right shift to make 62 bits the max. + // The limit of 62 on shift allows the shift to be decomposed as + // two right shifts of 31. + if (shift > 62) { // Shifting the multiplier by more than 32-bits is unnecessary. - multiplier = multiplier >> std::min(31, shift - 63); - shift = 63; + multiplier = multiplier >> std::min(31, shift - 62); + shift = 62; } } -- 2.7.4