From ab8547a002dceae1fc25b91ade9f9d5173aae196 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 29 Aug 2024 19:34:34 -0400 Subject: [PATCH] nir: push up abs in atan2 calculation everybody has abs on fmul, not everyone has abs on bcsel. should help agx and bifrost. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Ian Romanick Part-of: --- src/compiler/nir/nir_builtin_builder.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_builtin_builder.c b/src/compiler/nir/nir_builtin_builder.c index bfd44b99e18..06a07058370 100644 --- a/src/compiler/nir/nir_builtin_builder.c +++ b/src/compiler/nir/nir_builtin_builder.c @@ -273,7 +273,8 @@ nir_atan2(nir_builder *b, nir_def *y, nir_def *x) nir_def *scale = nir_bcsel(b, nir_fge_imm(b, nir_fabs(b, t), huge_val), nir_imm_floatN_t(b, 0.25, bit_size), one); nir_def *rcp_scaled_t = nir_frcp(b, nir_fmul(b, t, scale)); - nir_def *s_over_t = nir_fmul(b, nir_fmul(b, s, scale), rcp_scaled_t); + nir_def *abs_s_over_t = nir_fmul(b, nir_fabs(b, nir_fmul(b, s, scale)), + nir_fabs(b, rcp_scaled_t)); /* For |x| = |y| assume tan = 1 even if infinite (i.e. pretend momentarily * that ∞/∞ = 1) in order to comply with the rather artificial rules @@ -293,7 +294,7 @@ nir_atan2(nir_builder *b, nir_def *y, nir_def *x) * well). */ nir_def *tan = nir_bcsel(b, nir_feq(b, nir_fabs(b, x), nir_fabs(b, y)), - one, nir_fabs(b, s_over_t)); + one, abs_s_over_t); /* Calculate the arctangent and fix up the result if we had flipped the * coordinate system.