From: Erik Faye-Lund Date: Thu, 12 Mar 2020 14:00:37 +0000 (+0100) Subject: compiler/nir: move build_exp helper into builtin-builder X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f59ae6883853fd7c7ee0965111fc19d20f6acfd2;p=mesa.git compiler/nir: move build_exp 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 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; }