Mesa (master): compiler/nir: move build_exp helper into builtin-builder

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Mar 26 11:22:52 UTC 2020


Module: Mesa
Branch: master
Commit: f59ae6883853fd7c7ee0965111fc19d20f6acfd2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f59ae6883853fd7c7ee0965111fc19d20f6acfd2

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Thu Mar 12 15:00:37 2020 +0100

compiler/nir: move build_exp helper into builtin-builder

Reviewed-by: Karol Herbst <kherbst at redhat.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4318>

---

 src/compiler/nir/nir_builtin_builder.h |  6 ++++++
 src/compiler/spirv/vtn_glsl450.c       | 27 +++++++++------------------
 2 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/compiler/nir/nir_builtin_builder.h b/src/compiler/nir/nir_builtin_builder.h
index 9aa24ef592c..6a804219b61 100644
--- a/src/compiler/nir/nir_builtin_builder.h
+++ b/src/compiler/nir/nir_builtin_builder.h
@@ -88,6 +88,12 @@ nir_uabs_diff(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
    return nir_bcsel(b, cond, res0, res1);
 }
 
+static inline nir_ssa_def *
+nir_fexp(nir_builder *b, nir_ssa_def *x)
+{
+   return nir_fexp2(b, nir_fmul_imm(b, x, M_LOG2E));
+}
+
 static inline nir_ssa_def *
 nir_umul24(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
 {
diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c
index 571f06cbed2..3cdef852583 100644
--- a/src/compiler/spirv/vtn_glsl450.c
+++ b/src/compiler/spirv/vtn_glsl450.c
@@ -171,15 +171,6 @@ matrix_inverse(struct vtn_builder *b, struct vtn_ssa_value *src)
    return val;
 }
 
-/**
- * Return e^x.
- */
-static nir_ssa_def *
-build_exp(nir_builder *b, nir_ssa_def *x)
-{
-   return nir_fexp2(b, nir_fmul_imm(b, x, M_LOG2E));
-}
-
 /**
  * Return ln(x) - the natural logarithm of x.
  */
@@ -364,7 +355,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
       return;
 
    case GLSLstd450Exp:
-      val->ssa->def = build_exp(nb, src[0]);
+      val->ssa->def = nir_fexp(nb, src[0]);
       return;
 
    case GLSLstd450Log:
@@ -444,16 +435,16 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
    case GLSLstd450Sinh:
       /* 0.5 * (e^x - e^(-x)) */
       val->ssa->def =
-         nir_fmul_imm(nb, nir_fsub(nb, build_exp(nb, src[0]),
-                                       build_exp(nb, nir_fneg(nb, src[0]))),
+         nir_fmul_imm(nb, nir_fsub(nb, nir_fexp(nb, src[0]),
+                                       nir_fexp(nb, nir_fneg(nb, src[0]))),
                           0.5f);
       return;
 
    case GLSLstd450Cosh:
       /* 0.5 * (e^x + e^(-x)) */
       val->ssa->def =
-         nir_fmul_imm(nb, nir_fadd(nb, build_exp(nb, src[0]),
-                                       build_exp(nb, nir_fneg(nb, src[0]))),
+         nir_fmul_imm(nb, nir_fadd(nb, nir_fexp(nb, src[0]),
+                                       nir_fexp(nb, nir_fneg(nb, src[0]))),
                           0.5f);
       return;
 
@@ -472,10 +463,10 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
                                   nir_imm_floatN_t(nb, -clamped_x, bit_size),
                                   nir_imm_floatN_t(nb, clamped_x, bit_size));
       val->ssa->def =
-         nir_fdiv(nb, nir_fsub(nb, build_exp(nb, x),
-                               build_exp(nb, nir_fneg(nb, x))),
-                  nir_fadd(nb, build_exp(nb, x),
-                           build_exp(nb, nir_fneg(nb, x))));
+         nir_fdiv(nb, nir_fsub(nb, nir_fexp(nb, x),
+                               nir_fexp(nb, nir_fneg(nb, x))),
+                  nir_fadd(nb, nir_fexp(nb, x),
+                           nir_fexp(nb, nir_fneg(nb, x))));
       return;
    }
 



More information about the mesa-commit mailing list