SpvOpSDiv, SpvOpUDiv, SpvOpUMod and zero divisors
brianpaul opened this issue · 3 comments
The spec language for these functions says "Results are computed per component. The resulting value is undefined if Operand 2 is 0". If the operands are vectors, it's not clear what that means.
Does it mean "the whole results is undefined if any component of operand 2 is zero"?
Or, does it mean "components of the result are undefined if the corresponding component of operand 2 is zero"?
From my tests, it appears that AMD (AMDVLK driver) implements for former while Intel and Nvidia implement the later.
Khronos has agreed internally to make all these cases undefined behavior, allowing even more behavior than just values/vectors values being undefined. This is already queued up for the next revision of SPIR-V to be published.
Fixed in SPIR-V 1.6 release.
Example: https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#OpSMod
IMHO, this could still be stated more precisely. I'd say something like (for OpFDiv) "For vector operands, if any component of Operand2 is 0, the results are undefined for all the vector components".