compiler/nir: move build_log helper into builtin-builder
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 12 Mar 2020 14:58:04 +0000 (15:58 +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 6a804219b611819c80b297fb30b23496b4aa9a2d..ad837a5156906ae7665c7919643655972a101e79 100644 (file)
@@ -94,6 +94,12 @@ 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_flog(nir_builder *b, nir_ssa_def *x)
+{
+   return nir_fmul_imm(b, nir_flog2(b, x), 1.0 / M_LOG2E);
+}
+
 static inline nir_ssa_def *
 nir_umul24(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
 {
index 3cdef852583c851ad85eeeef788d8f46f48499df..2ecd0295bc8219eaab0904272b1c5c8c57ae6cc8 100644 (file)
@@ -171,15 +171,6 @@ matrix_inverse(struct vtn_builder *b, struct vtn_ssa_value *src)
    return val;
 }
 
-/**
- * Return ln(x) - the natural logarithm of x.
- */
-static nir_ssa_def *
-build_log(nir_builder *b, nir_ssa_def *x)
-{
-   return nir_fmul_imm(b, nir_flog2(b, x), 1.0 / M_LOG2E);
-}
-
 /**
  * Approximate asin(x) by the formula:
  *    asin~(x) = sign(x) * (pi/2 - sqrt(1 - |x|) * (pi/2 + |x|(pi/4 - 1 + |x|(p0 + |x|p1))))
@@ -359,7 +350,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
       return;
 
    case GLSLstd450Log:
-      val->ssa->def = build_log(nb, src[0]);
+      val->ssa->def = nir_flog(nb, src[0]);
       return;
 
    case GLSLstd450FClamp:
@@ -472,20 +463,20 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
 
    case GLSLstd450Asinh:
       val->ssa->def = nir_fmul(nb, nir_fsign(nb, src[0]),
-         build_log(nb, nir_fadd(nb, nir_fabs(nb, src[0]),
-                       nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
-                                                      1.0f)))));
+         nir_flog(nb, nir_fadd(nb, nir_fabs(nb, src[0]),
+                      nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
+                                                    1.0f)))));
       return;
    case GLSLstd450Acosh:
-      val->ssa->def = build_log(nb, nir_fadd(nb, src[0],
+      val->ssa->def = nir_flog(nb, nir_fadd(nb, src[0],
          nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),
                                         -1.0f))));
       return;
    case GLSLstd450Atanh: {
       nir_ssa_def *one = nir_imm_floatN_t(nb, 1.0, src[0]->bit_size);
       val->ssa->def =
-         nir_fmul_imm(nb, build_log(nb, nir_fdiv(nb, nir_fadd(nb, src[0], one),
-                                        nir_fsub(nb, one, src[0]))),
+         nir_fmul_imm(nb, nir_flog(nb, nir_fdiv(nb, nir_fadd(nb, src[0], one),
+                                       nir_fsub(nb, one, src[0]))),
                           0.5f);
       return;
    }