NIR f2u constant folding invokes undefined behaviour
In C, the implicit conversion of a negative floating point number to an unsigned integer is UNDEFINED. In practice, it converts as is signed on some architectures (x86) and converts to 0 on others (arm). Accordingly, the results of constant folding f2u32 of a negative floating point number are unreliable across architectures. I hit this issue on a Bifrost unit test that passed on arm but failed on x86. The relevant questions are thus
- Should f2u(-x) be defined at all? If so, to what?
- Is it defined in SPIR-V? If so, to what?
- What does GPU hardware do practice?
For the last point, computerator says that on Mali G78, f2u(-x) = 0, matching the arm64 semantic. So I have a vested interest in making sure it's defined to be zero
Cc @jekstrand the wizard of numerology.