[Mlir-commits] [mlir] [mlir][tosa] Add check for invalid tosa.rescale parameters (PR #129606)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Mar 4 17:41:28 PST 2025


================
@@ -92,18 +92,25 @@ static void computeMultiplierAndShiftTosaScale32(double scale,
 }
 
 /// Generates a quantized multiplier/shift from double.
-void mlir::tosa::computeMultiplierAndShift(double scale, int32_t &multiplier,
+bool mlir::tosa::computeMultiplierAndShift(double scale, int32_t &multiplier,
                                            int32_t &shift, int32_t scaleWidth) {
 
   switch (scaleWidth) {
   case 16:
     computeMultiplierAndShiftTosaScale16(scale, multiplier, shift);
-    return;
+
+    // In some cases computeMultiplierAndShiftTosaScale16 can return
+    // a value less then 2, which is not valid in the TOSA spec.
+    return (!(shift < 2));
   case 32:
     computeMultiplierAndShiftTosaScale32(scale, multiplier, shift);
----------------
Jerry-Ge wrote:

`computeMultiplierAndShiftTosaScale32` returns `static void` https://github.com/llvm/llvm-project/blob/ab6cc6b7b3a3de5e6f5999601f0d40ab2b2819e2/mlir/lib/Dialect/Tosa/Utils/QuantUtils.cpp#L60

https://github.com/llvm/llvm-project/pull/129606


More information about the Mlir-commits mailing list