You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it okay that isInf() and isNan() can return false for infinities / nans? #2270
Issue #2259 highlights the fact that some backends assume fast-math, and so compilers may perform transformations that result in the isInf() / isNan() builtins returning false for infinite / NaN values, even when loading these values directly from memory.
Is this something we're happy with? If not, should we consider removing these builtins from the WGSL spec until we can guarantee more strict behaviours?
isFinite(x) is false when x is infinity or NaN. An implementation can assume infinities and NaNs don't exist, so isFinite can be implemented as always returning false.
As long as the backends use -ffast-math, I don't think these functions make much sense (since the compiler can always assume that no value is inf/NaN).
Since issue #2259 suggests that disabling -ffast-math would come from an extension, I would propose moving these functions to the same extension.
As long as the backends use -ffast-math, I don't think these functions make much sense (since the compiler can always assume that no value is inf/NaN). Since issue #2259 suggests that disabling -ffast-math would come from an extension, I would propose moving these functions to the same extension.
JG: (gives background). Fast math can make isnan() turn into always-false. (!)
JG: Like Robin’s idea of removing now, and later adding an extension that adds preservation of inf and nan and than adds the functions back again.
MM: Philosophically adding false information is worse than not adding information.
DM: Can we possibly detect these on fast-math?
BC: Even if you polyfill, the compiler can still assume it doesn’t happen, and will melt it away.
JG: I think that even “loading directly from memory” isn’t enough
MM: Yes, can still get false negatives.
DN: So when translating spir-v, when I see these opcodes, what do I do? Inject false? (JG: yes)
MM: I think it’s up to implementation. Like, you can (try to) check the bits, that’s up to you. But rather that we shouldn’t volunteer known-flakey builtins.
AB: Would we mind if multiple extensions added these same builtins?
MM: Which multiple extensions?
AB: I could see multiple precise-math approach extensions might both re-introduce these.
MM: It would be unfortunate if we ended up with e.g. three subtly different extensions for precise math.
AB: We should figure out what our requirements for releasing/exposing extensions are. (AB to file issue)
DN: Yes, since zero is non-normal. And there are also denormals. Denormals are not normal.
JG: So don’t some systems maybe-flush subnormals?
AB: Yeah, though if you load from memory it probably is preserved, just not for arithmetic. Is_normal is basically “is exponent not one of the extremes”.
MM: So doesn’t that put us in the same spot as isinf?
JG: It sounds like it’s more reliable than isinf.
AB: Review of all platforms. Can flush demormals on arithmetic operations. Vulkan phrases is “these operations preserve denormals”.. HLSL says “data movement” preserves denorms. Metal may have similar language. The language on underlying implementation is “implementation may assume that nans and infinities do not occur”. And with that the compiler will affirmatively remove function calls like isnan, isinf. My testing shows that it’s actually sometimes reliable and not always.
Activity
dneto0 commentedon Nov 8, 2021
isFinite(x) is false when x is infinity or NaN. An implementation can assume infinities and NaNs don't exist, so isFinite can be implemented as always returning false.
RobinMorisset commentedon Nov 16, 2021
As long as the backends use -ffast-math, I don't think these functions make much sense (since the compiler can always assume that no value is inf/NaN).
Since issue #2259 suggests that disabling -ffast-math would come from an extension, I would propose moving these functions to the same extension.
kdashg commentedon Nov 16, 2021
I like this idea.
kdashg commentedon Nov 16, 2021
WGSL meeting minutes 2021-11-16
Remove isInf, isNan
Remove isInf, isNan (#2311)