From: Erik Faye-Lund Date: Thu, 12 Mar 2020 14:58:04 +0000 (+0100) Subject: compiler/nir: move build_log helper into builtin-builder X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c98e745e787f5df9ad45db6472a37d51a03b5fb8;p=mesa.git compiler/nir: move build_log helper into builtin-builder Reviewed-by: Karol Herbst Reviewed-by: Jason Ekstrand Part-of: --- diff --git a/src/compiler/nir/nir_builtin_builder.h b/src/compiler/nir/nir_builtin_builder.h index 6a804219b61..ad837a51569 100644 --- a/src/compiler/nir/nir_builtin_builder.h +++ b/src/compiler/nir/nir_builtin_builder.h @@ -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) { diff --git a/src/compiler/spirv/vtn_glsl450.c b/src/compiler/spirv/vtn_glsl450.c index 3cdef852583..2ecd0295bc8 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 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; }