[Mesa-dev] [PATCH 27/38] ac/nir: make ac_build_bit_count work on all bit sizes

Rhys Perry pendingchaos02 at gmail.com
Fri Dec 7 17:22:20 UTC 2018


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

diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c
index 2172d81f8b..3990a1f56d 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -2362,35 +2362,16 @@ LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
 
 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0)
 {
-	LLVMValueRef result;
-	unsigned bitsize;
+	unsigned bitsize = ac_get_elem_bits(ctx, LLVMTypeOf(src0));
 
-	bitsize = ac_get_elem_bits(ctx, LLVMTypeOf(src0));
+	char name[64];
+	snprintf(name, sizeof(name), "llvm.ctpop.i%d", bitsize);
 
-	switch (bitsize) {
-	case 64:
-		result = ac_build_intrinsic(ctx, "llvm.ctpop.i64", ctx->i64,
-					    (LLVMValueRef []) { src0 }, 1,
-					    AC_FUNC_ATTR_READNONE);
-
-		result = LLVMBuildTrunc(ctx->builder, result, ctx->i32, "");
-		break;
-	case 32:
-		result = ac_build_intrinsic(ctx, "llvm.ctpop.i32", ctx->i32,
-					    (LLVMValueRef []) { src0 }, 1,
-					    AC_FUNC_ATTR_READNONE);
-		break;
-	case 16:
-		result = ac_build_intrinsic(ctx, "llvm.ctpop.i16", ctx->i16,
-					    (LLVMValueRef []) { src0 }, 1,
-					    AC_FUNC_ATTR_READNONE);
-		break;
-	default:
-		unreachable(!"invalid bitsize");
-		break;
-	}
+	LLVMValueRef result = ac_build_intrinsic(ctx, name, LLVMTypeOf(src0),
+						 (LLVMValueRef []) { src0 }, 1,
+						 AC_FUNC_ATTR_READNONE);
 
-	return result;
+	return ac_build_ui_cast(ctx, result, ctx->i32);
 }
 
 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx,
-- 
2.19.2



More information about the mesa-dev mailing list