[Mlir-commits] [mlir] Add arith expansion of f8E8M0 type for extf/trunc ops (PR #140332)

Umang Yadav llvmlistbot at llvm.org
Wed May 21 09:11:05 PDT 2025


umangyadav wrote:

I am open to renaming `arith.truncf` to `arith.extract_exponent` but then i am not sure what i should name `arith.extf : f8E8M0 to f32`.  Because, `arith.extf` of f8E8M0 to f32 would be a regular upcast in conventional way.  So i'll have `arith.extf` but not corresponding `arith.truncf` for F32 to F8E8M0 but `arith.extract_exponent` for that. 

Here is the  python code from official spec implementation. 

https://github.com/microsoft/microxcaling/blob/7bc41952de394f5cc5e782baf132e7c7542eb4e4/mx/mx_ops.py#L49

which is doing `max(fabs(x))` along with clamping [later](https://github.com/microsoft/microxcaling/blob/7bc41952de394f5cc5e782baf132e7c7542eb4e4/mx/mx_ops.py#L282). (though i argue that clamping is not necessary for f32 to f8E8M0 downcast since both have 8 bit exponents). 

One thing i missed is that it is mapping `zero.f32` to `2 ^ -126` and not `2 ^ -127`.  That allows to check for flush denorms later in the code [here](https://github.com/microsoft/microxcaling/blob/7bc41952de394f5cc5e782baf132e7c7542eb4e4/mx/mx_ops.py#L275)




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


More information about the Mlir-commits mailing list