Mesa (master): pan/bi: Lower frcp to Newton-Raphson
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Feb 8 14:06:19 UTC 2021
Module: Mesa
Branch: master
Commit: c5e5d11599f998dc89ad192fc85feb3c14b4e97a
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c5e5d11599f998dc89ad192fc85feb3c14b4e97a
Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date: Fri Jan 15 15:38:35 2021 -0500
pan/bi: Lower frcp to Newton-Raphson
For G71 but should work on any Bifrost, probably overlaps some CL stuff.
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Acked-by: Boris Brezillon <boris.brezillon at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8894>
---
src/panfrost/bifrost/bifrost_compile.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c
index 927a33d34ad..f73c74b9467 100644
--- a/src/panfrost/bifrost/bifrost_compile.c
+++ b/src/panfrost/bifrost/bifrost_compile.c
@@ -974,6 +974,21 @@ bi_fmul_f32(bi_builder *b, bi_index s0, bi_index s1)
return bi_fma_f32(b, s0, s1, bi_imm_f32(-0.0f), BI_ROUND_NONE);
}
+/* Approximate with FRCP_APPROX.f32 and apply a single iteration of
+ * Newton-Raphson to improve precision */
+
+static void
+bi_lower_frcp_32(bi_builder *b, bi_index dst, bi_index s0)
+{
+ bi_index x1 = bi_frcp_approx_f32(b, s0);
+ bi_index m = bi_frexpm_f32(b, s0, false, false);
+ bi_index e = bi_frexpe_f32(b, bi_neg(s0), false, false);
+ bi_index t1 = bi_fma_rscale_f32(b, m, bi_neg(x1), bi_imm_f32(1.0),
+ bi_zero(), BI_ROUND_NONE, BI_SPECIAL_N);
+ bi_fma_rscale_f32_to(b, dst, t1, x1, x1, e,
+ BI_ROUND_NONE, BI_SPECIAL_NONE);
+}
+
static void
bi_emit_alu(bi_builder *b, nir_alu_instr *instr)
{
More information about the mesa-commit
mailing list