[Mesa-dev] Mesa (master): glsl: Fix constant-folding for reciprocal expressions

Ian Romanick idr at freedesktop.org
Wed Feb 2 13:36:32 PST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/02/2011 10:01 AM, Chad Versace wrote:
> Module: Mesa
> Branch: master
> Commit: b3cf92aa916ee0537ee37723c23a9897ac9cd3e0
> URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b3cf92aa916ee0537ee37723c23a9897ac9cd3e0
> 
> Author: Chad Versace <chad.versace at intel.com>
> Date:   Tue Feb  1 09:09:33 2011 -0800
> 
> glsl: Fix constant-folding for reciprocal expressions
> 
> Do not constant-fold a reciprocal if any component of the reciprocated
> expression is 0. For example, do not constant-fold `1 / vec4(0, 1, 2, 3)`.
> 
> Incorrect, previous behavior
> ----------------------------
> Reciprocals were constant-folded even when some component of the
> reciprocated expression was 0. The incorrectly applied arithmetic was:
>    1 / 0 := 0
> For example,
>    1 / vec4(0, 1, 2, 3) = vec4(0, 1, 1/2, 1/3)

This behavior is actually correct.  Page 58 of the GLSL 3.30 (page 63 of
the PDF) says, "Dividing by zero does not cause an exception but does
result in an unspecified value."  Based on that, 1/0 can be 0.

The 4.10 spec contains that language, but it also requires IEEE 754
behavior.  Specifically, page 54 (page 59 of the PDF) says, "The
following rules apply to both single and double-precision operations:
Dividing by 0 results in the appropriately signed IEEE Inf."

For now I believe 1/0 for both integer and real values should result in
0.  In the future, I think drivers should supply the values for each
type that result from division by zero.  This will allow us to generate
the same results for constant expressions that the hardware generates
for non-constant expressions.

This also applies to e7c1f058.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk1JzmAACgkQX1gOwKyEAw9IXQCgh8h2hL44tYccI/G/d7G7G7kk
UgcAnjS4qQNJ9znI3Ks5r2iaSdRYh2mi
=g3/s
-----END PGP SIGNATURE-----


More information about the mesa-dev mailing list