Description
Wasm's current f32.min
and f32.max
, correspond to IEEE 754-2019's minimum
and maximum
operations. When exactly one of their two operands is a NaN, they pick the NaN. Wasm may wish to consider adding instructions corresponding to IEEE 754-2019's minimumNumber
and maximumNumber
operations, which would pick the non-NaN.
In LLVM, the corresponding operations are minimumnum
and maximumnum
. In C23, the corresponding functions are fminimum_num
and fmaximum_num
.
These are similar to the now-removed minNum
and maxNum
operators from IEEE 754-2008, but specify that negative zero is to be treated as less than zero rather than being nondeterministic, and that signaling NaN is to be handled more like quiet NaN so that the operators are associative.
Implementations
Looking at current major CPU ISAs, it appears only PowerPC has direct support for these instructions. However, as can be seen on aarch64, CPUs with instructions implementing 754-2008's minNum
and maxNum
can implement it with three instructions, and as can be seen on x86_64, AVX enables significant optimizations, so adding these new instructions would at least be an improvement over the status quo on most architectures for code that would use them.
Naming
Given that IEEE 754-2019's minimum
corresponds to Wasm's min
, it's tempting to map minimumNumber
to minnum
in Wasm, however this risks confusion with the old and removed minNum
and maxNum
operators.
Consequently, I suggest the names minnumber
and maxnumber
for Wasm. The full set would be:
f32.minnumber
f32.maxnumber
f64.minnumber
f64.maxnumber
Next steps
If anyone has information about source languages, compilers, or libraries using IEEE 754-2019's minumNumber
and maximumNumber
, or CPUs implementing them, or use cases that would benefit from them, please post about it here!