[Mesa-dev] [PATCH v2 26/41] ac/nir: make ac_find_lsb work on all bit sizes

Rhys Perry pendingchaos02 at gmail.com
Sat Feb 16 00:22:15 UTC 2019


v2: don't use ac_get_zero() and ac_int_of_size()

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
---
 src/amd/common/ac_llvm_build.c | 33 ++++++---------------------------
 1 file changed, 6 insertions(+), 27 deletions(-)

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index aa92c55c822..61085db9320 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -2474,30 +2474,11 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
 			 LLVMTypeRef dst_type,
 			 LLVMValueRef src0)
 {
-	unsigned src0_bitsize = ac_get_elem_bits(ctx, LLVMTypeOf(src0));
-	const char *intrin_name;
-	LLVMTypeRef type;
-	LLVMValueRef zero;
-
-	switch (src0_bitsize) {
-	case 64:
-		intrin_name = "llvm.cttz.i64";
-		type = ctx->i64;
-		zero = ctx->i64_0;
-		break;
-	case 32:
-		intrin_name = "llvm.cttz.i32";
-		type = ctx->i32;
-		zero = ctx->i32_0;
-		break;
-	case 16:
-		intrin_name = "llvm.cttz.i16";
-		type = ctx->i16;
-		zero = ctx->i16_0;
-		break;
-	default:
-		unreachable(!"invalid bitsize");
-	}
+	LLVMTypeRef type = LLVMTypeOf(src0);
+	unsigned src0_bitsize = ac_get_elem_bits(ctx, type);
+	char intrin_name[64];
+	LLVMValueRef zero = LLVMConstInt(type, 0, false);
+	snprintf(intrin_name, sizeof(intrin_name), "llvm.cttz.i%d", src0_bitsize);
 
 	LLVMValueRef params[2] = {
 		src0,
@@ -2518,9 +2499,7 @@ LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
 					      params, 2,
 					      AC_FUNC_ATTR_READNONE);
 
-	if (src0_bitsize == 64) {
-		lsb = LLVMBuildTrunc(ctx->builder, lsb, ctx->i32, "");
-	}
+	lsb = ac_build_ui_cast(ctx, lsb, ctx->i32);
 
 	/* TODO: We need an intrinsic to skip this conditional. */
 	/* Check for zero: */
-- 
2.20.1



More information about the mesa-dev mailing list