0
0
mirror of https://github.com/termux/termux-packages.git synced 2025-05-11 03:55:32 +00:00
Files
termux-packages/packages/clvk/0001-Do-not-use-__builtin_elementwise_popcount-for-clc_po.patch.beforehostbuild
2025-04-02 07:48:57 +08:00

84 lines
3.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Chongyun Lee <licy183@termux.dev>
Date: Tue, 1 Apr 2025 00:01:47 +0800
Subject: [PATCH] Do not use `__builtin_elementwise_popcount` for
`clc_popcount`
__builtin_elementwise_popcount is introduced in LLVM 20
---
libclc/clc/lib/generic/SOURCES | 1 -
libclc/generic/include/integer/popcount.h | 3 +++
.../generic/include/integer/unary_intrin.inc | 20 +++++++++++++++++++
libclc/generic/lib/integer/popcount.cl | 7 ++++---
4 files changed, 27 insertions(+), 4 deletions(-)
create mode 100644 libclc/generic/include/integer/popcount.h
create mode 100644 libclc/generic/include/integer/unary_intrin.inc
diff --git a/external/clspv/third_party/llvm/libclc/clc/lib/generic/SOURCES b/external/clspv/third_party/llvm/libclc/clc/lib/generic/SOURCES
index f7688d044..b2ffcd18a 100644
--- a/external/clspv/third_party/llvm/libclc/clc/lib/generic/SOURCES
+++ b/external/clspv/third_party/llvm/libclc/clc/lib/generic/SOURCES
@@ -12,7 +12,6 @@ integer/clc_mad24.cl
integer/clc_mad_sat.cl
integer/clc_mul24.cl
integer/clc_mul_hi.cl
-integer/clc_popcount.cl
integer/clc_rhadd.cl
integer/clc_rotate.cl
integer/clc_sub_sat.cl
diff --git a/external/clspv/third_party/llvm/libclc/generic/include/integer/popcount.h b/external/clspv/third_party/llvm/libclc/generic/include/integer/popcount.h
new file mode 100644
index 000000000..00c753753
--- /dev/null
+++ b/external/clspv/third_party/llvm/libclc/generic/include/integer/popcount.h
@@ -0,0 +1,3 @@
+#define __CLC_FUNCTION __clc_native_popcount
+#define __CLC_INTRINSIC "llvm.ctpop"
+#include <integer/unary_intrin.inc>
diff --git a/external/clspv/third_party/llvm/libclc/generic/include/integer/unary_intrin.inc b/external/clspv/third_party/llvm/libclc/generic/include/integer/unary_intrin.inc
new file mode 100644
index 000000000..ee9862a4c
--- /dev/null
+++ b/external/clspv/third_party/llvm/libclc/generic/include/integer/unary_intrin.inc
@@ -0,0 +1,20 @@
+#define __CLC_INTRINSIC_DEF(SCALAR_TYPE, BIT_SIZE) \
+_CLC_OVERLOAD SCALAR_TYPE __CLC_FUNCTION(SCALAR_TYPE x) __asm(__CLC_INTRINSIC ".i" BIT_SIZE); \
+_CLC_OVERLOAD SCALAR_TYPE##2 __CLC_FUNCTION(SCALAR_TYPE##2 x) __asm(__CLC_INTRINSIC ".v2i" BIT_SIZE); \
+_CLC_OVERLOAD SCALAR_TYPE##3 __CLC_FUNCTION(SCALAR_TYPE##3 x) __asm(__CLC_INTRINSIC ".v3i" BIT_SIZE); \
+_CLC_OVERLOAD SCALAR_TYPE##4 __CLC_FUNCTION(SCALAR_TYPE##4 x) __asm(__CLC_INTRINSIC ".v4i" BIT_SIZE); \
+_CLC_OVERLOAD SCALAR_TYPE##8 __CLC_FUNCTION(SCALAR_TYPE##8 x) __asm(__CLC_INTRINSIC ".v8i" BIT_SIZE); \
+_CLC_OVERLOAD SCALAR_TYPE##16 __CLC_FUNCTION(SCALAR_TYPE##16 x) __asm(__CLC_INTRINSIC ".v16i" BIT_SIZE);
+
+__CLC_INTRINSIC_DEF(char, "8")
+__CLC_INTRINSIC_DEF(uchar, "8")
+__CLC_INTRINSIC_DEF(short, "16")
+__CLC_INTRINSIC_DEF(ushort, "16")
+__CLC_INTRINSIC_DEF(int, "32")
+__CLC_INTRINSIC_DEF(uint, "32")
+__CLC_INTRINSIC_DEF(long, "64")
+__CLC_INTRINSIC_DEF(ulong, "64")
+
+#undef __CLC_FUNCTION
+#undef __CLC_INTRINSIC
+#undef __CLC_INTRINSIC_DEF
diff --git a/external/clspv/third_party/llvm/libclc/generic/lib/integer/popcount.cl b/external/clspv/third_party/llvm/libclc/generic/lib/integer/popcount.cl
index 4e8a6ebab..ca83b1afa 100644
--- a/external/clspv/third_party/llvm/libclc/generic/lib/integer/popcount.cl
+++ b/external/clspv/third_party/llvm/libclc/generic/lib/integer/popcount.cl
@@ -1,7 +1,8 @@
#include <clc/clc.h>
-#include <clc/integer/clc_popcount.h>
+#include <integer/popcount.h>
-#define FUNCTION popcount
-#define __CLC_BODY <clc/shared/unary_def.inc>
+#define __CLC_FUNC popcount
+#define __CLC_IMPL_FUNC __clc_native_popcount
+#define __CLC_BODY "../clc_unary.inc"
#include <clc/integer/gentype.inc>
--
2.43.0