[Mesa-dev] [PATCH] ac/llvm: fix various findMSB bugs

Nicolai Hähnle nhaehnle at gmail.com
Sun Feb 19 09:08:14 UTC 2017


On 17.02.2017 14:26, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> sffbh needs to be suffixed with ".i32"

Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>

> ---
>  src/amd/common/ac_llvm_build.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
> index 5398f07..2f25b14 100644
> --- a/src/amd/common/ac_llvm_build.c
> +++ b/src/amd/common/ac_llvm_build.c
> @@ -762,21 +762,22 @@ ac_emit_sendmsg(struct ac_llvm_context *ctx,
>  	args[1] = wave_id;
>  	ac_emit_llvm_intrinsic(ctx, intr_name, ctx->voidt,
>  			       args, 2, 0);
>  }
>
>  LLVMValueRef
>  ac_emit_imsb(struct ac_llvm_context *ctx,
>  	     LLVMValueRef arg,
>  	     LLVMTypeRef dst_type)
>  {
> -	const char *intr_name = (HAVE_LLVM < 0x0400) ? "llvm.AMDGPU.flbit.i32" : "llvm.amdgcn.sffbh";
> +	const char *intr_name = (HAVE_LLVM < 0x0400) ? "llvm.AMDGPU.flbit.i32" :
> +						       "llvm.amdgcn.sffbh.i32";
>  	LLVMValueRef msb = ac_emit_llvm_intrinsic(ctx, intr_name,
>  						  dst_type, &arg, 1,
>  						  AC_FUNC_ATTR_READNONE);
>
>  	/* The HW returns the last bit index from MSB, but NIR/TGSI wants
>  	 * the index from LSB. Invert it by doing "31 - msb". */
>  	msb = LLVMBuildSub(ctx->builder, LLVMConstInt(ctx->i32, 31, false),
>  			   msb, "");
>
>  	LLVMValueRef all_ones = LLVMConstInt(ctx->i32, -1, true);
> @@ -789,21 +790,21 @@ ac_emit_imsb(struct ac_llvm_context *ctx,
>  	return LLVMBuildSelect(ctx->builder, cond, all_ones, msb, "");
>  }
>
>  LLVMValueRef
>  ac_emit_umsb(struct ac_llvm_context *ctx,
>  	     LLVMValueRef arg,
>  	     LLVMTypeRef dst_type)
>  {
>  	LLVMValueRef args[2] = {
>  		arg,
> -		LLVMConstInt(ctx->i32, 1, 0),
> +		LLVMConstInt(ctx->i1, 1, 0),
>  	};
>  	LLVMValueRef msb = ac_emit_llvm_intrinsic(ctx, "llvm.ctlz.i32",
>  						  dst_type, args, ARRAY_SIZE(args),
>  						  AC_FUNC_ATTR_READNONE);
>
>  	/* The HW returns the last bit index from MSB, but TGSI/NIR wants
>  	 * the index from LSB. Invert it by doing "31 - msb". */
>  	msb = LLVMBuildSub(ctx->builder, LLVMConstInt(ctx->i32, 31, false),
>  			   msb, "");
>
>



More information about the mesa-dev mailing list