[libclc] [libclc] Add generic implementation of bitfield_insert/extract,bit_reverse (PR #149070)
Wenju He via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 16 03:45:35 PDT 2025
https://github.com/wenju-he created https://github.com/llvm/llvm-project/pull/149070
The implementation is based on reference implementation in OpenCL-CTS/test_integer_ops. The generic implementations pass OpenCL-CTS/test_integer_ops tests on Intel GPU.
>From 9f8b12e6cf600cd05bab586e3d521e5354789e12 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Wed, 16 Jul 2025 12:44:48 +0200
Subject: [PATCH] [libclc] Add generic implementation of
bitfield_insert/extract,bit_reverse
The implementation is based on reference implementation in OpenCL-CTS/test_integer_ops.
The generic implementations pass OpenCL-CTS/test_integer_ops tests on Intel GPU.
---
.../clc/include/clc/integer/clc_bit_reverse.h | 19 +++++++++++++++
.../clc/integer/clc_bitfield_extract.inc | 10 ++++++++
.../clc/integer/clc_bitfield_extract_signed.h | 23 +++++++++++++++++++
.../integer/clc_bitfield_extract_unsigned.h | 23 +++++++++++++++++++
.../include/clc/integer/clc_bitfield_insert.h | 17 ++++++++++++++
.../clc/integer/clc_bitfield_insert.inc | 10 ++++++++
libclc/clc/lib/generic/SOURCES | 4 ++++
.../lib/generic/integer/clc_bit_reverse.cl | 15 ++++++++++++
.../integer/clc_bitfield_extract_signed.cl | 12 ++++++++++
.../integer/clc_bitfield_extract_signed.inc | 19 +++++++++++++++
.../integer/clc_bitfield_extract_unsigned.cl | 12 ++++++++++
.../integer/clc_bitfield_extract_unsigned.inc | 16 +++++++++++++
.../generic/integer/clc_bitfield_insert.cl | 12 ++++++++++
.../generic/integer/clc_bitfield_insert.inc | 20 ++++++++++++++++
.../include/clc/opencl/integer/bit_reverse.h | 21 +++++++++++++++++
.../clc/opencl/integer/bitfield_extract.inc | 10 ++++++++
.../opencl/integer/bitfield_extract_signed.h | 23 +++++++++++++++++++
.../integer/bitfield_extract_unsigned.h | 23 +++++++++++++++++++
.../clc/opencl/integer/bitfield_insert.h | 19 +++++++++++++++
.../clc/opencl/integer/bitfield_insert.inc | 11 +++++++++
libclc/opencl/lib/generic/SOURCES | 4 ++++
.../opencl/lib/generic/integer/bit_reverse.cl | 19 +++++++++++++++
.../lib/generic/integer/bitfield_extract.inc | 16 +++++++++++++
.../integer/bitfield_extract_signed.cl | 20 ++++++++++++++++
.../integer/bitfield_extract_unsigned.cl | 20 ++++++++++++++++
.../lib/generic/integer/bitfield_insert.cl | 17 ++++++++++++++
.../lib/generic/integer/bitfield_insert.inc | 13 +++++++++++
27 files changed, 428 insertions(+)
create mode 100644 libclc/clc/include/clc/integer/clc_bit_reverse.h
create mode 100644 libclc/clc/include/clc/integer/clc_bitfield_extract.inc
create mode 100644 libclc/clc/include/clc/integer/clc_bitfield_extract_signed.h
create mode 100644 libclc/clc/include/clc/integer/clc_bitfield_extract_unsigned.h
create mode 100644 libclc/clc/include/clc/integer/clc_bitfield_insert.h
create mode 100644 libclc/clc/include/clc/integer/clc_bitfield_insert.inc
create mode 100644 libclc/clc/lib/generic/integer/clc_bit_reverse.cl
create mode 100644 libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.cl
create mode 100644 libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.inc
create mode 100644 libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.cl
create mode 100644 libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.inc
create mode 100644 libclc/clc/lib/generic/integer/clc_bitfield_insert.cl
create mode 100644 libclc/clc/lib/generic/integer/clc_bitfield_insert.inc
create mode 100644 libclc/opencl/include/clc/opencl/integer/bit_reverse.h
create mode 100644 libclc/opencl/include/clc/opencl/integer/bitfield_extract.inc
create mode 100644 libclc/opencl/include/clc/opencl/integer/bitfield_extract_signed.h
create mode 100644 libclc/opencl/include/clc/opencl/integer/bitfield_extract_unsigned.h
create mode 100644 libclc/opencl/include/clc/opencl/integer/bitfield_insert.h
create mode 100644 libclc/opencl/include/clc/opencl/integer/bitfield_insert.inc
create mode 100644 libclc/opencl/lib/generic/integer/bit_reverse.cl
create mode 100644 libclc/opencl/lib/generic/integer/bitfield_extract.inc
create mode 100644 libclc/opencl/lib/generic/integer/bitfield_extract_signed.cl
create mode 100644 libclc/opencl/lib/generic/integer/bitfield_extract_unsigned.cl
create mode 100644 libclc/opencl/lib/generic/integer/bitfield_insert.cl
create mode 100644 libclc/opencl/lib/generic/integer/bitfield_insert.inc
diff --git a/libclc/clc/include/clc/integer/clc_bit_reverse.h b/libclc/clc/include/clc/integer/clc_bit_reverse.h
new file mode 100644
index 0000000000000..c945e326c74fa
--- /dev/null
+++ b/libclc/clc/include/clc/integer/clc_bit_reverse.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_INTEGER_CLC_BIT_REVERSE_H__
+#define __CLC_INTEGER_CLC_BIT_REVERSE_H__
+
+#define FUNCTION __clc_bit_reverse
+#define __CLC_BODY <clc/shared/unary_decl.inc>
+
+#include <clc/integer/gentype.inc>
+
+#undef FUNCTION
+
+#endif // __CLC_INTEGER_CLC_BIT_REVERSE_H__
diff --git a/libclc/clc/include/clc/integer/clc_bitfield_extract.inc b/libclc/clc/include/clc/integer/clc_bitfield_extract.inc
new file mode 100644
index 0000000000000..c93eff08de0bc
--- /dev/null
+++ b/libclc/clc/include/clc/integer/clc_bitfield_extract.inc
@@ -0,0 +1,10 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DECL __RETTYPE FUNCTION(__CLC_GENTYPE base, uint offset,
+ uint count);
diff --git a/libclc/clc/include/clc/integer/clc_bitfield_extract_signed.h b/libclc/clc/include/clc/integer/clc_bitfield_extract_signed.h
new file mode 100644
index 0000000000000..fec5bf0b272e0
--- /dev/null
+++ b/libclc/clc/include/clc/integer/clc_bitfield_extract_signed.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
+#define __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
+
+#include <clc/internal/clc.h>
+
+#define FUNCTION __clc_bitfield_extract_signed
+#define __RETTYPE __CLC_S_GENTYPE
+
+#define __CLC_BODY <clc/integer/clc_bitfield_extract.inc>
+#include <clc/integer/gentype.inc>
+
+#undef __RETTYPE
+#undef FUNCTION
+
+#endif // __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
diff --git a/libclc/clc/include/clc/integer/clc_bitfield_extract_unsigned.h b/libclc/clc/include/clc/integer/clc_bitfield_extract_unsigned.h
new file mode 100644
index 0000000000000..ddbbf2bd92483
--- /dev/null
+++ b/libclc/clc/include/clc/integer/clc_bitfield_extract_unsigned.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
+#define __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
+
+#include <clc/internal/clc.h>
+
+#define FUNCTION __clc_bitfield_extract_unsigned
+#define __RETTYPE __CLC_U_GENTYPE
+
+#define __CLC_BODY <clc/integer/clc_bitfield_extract.inc>
+#include <clc/integer/gentype.inc>
+
+#undef __RETTYPE
+#undef FUNCTION
+
+#endif // __CLC_INTEGER_CLC_BITFIELD_EXTRACT_SIGNED_H__
diff --git a/libclc/clc/include/clc/integer/clc_bitfield_insert.h b/libclc/clc/include/clc/integer/clc_bitfield_insert.h
new file mode 100644
index 0000000000000..4e15d7884988b
--- /dev/null
+++ b/libclc/clc/include/clc/integer/clc_bitfield_insert.h
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_INTEGER_CLC_BITFIELD_INSERT_H__
+#define __CLC_INTEGER_CLC_BITFIELD_INSERT_H__
+
+#include <clc/internal/clc.h>
+
+#define __CLC_BODY <clc/integer/clc_bitfield_insert.inc>
+#include <clc/integer/gentype.inc>
+
+#endif // __CLC_INTEGER_CLC_BITFIELD_INSERT_H__
diff --git a/libclc/clc/include/clc/integer/clc_bitfield_insert.inc b/libclc/clc/include/clc/integer/clc_bitfield_insert.inc
new file mode 100644
index 0000000000000..de9a42f34223f
--- /dev/null
+++ b/libclc/clc/include/clc/integer/clc_bitfield_insert.inc
@@ -0,0 +1,10 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_bitfield_insert(
+ __CLC_GENTYPE base, __CLC_GENTYPE insert, uint offset, uint count);
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index bf8736a726315..9d792c4b3d28d 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -15,6 +15,10 @@ geometric/clc_normalize.cl
integer/clc_abs.cl
integer/clc_abs_diff.cl
integer/clc_add_sat.cl
+integer/clc_bitfield_extract_signed.cl
+integer/clc_bitfield_extract_unsigned.cl
+integer/clc_bitfield_insert.cl
+integer/clc_bit_reverse.cl
integer/clc_clz.cl
integer/clc_ctz.cl
integer/clc_hadd.cl
diff --git a/libclc/clc/lib/generic/integer/clc_bit_reverse.cl b/libclc/clc/lib/generic/integer/clc_bit_reverse.cl
new file mode 100644
index 0000000000000..439957383f583
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bit_reverse.cl
@@ -0,0 +1,15 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/integer/clc_bit_reverse.h>
+
+#define FUNCTION __clc_bit_reverse
+#define __IMPL_FUNCTION(x) __builtin_elementwise_bitreverse
+#define __CLC_BODY <clc/shared/unary_def.inc>
+
+#include <clc/integer/gentype.inc>
diff --git a/libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.cl b/libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.cl
new file mode 100644
index 0000000000000..d779ed6a43593
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.cl
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/integer/clc_bitfield_extract_signed.h>
+
+#define __CLC_BODY <clc_bitfield_extract_signed.inc>
+#include <clc/integer/gentype.inc>
diff --git a/libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.inc b/libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.inc
new file mode 100644
index 0000000000000..84cae2166f7ce
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bitfield_extract_signed.inc
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_S_GENTYPE
+__clc_bitfield_extract_signed(__CLC_GENTYPE base, uint offset, uint count) {
+ if (count == 0)
+ return 0;
+ __CLC_U_GENTYPE x = __CLC_AS_U_GENTYPE(base)
+ << (__CLC_GENSIZE - offset - count);
+ // Implement an arithmetic shift right.
+ __CLC_U_GENTYPE s = -(x >> (__CLC_GENSIZE - 1));
+ __CLC_U_GENTYPE result = ((s ^ x) >> (__CLC_GENSIZE - count)) ^ s;
+ return __CLC_AS_S_GENTYPE(result);
+}
diff --git a/libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.cl b/libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.cl
new file mode 100644
index 0000000000000..bf7db401034dc
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.cl
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/integer/clc_bitfield_extract_unsigned.h>
+
+#define __CLC_BODY <clc_bitfield_extract_unsigned.inc>
+#include <clc/integer/gentype.inc>
diff --git a/libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.inc b/libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.inc
new file mode 100644
index 0000000000000..bc81ce5c98b09
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bitfield_extract_unsigned.inc
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE
+__clc_bitfield_extract_unsigned(__CLC_GENTYPE base, uint offset, uint count) {
+ if (count == 0)
+ return 0;
+ __CLC_U_GENTYPE result = __CLC_AS_U_GENTYPE(base)
+ << (__CLC_GENSIZE - offset - count);
+ return result >> (__CLC_GENSIZE - count);
+}
diff --git a/libclc/clc/lib/generic/integer/clc_bitfield_insert.cl b/libclc/clc/lib/generic/integer/clc_bitfield_insert.cl
new file mode 100644
index 0000000000000..a40fc804f2187
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bitfield_insert.cl
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <clc/integer/clc_bitfield_insert.h>
+
+#define __CLC_BODY <clc_bitfield_insert.inc>
+#include <clc/integer/gentype.inc>
diff --git a/libclc/clc/lib/generic/integer/clc_bitfield_insert.inc b/libclc/clc/lib/generic/integer/clc_bitfield_insert.inc
new file mode 100644
index 0000000000000..ad8dac28750cc
--- /dev/null
+++ b/libclc/clc/lib/generic/integer/clc_bitfield_insert.inc
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_bitfield_insert(__CLC_GENTYPE base,
+ __CLC_GENTYPE insert,
+ uint offset,
+ uint count) {
+ __CLC_U_GENTYPE u_base = __CLC_AS_U_GENTYPE(base);
+ __CLC_U_GENTYPE u_insert = __CLC_AS_U_GENTYPE(insert);
+ __CLC_U_GENTYPE mask = (((__CLC_U_GENTYPE)1 << count) - (__CLC_U_GENTYPE)1)
+ << offset;
+ mask = count < __CLC_GENSIZE ? mask : ~(__CLC_U_GENTYPE)0;
+ __CLC_U_GENTYPE result = ((u_insert << offset) & mask) | (u_base & ~mask);
+ return __CLC_AS_GENTYPE(result);
+}
diff --git a/libclc/opencl/include/clc/opencl/integer/bit_reverse.h b/libclc/opencl/include/clc/opencl/integer/bit_reverse.h
new file mode 100644
index 0000000000000..8fe949cd9d573
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/integer/bit_reverse.h
@@ -0,0 +1,21 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_OPENCL_INTEGER_BIT_REVERSE_H__
+#define __CLC_OPENCL_INTEGER_BIT_REVERSE_H__
+
+#include <clc/opencl/opencl-base.h>
+
+#define FUNCTION bit_reverse
+#define __CLC_BODY <clc/shared/unary_decl.inc>
+
+#include <clc/integer/gentype.inc>
+
+#undef FUNCTION
+
+#endif // __CLC_OPENCL_INTEGER_BIT_REVERSE_H__
diff --git a/libclc/opencl/include/clc/opencl/integer/bitfield_extract.inc b/libclc/opencl/include/clc/opencl/integer/bitfield_extract.inc
new file mode 100644
index 0000000000000..c93eff08de0bc
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/integer/bitfield_extract.inc
@@ -0,0 +1,10 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DECL __RETTYPE FUNCTION(__CLC_GENTYPE base, uint offset,
+ uint count);
diff --git a/libclc/opencl/include/clc/opencl/integer/bitfield_extract_signed.h b/libclc/opencl/include/clc/opencl/integer/bitfield_extract_signed.h
new file mode 100644
index 0000000000000..94ae8c6b00353
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/integer/bitfield_extract_signed.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_OPENCL_INTEGER_BITFIELD_EXTRACT_SIGNED_H__
+#define __CLC_OPENCL_INTEGER_BITFIELD_EXTRACT_SIGNED_H__
+
+#include <clc/opencl/opencl-base.h>
+
+#define FUNCTION bitfield_extract_signed
+#define __RETTYPE __CLC_S_GENTYPE
+
+#define __CLC_BODY <clc/opencl/integer/bitfield_extract.inc>
+#include <clc/integer/gentype.inc>
+
+#undef __RETTYPE
+#undef FUNCTION
+
+#endif // __CLC_OPENCL_INTEGER_BITFIELD_EXTRACT_SIGNED_H__
diff --git a/libclc/opencl/include/clc/opencl/integer/bitfield_extract_unsigned.h b/libclc/opencl/include/clc/opencl/integer/bitfield_extract_unsigned.h
new file mode 100644
index 0000000000000..fb43f158cb7b6
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/integer/bitfield_extract_unsigned.h
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_OPENCL_INTEGER_BITFIELD_EXTRACT_UNSIGNED_H__
+#define __CLC_OPENCL_INTEGER_BITFIELD_EXTRACT_UNSIGNED_H__
+
+#include <clc/opencl/opencl-base.h>
+
+#define FUNCTION bitfield_extract_unsigned
+#define __RETTYPE __CLC_U_GENTYPE
+
+#define __CLC_BODY <clc/opencl/integer/bitfield_extract.inc>
+#include <clc/integer/gentype.inc>
+
+#undef __RETTYPE
+#undef FUNCTION
+
+#endif // __CLC_OPENCL_INTEGER_BITFIELD_EXTRACT_UNSIGNED_H__
diff --git a/libclc/opencl/include/clc/opencl/integer/bitfield_insert.h b/libclc/opencl/include/clc/opencl/integer/bitfield_insert.h
new file mode 100644
index 0000000000000..6409069aa4bce
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/integer/bitfield_insert.h
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __CLC_OPENCL_INTEGER_BITFIELD_INSERT_H__
+#define __CLC_OPENCL_INTEGER_BITFIELD_INSERT_H__
+
+#include <clc/opencl/opencl-base.h>
+
+#define __CLC_BODY <clc/integer/clc_bitfield_insert.inc>
+#include <clc/integer/gentype.inc>
+
+#undef FUNCTION
+
+#endif // __CLC_OPENCL_INTEGER_BITFIELD_INSERT_H__
diff --git a/libclc/opencl/include/clc/opencl/integer/bitfield_insert.inc b/libclc/opencl/include/clc/opencl/integer/bitfield_insert.inc
new file mode 100644
index 0000000000000..7d4143dab2a45
--- /dev/null
+++ b/libclc/opencl/include/clc/opencl/integer/bitfield_insert.inc
@@ -0,0 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE bitfield_insert(__CLC_GENTYPE base,
+ __CLC_GENTYPE insert,
+ uint offset, uint count);
diff --git a/libclc/opencl/lib/generic/SOURCES b/libclc/opencl/lib/generic/SOURCES
index 46ce6d6e36c24..a59a82ee325ec 100644
--- a/libclc/opencl/lib/generic/SOURCES
+++ b/libclc/opencl/lib/generic/SOURCES
@@ -43,6 +43,10 @@ geometric/normalize.cl
integer/abs.cl
integer/abs_diff.cl
integer/add_sat.cl
+integer/bitfield_extract_signed.cl
+integer/bitfield_extract_unsigned.cl
+integer/bitfield_insert.cl
+integer/bit_reverse.cl
integer/clz.cl
integer/ctz.cl
integer/hadd.cl
diff --git a/libclc/opencl/lib/generic/integer/bit_reverse.cl b/libclc/opencl/lib/generic/integer/bit_reverse.cl
new file mode 100644
index 0000000000000..23181b6b3eba5
--- /dev/null
+++ b/libclc/opencl/lib/generic/integer/bit_reverse.cl
@@ -0,0 +1,19 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef cl_khr_extended_bit_ops
+
+#include <clc/integer/clc_bit_reverse.h>
+#include <clc/opencl/integer/bit_reverse.h>
+
+#define FUNCTION bit_reverse
+#define __CLC_BODY <clc/shared/unary_def.inc>
+
+#include <clc/integer/gentype.inc>
+
+#endif // cl_khr_extended_bit_ops
diff --git a/libclc/opencl/lib/generic/integer/bitfield_extract.inc b/libclc/opencl/lib/generic/integer/bitfield_extract.inc
new file mode 100644
index 0000000000000..0262f67732afc
--- /dev/null
+++ b/libclc/opencl/lib/generic/integer/bitfield_extract.inc
@@ -0,0 +1,16 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __IMPL_FUNCTION
+#define __IMPL_FUNCTION(x) __CLC_CONCAT(__clc_, x)
+#endif
+
+_CLC_OVERLOAD _CLC_DEF __RETTYPE FUNCTION(__CLC_GENTYPE base, uint offset,
+ uint count) {
+ return __IMPL_FUNCTION(FUNCTION)(base, offset, count);
+}
diff --git a/libclc/opencl/lib/generic/integer/bitfield_extract_signed.cl b/libclc/opencl/lib/generic/integer/bitfield_extract_signed.cl
new file mode 100644
index 0000000000000..e16e861a167b8
--- /dev/null
+++ b/libclc/opencl/lib/generic/integer/bitfield_extract_signed.cl
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef cl_khr_extended_bit_ops
+
+#include <clc/integer/clc_bitfield_extract_signed.h>
+#include <clc/opencl/integer/bitfield_extract_signed.h>
+
+#define FUNCTION bitfield_extract_signed
+#define __RETTYPE __CLC_S_GENTYPE
+
+#define __CLC_BODY <bitfield_extract.inc>
+#include <clc/integer/gentype.inc>
+
+#endif // cl_khr_extended_bit_ops
diff --git a/libclc/opencl/lib/generic/integer/bitfield_extract_unsigned.cl b/libclc/opencl/lib/generic/integer/bitfield_extract_unsigned.cl
new file mode 100644
index 0000000000000..29ea70e720d17
--- /dev/null
+++ b/libclc/opencl/lib/generic/integer/bitfield_extract_unsigned.cl
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef cl_khr_extended_bit_ops
+
+#include <clc/integer/clc_bitfield_extract_unsigned.h>
+#include <clc/opencl/integer/bitfield_extract_unsigned.h>
+
+#define FUNCTION bitfield_extract_unsigned
+#define __RETTYPE __CLC_U_GENTYPE
+
+#define __CLC_BODY <bitfield_extract.inc>
+#include <clc/integer/gentype.inc>
+
+#endif // cl_khr_extended_bit_ops
diff --git a/libclc/opencl/lib/generic/integer/bitfield_insert.cl b/libclc/opencl/lib/generic/integer/bitfield_insert.cl
new file mode 100644
index 0000000000000..c054661177736
--- /dev/null
+++ b/libclc/opencl/lib/generic/integer/bitfield_insert.cl
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef cl_khr_extended_bit_ops
+
+#include <clc/integer/clc_bitfield_insert.h>
+#include <clc/opencl/integer/bitfield_insert.h>
+
+#define __CLC_BODY <bitfield_insert.inc>
+#include <clc/integer/gentype.inc>
+
+#endif // cl_khr_extended_bit_ops
diff --git a/libclc/opencl/lib/generic/integer/bitfield_insert.inc b/libclc/opencl/lib/generic/integer/bitfield_insert.inc
new file mode 100644
index 0000000000000..b1f45907a4361
--- /dev/null
+++ b/libclc/opencl/lib/generic/integer/bitfield_insert.inc
@@ -0,0 +1,13 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE bitfield_insert(__CLC_GENTYPE base,
+ __CLC_GENTYPE insert,
+ uint offset, uint count) {
+ return __clc_bitfield_insert(base, insert, offset, count);
+}
More information about the cfe-commits
mailing list