[Mlir-commits] [mlir] a383a48 - [mlir][tosa] Update the limit of 62 on shift.
Eric Kunze
llvmlistbot at llvm.org
Wed May 24 15:36:43 PDT 2023
Author: Peng Sun
Date: 2023-05-24T15:35:50-07:00
New Revision: a383a481eed123f91a0b8460c88122a7dbcbaaa1
URL: https://github.com/llvm/llvm-project/commit/a383a481eed123f91a0b8460c88122a7dbcbaaa1
DIFF: https://github.com/llvm/llvm-project/commit/a383a481eed123f91a0b8460c88122a7dbcbaaa1.diff
LOG: [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
Added:
Modified:
mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp b/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp
index 1c4ae1f27319f..a164135aa0649 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<int32_t>(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<int32_t>(31, shift - 63);
- shift = 63;
+ multiplier = multiplier >> std::min<int32_t>(31, shift - 62);
+ shift = 62;
}
}
@@ -79,11 +81,13 @@ static void computeMultiplierAndShiftTosaScale32(double scale,
multiplier = static_cast<int32_t>(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<int32_t>(31, shift - 63);
- shift = 63;
+ multiplier = multiplier >> std::min<int32_t>(31, shift - 62);
+ shift = 62;
}
}
More information about the Mlir-commits
mailing list