[Mlir-commits] [mlir] [mlir][tosa][tosa-to-linalg] Fix resize bilinear delta computation for negative offsets (PR #184799)

Luke Hutton llvmlistbot at llvm.org
Thu Mar 5 09:14:01 PST 2026


lhutton1 wrote:

No worries, happy to add this to the commit message as well as it's a bit subtle. 

Essentially, RemSI uses a division which truncates to zero, while the specification pseudo-code computes the remainder using a floor division which rounds towards minus infinity. This was causing conformance tests to fail when the offset provided was negative. After this fix they pass.

```
// Suppose we have the following call to `getIndexAndDeltaFp`
in = 470
scaleN = 16
scaleD = 1
offset = -7

val = in * scaleD = 470 * 1 = 470
val = val + offset = 470 * -7 = -3290

// Previously
r = RemSI(val, scaleN) = val - trunc(val / scaleN) * scaleN
      q = trunc(val / scaleN) = trunc(-3290 / 16) = -205
      r = val - q * scaleN  = -3290 - (-205) * 16 = -10

// Now
r = val - FloorDivSI(val, scaleN) * scaleN
      q = foor(val / scaleN) = floor(-3290 / 16) = -206
      r = val - q * scaleN = -3290 - (-206) * 16 = 6
```

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


More information about the Mlir-commits mailing list