compiler/nir: move build_exp helper into builtin-builder
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 12 Mar 2020 14:00:37 +0000 (15:00 +0100)
committerMarge Bot <eric+marge@anholt.net>
Thu, 26 Mar 2020 10:14:22 +0000 (10:14 +0000)
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4318>

src/compiler/nir/nir_builtin_builder.h
src/compiler/spirv/vtn_glsl450.c

index 9aa24ef592c5ccbd77aa6db13d74b105b3f9ecae..6a804219b611819c80b297fb30b23496b4aa9a2d 100644 (file)
@@ -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)
 {
index 571f06cbed2a59ffdbd0f85ab2e6037f6e341df3..3cdef852583c851ad85eeeef788d8f46f48499df 100644 (file)
@@ -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;
    }