ac: add 64bit bitCount support
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 6 Feb 2018 03:34:55 +0000 (14:34 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Thu, 8 Feb 2018 22:42:59 +0000 (09:42 +1100)
v2: use LLVMBuildTrunc()

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/amd/common/ac_nir_to_llvm.c

index 550c12d249c7a885b3fe1bdc9b143d58e8acf2a1..b842641383c3a2a8fb7db77e985d1194b1c66d22 100644 (file)
@@ -1917,7 +1917,12 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                result = ac_build_intrinsic(&ctx->ac, "llvm.bitreverse.i32", ctx->ac.i32, src, 1, AC_FUNC_ATTR_READNONE);
                break;
        case nir_op_bit_count:
-               result = ac_build_intrinsic(&ctx->ac, "llvm.ctpop.i32", ctx->ac.i32, src, 1, AC_FUNC_ATTR_READNONE);
+               if (get_elem_bits(&ctx->ac, LLVMTypeOf(src[0])) == 32)
+                       result = ac_build_intrinsic(&ctx->ac, "llvm.ctpop.i32", ctx->ac.i32, src, 1, AC_FUNC_ATTR_READNONE);
+               else {
+                       result = ac_build_intrinsic(&ctx->ac, "llvm.ctpop.i64", ctx->ac.i64, src, 1, AC_FUNC_ATTR_READNONE);
+                       result = LLVMBuildTrunc(ctx->ac.builder, result, ctx->ac.i32, "");
+               }
                break;
        case nir_op_vec2:
        case nir_op_vec3: