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

Georgios Pinitas llvmlistbot at llvm.org
Mon Sep 23 01:44:54 PDT 2024


================
@@ -92,18 +92,31 @@ 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.
+    if (shift < 2)
----------------
GeorgeARM wrote:

Similar code in the two cases. Maybe worth pulling it into a lambda? e.g. `isShiftWithinRange` and check that is between 2 and 62?

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


More information about the Mlir-commits mailing list