[Mesa-dev] [PATCH 1/3] r600g: emit fmul/fadd(fmul) instead of AMDGPU.mul/mad intrinsics

Tom Stellard tom at stellard.net
Thu Nov 29 13:01:44 PST 2012


On Thu, Nov 29, 2012 at 09:32:07PM +0100, Vincent Lejeune wrote:
> ---
>  src/gallium/drivers/r600/r600_llvm.c               | 23 ++++++++++++++++++++++
>  .../drivers/radeon/radeon_setup_tgsi_llvm.c        | 10 ++++++----
>  2 files changed, 29 insertions(+), 4 deletions(-)
> 
> diff --git a/src/gallium/drivers/r600/r600_llvm.c b/src/gallium/drivers/r600/r600_llvm.c
> index 8f1ed26..350527b 100644
> --- a/src/gallium/drivers/r600/r600_llvm.c
> +++ b/src/gallium/drivers/r600/r600_llvm.c
> @@ -387,6 +387,27 @@ static void dp_fetch_args(
>  	emit_data->dst_type = base->elem_type;
>  }
>  
> +static void llvm_fmul(
> +		const struct lp_build_tgsi_action * action,
> +		struct lp_build_tgsi_context * bld_base,
> +		struct lp_build_emit_data * emit_data)
> +{
> +	LLVMBuilderRef builder = bld_base->base.gallivm->builder;
> +	emit_data->output[emit_data->chan] = LLVMBuildFMul(builder,
> +		emit_data->args[0], emit_data->args[1], "");
> +}
> +
> +static void llvm_fmad(
> +		const struct lp_build_tgsi_action * action,
> +		struct lp_build_tgsi_context * bld_base,
> +		struct lp_build_emit_data * emit_data)
> +{
> +	LLVMBuilderRef builder = bld_base->base.gallivm->builder;
> +	emit_data->output[emit_data->chan] = LLVMBuildFAdd(builder,
> +		LLVMBuildFMul(builder, emit_data->args[0], emit_data->args[1], ""),
> +		emit_data->args[2], "");
> +}
> +
>  static struct lp_build_tgsi_action dot_action = {
>  	.fetch_args = dp_fetch_args,
>  	.emit = build_tgsi_intrinsic_nomem,
> @@ -428,6 +449,8 @@ LLVMModuleRef r600_tgsi_llvm(
>  	bld_base->op_actions[TGSI_OPCODE_TXQ].emit = llvm_emit_tex;
>  	bld_base->op_actions[TGSI_OPCODE_TXP].emit = llvm_emit_tex;
>  	bld_base->op_actions[TGSI_OPCODE_CMP].emit = emit_cndlt;
> +	bld_base->op_actions[TGSI_OPCODE_MUL].emit = llvm_fmul;
> +	bld_base->op_actions[TGSI_OPCODE_MAD].emit = llvm_fmad;
>  

In auxiliary/gallivm/lp_bld_tgsi_action.c, there are already default
implementations of these opcodes and they are the same as the ones
you've added.  So, all we need to do here is not overide the emit function
of these two opcodes.

>  	lp_build_tgsi_llvm(bld_base, tokens);
>  
> diff --git a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
> index 5e3d6c2..cbcebbc 100644
> --- a/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
> +++ b/src/gallium/drivers/radeon/radeon_setup_tgsi_llvm.c
> @@ -547,12 +547,14 @@ static void emit_prepare_cube_coords(
>  	mad_args[2] = LLVMConstReal(type, 1.5);
>  
>  	mad_args[0] = coords[0];
> -	coords[0] = build_intrinsic(builder, "llvm.AMDIL.mad.",
> -			type, mad_args, 3, LLVMReadNoneAttribute);
> +	coords[0] = LLVMBuildFAdd(builder,
> +			LLVMBuildFMul(builder, mad_args[0], mad_args[1], ""),
> +			mad_args[2], "");
> 

I would prefer we use:

lp_build_emit_llvm_ternary(bld_base, TGSI_OPCODE_MAD,
                           mad_args[0], mad_args[1], mad_args[2]);

 
>  	mad_args[0] = coords[1];
> -	coords[1] = build_intrinsic(builder, "llvm.AMDIL.mad.",
> -			type, mad_args, 3, LLVMReadNoneAttribute);
> +	coords[1] = LLVMBuildFAdd(builder,
> +			LLVMBuildFMul(builder, mad_args[0], mad_args[1], ""),
> +			mad_args[2], "");

You can use the helper function here too.

>  
>  	/* apply yxwy swizzle to cooords */
>  	coords[2] = coords[3];
> -- 
> 1.8.0
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list