From: Ruslan Kabatsayev Date: Sat, 11 May 2019 11:04:36 +0000 (+0300) Subject: nir: Fix wrong sign in lower_rcp X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=974c4d679c23373dbed386c696e3e3bc1bfa23ae;p=mesa.git nir: Fix wrong sign in lower_rcp The nested fma calls were supposed to implement x_new = x + x * (1 - x*src), but instead current code is equivalent to x_new = x - x * (1 - x*src). The result is that Newton-Raphson steps don't improve precision at all. This patch fixes this problem. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110435 Reviewed-by: Kenneth Graunke --- diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c index 863046e65c7..18fe08c7d5d 100644 --- a/src/compiler/nir/nir_lower_double_ops.c +++ b/src/compiler/nir/nir_lower_double_ops.c @@ -142,8 +142,8 @@ lower_rcp(nir_builder *b, nir_ssa_def *src) * See https://en.wikipedia.org/wiki/Division_algorithm for more details. */ - ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); - ra = nir_ffma(b, ra, nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); + ra = nir_ffma(b, nir_fneg(b, ra), nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); + ra = nir_ffma(b, nir_fneg(b, ra), nir_ffma(b, ra, src, nir_imm_double(b, -1)), ra); return fix_inv_result(b, ra, src, new_exp); }