gallivm: add popcount intrinsic wrapper
authorDave Airlie <airlied@redhat.com>
Mon, 28 Oct 2019 04:21:43 +0000 (14:21 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 28 Nov 2019 04:48:25 +0000 (14:48 +1000)
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_bitarit.c
src/gallium/auxiliary/gallivm/lp_bld_bitarit.h

index f3fa5f4..998d359 100644 (file)
@@ -32,7 +32,7 @@
 #include "lp_bld_debug.h"
 #include "lp_bld_const.h"
 #include "lp_bld_bitarit.h"
-
+#include "lp_bld_intr.h"
 
 /**
  * Return (a | b)
@@ -240,3 +240,15 @@ lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
    assert(imm < bld->type.width);
    return lp_build_shr(bld, a, b);
 }
+
+LLVMValueRef
+lp_build_popcount(struct lp_build_context *bld, LLVMValueRef a)
+{
+   LLVMBuilderRef builder = bld->gallivm->builder;
+   LLVMValueRef result;
+   char intr_str[256];
+
+   lp_format_intrinsic(intr_str, sizeof(intr_str), "llvm.ctpop", bld->vec_type);
+   result = lp_build_intrinsic_unary(builder, intr_str, bld->vec_type, a);
+   return result;
+}
index 29f5def..e0f4f4a 100644 (file)
@@ -71,4 +71,6 @@ lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm);
 LLVMValueRef
 lp_build_not(struct lp_build_context *bld, LLVMValueRef a);
 
+LLVMValueRef
+lp_build_popcount(struct lp_build_context *bld, LLVMValueRef a);
 #endif /* !LP_BLD_ARIT_H */