From: Ian Romanick Date: Tue, 30 Apr 2019 15:00:32 +0000 (-0700) Subject: nir: Saturating integer arithmetic is not associative X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=85e6865ff62390c632909a07a46deab54c742963;p=mesa.git nir: Saturating integer arithmetic is not associative In 8-bits, iadd_sat(iadd_sat(0x7f, 0x7f), -1) = iadd_sat(0x7f, -1) = 0x7e but, iadd_sat(0x7f, iadd_sat(0x7f, -1)) = iadd_sat(0x7f, 0x7e) = 0x7f Fixes: 272e927d0e9 ("nir/spirv: initial handling of OpenCL.std extension opcodes") Reviewed-by: Karol Herbst Reviewed-by: Jason Ekstrand --- diff --git a/src/compiler/nir/nir_opcodes.py b/src/compiler/nir/nir_opcodes.py index d35d820aa5b..246d3d40381 100644 --- a/src/compiler/nir/nir_opcodes.py +++ b/src/compiler/nir/nir_opcodes.py @@ -482,7 +482,7 @@ def binop_reduce(name, output_size, output_type, src_type, prereduce_expr, binop("fadd", tfloat, commutative + associative, "src0 + src1") binop("iadd", tint, commutative + associative, "src0 + src1") -binop("iadd_sat", tint, commutative + associative, """ +binop("iadd_sat", tint, commutative, """ src1 > 0 ? (src0 + src1 < src0 ? (1ull << (bit_size - 1)) - 1 : src0 + src1) : (src0 < src0 + src1 ? (1ull << (bit_size - 1)) : src0 + src1)