[all-commits] [llvm/llvm-project] 3a3732: [mlir][arith] wide integer emulation support for ...

egebeysel via All-commits all-commits at lists.llvm.org
Thu Mar 27 17:59:17 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3a3732c2527056342051068c3dbaef4e822bd0a6
      https://github.com/llvm/llvm-project/commit/3a3732c2527056342051068c3dbaef4e822bd0a6
  Author: egebeysel <beysel at roofline.ai>
  Date:   2025-03-27 (Thu, 27 Mar 2025)

  Changed paths:
    M mlir/lib/Dialect/Arith/Transforms/EmulateWideInt.cpp
    M mlir/test/Dialect/Arith/emulate-wide-int.mlir
    A mlir/test/Integration/Dialect/Arith/CPU/test-wide-int-emulation-fptosi-i64.mlir
    A mlir/test/Integration/Dialect/Arith/CPU/test-wide-int-emulation-fptoui-i64.mlir

  Log Message:
  -----------
  [mlir][arith]  wide integer emulation support for fpto*i ops (#132375)

Adding wide integer emulation support for `arith.fpto*i` operations. As
the other emulated operations, the upper and lower `N` bits of the `i2N`
integer result are emitted separately.

For the unsigned case we use the following emulation

```c
// example is 64 -> 32 bit emulation, but the implementation is generalized to any 2N -> N case
const double TWO_POW_N = (uint_64_t(1) << N); // 2^N, N is the bitwidth of the widest int supported

// f is a floating-point value representing the input of the fptoui op.
uint32_t hi = (uint32_t)(f / TWO_POW_N);         // Truncates the division result
uint32_t lo = (uint32_t)(f - hi * TWO_POW_N);       // Subtracts to get the lower bits.
```

For the signed case, we defer the emulation of the absolute value to
`fptoui` and handle the sign:

```
fptosi(fp) = sign(fp) * fptoui(abs(fp))
```

The edge cases of `NaNs, +-inf` and overflows/underflows are undefined
behaviour and the resulting numbers are the combination of the lower
bitwidth UB values. These operations also propagate poison values.

Signed-off-by: Ege Beysel <beysel at roofline.ai>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list