nir_opcodes.py: Saturate to expression that doesn't overflow
authorKristian H. Kristensen <hoegsberg@google.com>
Thu, 18 Apr 2019 18:23:13 +0000 (11:23 -0700)
committerKristian H. Kristensen <hoegsberg@gmail.com>
Fri, 19 Apr 2019 16:17:37 +0000 (16:17 +0000)
commit41593f3c3711cd61156d91ad12bb8aabf91a9556
treea7b933c52c94996ec40e794693f7c62adba46440
parent15605cc9d481dccc8f4dff0e6471600809d56980
nir_opcodes.py: Saturate to expression that doesn't overflow

Compiler warns about overflow when assigning UINT64_MAX to something
smaller than a uin64_t:

src/compiler/nir/nir_constant_expressions.c:16909:50: warning: implicit conversion from 'unsigned long long' to 'uint1_t' (aka 'unsigned char') changes value from 18446744073709551615 to 255 [-Wconstant-conversion]
            uint1_t dst = (src0 + src1) < src0 ? UINT64_MAX : (src0 + src1);
                    ~~~                          ^~~~~~~~~~

Shift UINT64_MAX down to the appropriate maximum value for the type
being assigned to.

Signed-off-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_constant_expressions.py
src/compiler/nir/nir_opcodes.py