From 85e6865ff62390c632909a07a46deab54c742963 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 30 Apr 2019 08:00:32 -0700 Subject: [PATCH] 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 --- src/compiler/nir/nir_opcodes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) -- 2.30.2