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 f3fa5f490aad3cb349a38892276eefdeadcb2ce7..998d3592199450bb9b5c25a98a70721fe6d89d6c 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 29f5def9b5880727b7a2f2c849435099b9ed7403..e0f4f4aa3bce964c8cd03aaa5d46eca25a530df4 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 */