[llvm-branch-commits] [libclc] libclc: Add work group scan functions (PR #188829)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Mar 27 01:18:12 PDT 2026


================
@@ -0,0 +1,157 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#if defined(__CLC_SCALAR) &&                                                   \
+    (defined(__CLC_FPSIZE) || __CLC_GENSIZE == 32 || __CLC_GENSIZE == 64)
+
+static _CLC_OVERLOAD _CLC_CONST __CLC_GENTYPE sub_group_scan_op(
+    __CLC_GENTYPE x, enum __CLC_WORK_GROUP_SCAN_OP opcode, bool inclusive) {
+  switch (opcode) {
+  case __CLC_WORK_GROUP_SCAN_ADD:
+    return inclusive ? __clc_sub_group_scan_inclusive_add(x)
+                     : __clc_sub_group_scan_exclusive_add(x);
+  case __CLC_WORK_GROUP_SCAN_MIN:
+    return inclusive ? __clc_sub_group_scan_inclusive_min(x)
+                     : __clc_sub_group_scan_exclusive_min(x);
+  case __CLC_WORK_GROUP_SCAN_MAX:
+    return inclusive ? __clc_sub_group_scan_inclusive_max(x)
+                     : __clc_sub_group_scan_exclusive_max(x);
+  }
+}
+
+static _CLC_OVERLOAD _CLC_CONST __CLC_GENTYPE scan_op(
+    __CLC_GENTYPE x, __CLC_GENTYPE y, enum __CLC_WORK_GROUP_SCAN_OP opcode) {
+  switch (opcode) {
+  case __CLC_WORK_GROUP_SCAN_ADD:
+    return x + y;
+  case __CLC_WORK_GROUP_SCAN_MIN:
+#ifdef __CLC_FPSIZE
+    return __clc_fmin(x, y);
+#else
+    return __clc_min(x, y);
+#endif
+  case __CLC_WORK_GROUP_SCAN_MAX:
+#ifdef __CLC_FPSIZE
+    return __clc_fmax(x, y);
+#else
+    return __clc_max(x, y);
+#endif
+  }
+}
+
+#ifdef __CLC_FPSIZE
+static _CLC_OVERLOAD _CLC_CONST __CLC_GENTYPE work_group_scan_identity_value(
+    __CLC_GENTYPE x, enum __CLC_WORK_GROUP_SCAN_OP opcode) {
+  (void)x;
----------------
arsenm wrote:

It's needed to make this an overloadable function 

https://github.com/llvm/llvm-project/pull/188829


More information about the llvm-branch-commits mailing list