From fc5c671e8785c89cf986181e0e3e7fa8742c4dce Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 13 Oct 2022 17:18:09 -0400 Subject: [PATCH] nir: Fix nir_fmax_abs_vec_comp This failed to take fabs of the first component, implementing an unintended formula that would return the right results in some common cases but is wrong in general: max { x, |y|, |z| } instead of the intended max { |x|, |y|, |z| } Reexpress the implementation to make correctness obvious. Fixes: 272e927d0e9 ("nir/spirv: initial handling of OpenCL.std extension opcodes") Signed-off-by: Alyssa Rosenzweig Reviewed-by: Karol Herbst Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir_builtin_builder.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_builtin_builder.h b/src/compiler/nir/nir_builtin_builder.h index 40983a26456..97a4e4d3010 100644 --- a/src/compiler/nir/nir_builtin_builder.h +++ b/src/compiler/nir/nir_builtin_builder.h @@ -62,9 +62,10 @@ nir_nan_check2(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *res) static inline nir_ssa_def * nir_fmax_abs_vec_comp(nir_builder *b, nir_ssa_def *vec) { - nir_ssa_def *res = nir_channel(b, vec, 0); + nir_ssa_def *abs = nir_fabs(b, vec); + nir_ssa_def *res = nir_channel(b, abs, 0); for (unsigned i = 1; i < vec->num_components; ++i) - res = nir_fmax(b, res, nir_fabs(b, nir_channel(b, vec, i))); + res = nir_fmax(b, res, nir_channel(b, abs, i)); return res; }