pan/va: Document IEEE 754 conformance of clamps

These rules are not obvious. But they turn out to be exactly what's
required by the spec.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12205>
This commit is contained in:
Alyssa Rosenzweig 2021-08-04 12:21:06 -04:00
parent cdfb5d3788
commit 6fa1479479
1 changed files with 27 additions and 0 deletions

View File

@ -400,6 +400,33 @@
clamps may be decomposed as two independent bits for `clamp_0_inf` and
`clamp_m1_1`, with `clamp_0_1` arising as the composition of `clamp_0_inf`
and `clamp_m1_1` in either order.
Clamps are implemented per the SPIR-V specification:
$$\text{clamp} \; (x, \ell, h) = \min( \max( x, \ell ), h)$$
The min/max functions return the other operand if one operand is NaN, and
compare $-0 &lt; +0$. That means the following identities hold for Valhall
clamps:
\begin{align*}
\text{clamp}(-0.0, 0.0, 1.0) &amp; = +0.0 \\
\text{clamp}(-\text{NaN}, 0.0, 1.0) &amp; = +0.0 \\
\text{clamp}(\text{NaN}, 0.0, 1.0) &amp; = +0.0 \\
&amp; \\
\text{clamp}(-0.0, -1.0, 1.0) &amp; = -0.0 \\
\text{clamp}(\text{NaN}, -1.0, 1.0) &amp; = -1.0 \\
\text{clamp}(-\text{NaN}, -1.0, 1.0) &amp; = -1.0 \\
&amp; \\
\max(\text{NaN}, 0.0) &amp; = +0.0 \\
\max(-\text{NaN}, 0.0) &amp; = +0.0 \\
\max(-0.0, 0.0) &amp; = +0.0 \\
\end{align*}
This behaviour is consistent with the FMin/FMax/FClamp and
NMin/NMax/NClamp rules prescribed by SPIR-V and governed by IEEE-754. As
a consequence, substituting these clamps for equivalent minimum/maximum
exprssions is legal even with strict floating point rules.
</desc>
<value default="true" desc="Identity">none</value>
<value desc="Clamp positive">clamp_0_inf</value>