[Mesa-dev] [PATCH 2/3] i965/fs: Fix comparisions with uint negation.

Paul Berry stereotype441 at gmail.com
Wed Oct 5 11:37:31 PDT 2011

On 4 October 2011 23:55, Kenneth Graunke <kenneth at whitecape.org> wrote:

> On 10/03/2011 03:41 PM, Eric Anholt wrote:
> > The condmod instruction ends up generating garbage condition codes,
> > because apparently the comparison happens on the accumulator value (33
> > bits for UD), not the truncated value that would be written.
> >
> > Fixes fs-op-neg-*
> I am uneasy about these two patches for a number of reasons.
> 1. fs-op-neg-* and vs-op-neg-* fail on AMD (Catalyst 11.7),
>   which makes me wonder if the tests are correct.
> AMD does the expected behavior if you change the line:
>  uint result = (- arg0);
> to this:
>  uint result = uint(-int(arg0));
> or this:
>  uint result = 0 - arg0;
> While the GLSL spec isn't terribly clear about how unary negate works on
> unsigned, the fact -arg0 != 0 - arg0 seems horrendously broken.  So
> maybe AMD's driver is just buggy.
I personally fall mostly on the "AMD's driver is just buggy" side of this
argument.  My reasoning is based on this text from the GLSL 1.30 spec
(section 4.1.3 "Integers"): "Operations resulting in overflow or underflow
will not cause any exception, nor will they saturate, rather they will
“wrap” to yield the low-order 32 bits of the result."  So even though -1 is
not representable in a uint, it seems reasonable to me that it should "wrap"
to binary 11111111..., and so on.  But I admit we are in fairly dodgy
territory here, trying to negate unsigned values :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20111005/cc519caa/attachment.htm>

More information about the mesa-dev mailing list