Signed-off-by: Rhys Perry <pendingchao...@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 c986f800fa4..46738faea9d 100644
--- a/src/amd/common/ac_llvm_build.c
+++ b/src/amd/common/ac_llvm_build.c
@@ -2085,35 +2085,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.20.1

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to