[libclc] [NFC][libclc] Merge atomic extension built-ins with identical name into a single file (PR #134489)

Wenju He via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 10 17:05:04 PDT 2025


https://github.com/wenju-he updated https://github.com/llvm/llvm-project/pull/134489

>From 310f537cb36fdb6cfe208860ad9c149c4a0c372a Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Sat, 5 Apr 2025 02:08:28 -0700
Subject: [PATCH 1/6] [NFC][libclc] Merge atomic extension built-ins with
 identical name into a single file

Similar to how cl_khr_fp64 and cl_khr_fp16 implementations are put in a
same file for math built-ins, this PR do the same to atom_* built-ins.

The main motivation is to prevent that two files with same base name
implementats different built-ins. In a follow-up PR, I'd like to relax
libclc_configure_lib_source to only compare filename instead of path for
overriding, since in our downstream the same category of built-ins, e.g.
math, are organized in several different folders.
---
 .../atom_add.h                                | 12 +++-
 .../atom_and.h                                | 12 +++-
 .../generic/include/clc/atomic/atom_cmpxchg.h | 36 +++++++++++
 .../atom_dec.h                                | 15 ++++-
 .../clc/{ => atomic}/atom_decl_int32.inc      |  7 +-
 .../clc/{ => atomic}/atom_decl_int64.inc      |  7 +-
 .../atom_inc.h                                | 15 ++++-
 .../atom_max.h                                | 13 +++-
 .../atom_min.h                                | 12 +++-
 .../atom_or.h                                 | 12 +++-
 .../atom_sub.h                                | 12 +++-
 .../atom_xchg.h                               | 12 +++-
 .../atom_xor.h                                | 12 +++-
 .../atom_cmpxchg.h                            | 10 ---
 .../atom_dec.h                                | 10 ---
 .../atom_inc.h                                | 10 ---
 .../clc/cl_khr_int64_base_atomics/atom_add.h  | 10 ---
 .../cl_khr_int64_base_atomics/atom_cmpxchg.h  | 12 ----
 .../clc/cl_khr_int64_base_atomics/atom_sub.h  | 10 ---
 .../clc/cl_khr_int64_base_atomics/atom_xchg.h | 10 ---
 .../cl_khr_int64_extended_atomics/atom_and.h  | 10 ---
 .../cl_khr_int64_extended_atomics/atom_max.h  | 10 ---
 .../cl_khr_int64_extended_atomics/atom_min.h  | 10 ---
 .../cl_khr_int64_extended_atomics/atom_or.h   | 10 ---
 .../cl_khr_int64_extended_atomics/atom_xor.h  | 10 ---
 .../atom_add.h                                | 11 ----
 .../atom_cmpxchg.h                            | 10 ---
 .../atom_dec.h                                | 10 ---
 .../atom_inc.h                                | 10 ---
 .../atom_sub.h                                | 11 ----
 .../atom_xchg.h                               | 11 ----
 .../atom_and.h                                | 11 ----
 .../atom_max.h                                | 11 ----
 .../atom_min.h                                | 11 ----
 .../atom_or.h                                 | 11 ----
 .../atom_xor.h                                | 11 ----
 libclc/generic/include/clc/clc.h              | 64 +++++--------------
 libclc/generic/lib/SOURCES                    | 46 ++++---------
 .../atom_add.cl                               | 14 +++-
 .../atom_and.cl                               | 14 +++-
 .../atom_cmpxchg.cl                           | 25 +++++++-
 .../atom_dec.cl                               | 26 +++++++-
 .../atom_inc.cl                               | 26 +++++++-
 .../lib/{ => atomic}/atom_int32_binary.inc    |  9 +--
 .../atom_max.cl                               | 14 +++-
 .../atom_min.cl                               | 14 +++-
 .../atom_or.cl                                | 12 +++-
 .../atom_sub.cl                               | 14 +++-
 .../atom_xchg.cl                              | 14 +++-
 .../atom_xor.cl                               | 12 +++-
 .../atom_add.cl                               | 11 ----
 .../atom_cmpxchg.cl                           | 17 -----
 .../atom_dec.cl                               | 17 -----
 .../atom_inc.cl                               | 17 -----
 .../atom_sub.cl                               | 11 ----
 .../atom_xchg.cl                              | 11 ----
 .../atom_and.cl                               | 11 ----
 .../atom_max.cl                               | 11 ----
 .../atom_min.cl                               | 11 ----
 .../atom_or.cl                                | 11 ----
 .../atom_xor.cl                               | 11 ----
 .../atom_add.cl                               | 11 ----
 .../atom_cmpxchg.cl                           | 17 -----
 .../atom_dec.cl                               | 17 -----
 .../atom_inc.cl                               | 17 -----
 .../atom_sub.cl                               | 11 ----
 .../atom_xchg.cl                              | 11 ----
 .../atom_and.cl                               | 11 ----
 .../atom_max.cl                               | 11 ----
 .../atom_min.cl                               | 11 ----
 .../atom_or.cl                                | 11 ----
 .../atom_xor.cl                               | 11 ----
 72 files changed, 361 insertions(+), 638 deletions(-)
 rename libclc/generic/include/clc/{cl_khr_global_int32_base_atomics => atomic}/atom_add.h (57%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_extended_atomics => atomic}/atom_and.h (56%)
 create mode 100644 libclc/generic/include/clc/atomic/atom_cmpxchg.h
 rename libclc/generic/include/clc/{cl_khr_int64_base_atomics => atomic}/atom_dec.h (52%)
 rename libclc/generic/include/clc/{ => atomic}/atom_decl_int32.inc (73%)
 rename libclc/generic/include/clc/{ => atomic}/atom_decl_int64.inc (74%)
 rename libclc/generic/include/clc/{cl_khr_int64_base_atomics => atomic}/atom_inc.h (52%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_extended_atomics => atomic}/atom_max.h (54%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_extended_atomics => atomic}/atom_min.h (56%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_extended_atomics => atomic}/atom_or.h (56%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_base_atomics => atomic}/atom_sub.h (57%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_base_atomics => atomic}/atom_xchg.h (57%)
 rename libclc/generic/include/clc/{cl_khr_global_int32_extended_atomics => atomic}/atom_xor.h (56%)
 delete mode 100644 libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_dec.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_inc.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_add.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_dec.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_inc.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_sub.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_and.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_max.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_min.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_or.h
 delete mode 100644 libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_xor.h
 rename libclc/generic/lib/{cl_khr_int64_base_atomics => atomic}/atom_add.cl (65%)
 rename libclc/generic/lib/{cl_khr_int64_extended_atomics => atomic}/atom_and.cl (64%)
 rename libclc/generic/lib/{cl_khr_int64_base_atomics => atomic}/atom_cmpxchg.cl (54%)
 rename libclc/generic/lib/{cl_khr_int64_base_atomics => atomic}/atom_dec.cl (54%)
 rename libclc/generic/lib/{cl_khr_int64_base_atomics => atomic}/atom_inc.cl (54%)
 rename libclc/generic/lib/{ => atomic}/atom_int32_binary.inc (64%)
 rename libclc/generic/lib/{cl_khr_int64_extended_atomics => atomic}/atom_max.cl (74%)
 rename libclc/generic/lib/{cl_khr_int64_extended_atomics => atomic}/atom_min.cl (74%)
 rename libclc/generic/lib/{cl_khr_int64_extended_atomics => atomic}/atom_or.cl (67%)
 rename libclc/generic/lib/{cl_khr_int64_base_atomics => atomic}/atom_sub.cl (65%)
 rename libclc/generic/lib/{cl_khr_int64_base_atomics => atomic}/atom_xchg.cl (64%)
 rename libclc/generic/lib/{cl_khr_int64_extended_atomics => atomic}/atom_xor.cl (67%)
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl
 delete mode 100644 libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl
 delete mode 100644 libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl

diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_add.h b/libclc/generic/include/clc/atomic/atom_add.h
similarity index 57%
rename from libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_add.h
rename to libclc/generic/include/clc/atomic/atom_add.h
index db6c09f563a38..05797b6eabe2e 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_add.h
+++ b/libclc/generic/include/clc/atomic/atom_add.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_base_atomics
 #define __CLC_FUNCTION atom_add
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_base_atomics
+#define __CLC_FUNCTION atom_add
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_base_atomics
+#define __CLC_FUNCTION atom_add
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_and.h b/libclc/generic/include/clc/atomic/atom_and.h
similarity index 56%
rename from libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_and.h
rename to libclc/generic/include/clc/atomic/atom_and.h
index 0d8c316d8f7fd..fd8435d07ef0d 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_and.h
+++ b/libclc/generic/include/clc/atomic/atom_and.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_and
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_FUNCTION atom_and
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_extended_atomics
+#define __CLC_FUNCTION atom_and
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/atomic/atom_cmpxchg.h b/libclc/generic/include/clc/atomic/atom_cmpxchg.h
new file mode 100644
index 0000000000000..e737e1858592e
--- /dev/null
+++ b/libclc/generic/include/clc/atomic/atom_cmpxchg.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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/clcfunc.h>
+#include <clc/clctypes.h>
+
+// cl_khr_global_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(volatile global int *p, int cmp,
+                                         int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int
+atom_cmpxchg(volatile global unsigned int *p, unsigned int cmp,
+             unsigned int val);
+
+// cl_khr_local_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(volatile local int *p, int cmp,
+                                         int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int
+atom_cmpxchg(volatile local unsigned int *p, unsigned int cmp,
+             unsigned int val);
+
+// cl_khr_int64_base_atomics
+_CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile global long *p, long cmp,
+                                          long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long
+atom_cmpxchg(volatile global unsigned long *p, unsigned long cmp,
+             unsigned long val);
+_CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile local long *p, long cmp,
+                                          long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long
+atom_cmpxchg(volatile local unsigned long *p, unsigned long cmp,
+             unsigned long val);
diff --git a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h b/libclc/generic/include/clc/atomic/atom_dec.h
similarity index 52%
rename from libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h
rename to libclc/generic/include/clc/atomic/atom_dec.h
index 4bf4e4eae5866..cc5f94e828613 100644
--- a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h
+++ b/libclc/generic/include/clc/atomic/atom_dec.h
@@ -6,7 +6,20 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <clc/clcfunc.h>
+#include <clc/clctypes.h>
+
+// cl_khr_global_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_dec(volatile global int *p);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile global unsigned int *p);
+
+// cl_khr_local_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_dec(volatile local int *p);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile local unsigned int *p);
+
+// cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_dec(volatile global long *p);
-_CLC_OVERLOAD _CLC_DECL unsigned long atom_dec(volatile global unsigned long *p);
+_CLC_OVERLOAD _CLC_DECL unsigned long
+atom_dec(volatile global unsigned long *p);
 _CLC_OVERLOAD _CLC_DECL long atom_dec(volatile local long *p);
 _CLC_OVERLOAD _CLC_DECL unsigned long atom_dec(volatile local unsigned long *p);
diff --git a/libclc/generic/include/clc/atom_decl_int32.inc b/libclc/generic/include/clc/atomic/atom_decl_int32.inc
similarity index 73%
rename from libclc/generic/include/clc/atom_decl_int32.inc
rename to libclc/generic/include/clc/atomic/atom_decl_int32.inc
index 6b666c58e99be..866d8903db816 100644
--- a/libclc/generic/include/clc/atom_decl_int32.inc
+++ b/libclc/generic/include/clc/atomic/atom_decl_int32.inc
@@ -6,8 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define __CLC_DECLARE_ATOM(ADDRSPACE, TYPE) \
-	_CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION (volatile ADDRSPACE TYPE *, TYPE);
+#include <clc/clcfunc.h>
+#include <clc/clctypes.h>
+
+#define __CLC_DECLARE_ATOM(ADDRSPACE, TYPE)                                    \
+  _CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION(volatile ADDRSPACE TYPE *, TYPE);
 
 __CLC_DECLARE_ATOM(__CLC_ADDRESS_SPACE, int)
 __CLC_DECLARE_ATOM(__CLC_ADDRESS_SPACE, uint)
diff --git a/libclc/generic/include/clc/atom_decl_int64.inc b/libclc/generic/include/clc/atomic/atom_decl_int64.inc
similarity index 74%
rename from libclc/generic/include/clc/atom_decl_int64.inc
rename to libclc/generic/include/clc/atomic/atom_decl_int64.inc
index f015cda424970..146de3412fc2e 100644
--- a/libclc/generic/include/clc/atom_decl_int64.inc
+++ b/libclc/generic/include/clc/atomic/atom_decl_int64.inc
@@ -6,8 +6,11 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define __CLC_DECLARE_ATOM(ADDRSPACE, TYPE) \
-	_CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION (volatile ADDRSPACE TYPE *, TYPE);
+#include <clc/clcfunc.h>
+#include <clc/clctypes.h>
+
+#define __CLC_DECLARE_ATOM(ADDRSPACE, TYPE)                                    \
+  _CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION(volatile ADDRSPACE TYPE *, TYPE);
 
 __CLC_DECLARE_ATOM(local, long)
 __CLC_DECLARE_ATOM(local, ulong)
diff --git a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h b/libclc/generic/include/clc/atomic/atom_inc.h
similarity index 52%
rename from libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h
rename to libclc/generic/include/clc/atomic/atom_inc.h
index d7a034640d420..093ae8a07d506 100644
--- a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h
+++ b/libclc/generic/include/clc/atomic/atom_inc.h
@@ -6,7 +6,20 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include <clc/clcfunc.h>
+#include <clc/clctypes.h>
+
+// cl_khr_global_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_inc(volatile global int *p);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile global unsigned int *p);
+
+// cl_khr_local_int32_base_atomics
+_CLC_OVERLOAD _CLC_DECL int atom_inc(volatile local int *p);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile local unsigned int *p);
+
+// cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_inc(volatile global long *p);
-_CLC_OVERLOAD _CLC_DECL unsigned long atom_inc(volatile global unsigned long *p);
+_CLC_OVERLOAD _CLC_DECL unsigned long
+atom_inc(volatile global unsigned long *p);
 _CLC_OVERLOAD _CLC_DECL long atom_inc(volatile local long *p);
 _CLC_OVERLOAD _CLC_DECL unsigned long atom_inc(volatile local unsigned long *p);
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_max.h b/libclc/generic/include/clc/atomic/atom_max.h
similarity index 54%
rename from libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_max.h
rename to libclc/generic/include/clc/atomic/atom_max.h
index f3af2eabd86e3..63bc91e4cd94e 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_max.h
+++ b/libclc/generic/include/clc/atomic/atom_max.h
@@ -6,6 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_max
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_FUNCTION atom_max
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_extended_atomics
+#define __CLC_FUNCTION atom_max
+#include <clc/atomic/atom_decl_int64.inc>
+#undef __CLC_FUNCTION
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_min.h b/libclc/generic/include/clc/atomic/atom_min.h
similarity index 56%
rename from libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_min.h
rename to libclc/generic/include/clc/atomic/atom_min.h
index e8418e161abfe..df91a6376d339 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_min.h
+++ b/libclc/generic/include/clc/atomic/atom_min.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_min
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_FUNCTION atom_min
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_extended_atomics
+#define __CLC_FUNCTION atom_min
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_or.h b/libclc/generic/include/clc/atomic/atom_or.h
similarity index 56%
rename from libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_or.h
rename to libclc/generic/include/clc/atomic/atom_or.h
index 34771728779c8..ef31f51ec1bd0 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_or.h
+++ b/libclc/generic/include/clc/atomic/atom_or.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_or
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_FUNCTION atom_or
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_extended_atomics
+#define __CLC_FUNCTION atom_or
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_sub.h b/libclc/generic/include/clc/atomic/atom_sub.h
similarity index 57%
rename from libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_sub.h
rename to libclc/generic/include/clc/atomic/atom_sub.h
index 81dab4926eaf1..0cc35a423c804 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_sub.h
+++ b/libclc/generic/include/clc/atomic/atom_sub.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_base_atomics
 #define __CLC_FUNCTION atom_sub
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_base_atomics
+#define __CLC_FUNCTION atom_sub
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_base_atomics
+#define __CLC_FUNCTION atom_sub
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h b/libclc/generic/include/clc/atomic/atom_xchg.h
similarity index 57%
rename from libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h
rename to libclc/generic/include/clc/atomic/atom_xchg.h
index 8964b9c151513..302f6821d20ab 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h
+++ b/libclc/generic/include/clc/atomic/atom_xchg.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_base_atomics
 #define __CLC_FUNCTION atom_xchg
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_base_atomics
+#define __CLC_FUNCTION atom_xchg
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_base_atomics
+#define __CLC_FUNCTION atom_xchg
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_xor.h b/libclc/generic/include/clc/atomic/atom_xor.h
similarity index 56%
rename from libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_xor.h
rename to libclc/generic/include/clc/atomic/atom_xor.h
index 17ca2e9f37c64..ed7fac0de8e85 100644
--- a/libclc/generic/include/clc/cl_khr_global_int32_extended_atomics/atom_xor.h
+++ b/libclc/generic/include/clc/atomic/atom_xor.h
@@ -6,6 +6,16 @@
 //
 //===----------------------------------------------------------------------===//
 
+// cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_xor
 #define __CLC_ADDRESS_SPACE global
-#include <clc/atom_decl_int32.inc>
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_FUNCTION atom_xor
+#define __CLC_ADDRESS_SPACE local
+#include <clc/atomic/atom_decl_int32.inc>
+
+// cl_khr_int64_extended_atomics
+#define __CLC_FUNCTION atom_xor
+#include <clc/atomic/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h b/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h
deleted file mode 100644
index b8b68aff758bb..0000000000000
--- a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 int atom_cmpxchg(volatile global int *p, int cmp, int val);
-_CLC_OVERLOAD _CLC_DECL unsigned int atom_cmpxchg(volatile global unsigned int *p, unsigned int cmp, unsigned int val);
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_dec.h b/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_dec.h
deleted file mode 100644
index f0576422f1ed6..0000000000000
--- a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_dec.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 int atom_dec(volatile global int *p);
-_CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile global unsigned int *p);
diff --git a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_inc.h b/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_inc.h
deleted file mode 100644
index f68758fa1561d..0000000000000
--- a/libclc/generic/include/clc/cl_khr_global_int32_base_atomics/atom_inc.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 int atom_inc(volatile global int *p);
-_CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile global unsigned int *p);
diff --git a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h b/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h
deleted file mode 100644
index 427006d0d57c6..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_add
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h b/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h
deleted file mode 100644
index 3e5317c22b8a1..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h
+++ /dev/null
@@ -1,12 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 long atom_cmpxchg(volatile global long *p, long cmp, long val);
-_CLC_OVERLOAD _CLC_DECL unsigned long atom_cmpxchg(volatile global unsigned long *p, unsigned long cmp, unsigned long val);
-_CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile local long *p, long cmp, long val);
-_CLC_OVERLOAD _CLC_DECL unsigned long atom_cmpxchg(volatile local unsigned long *p, unsigned long cmp, unsigned long val);
diff --git a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h b/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h
deleted file mode 100644
index 064801815dc95..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_sub
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h b/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h
deleted file mode 100644
index 4d4f3e3bcb774..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_xchg
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h b/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h
deleted file mode 100644
index 5077e626488b9..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_and
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h b/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h
deleted file mode 100644
index 5d338f82f7522..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_max
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h b/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h
deleted file mode 100644
index e3baeaf205266..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_min
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h b/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h
deleted file mode 100644
index 14d244ea55e3f..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_or
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h b/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h
deleted file mode 100644
index 0506fd4527e37..0000000000000
--- a/libclc/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_xor
-#include <clc/atom_decl_int64.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_add.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_add.h
deleted file mode 100644
index f681615c02ce9..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_add.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_add
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h
deleted file mode 100644
index 3b339e4a8d85f..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 int atom_cmpxchg(volatile local int *p, int cmp, int val);
-_CLC_OVERLOAD _CLC_DECL unsigned int atom_cmpxchg(volatile local unsigned int *p, unsigned int cmp, unsigned int val);
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_dec.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_dec.h
deleted file mode 100644
index 89a6b3528f2b3..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_dec.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 int atom_dec(volatile local int *p);
-_CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile local unsigned int *p);
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_inc.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_inc.h
deleted file mode 100644
index 1af31cea1521d..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_inc.h
+++ /dev/null
@@ -1,10 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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 int atom_inc(volatile local int *p);
-_CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile local unsigned int *p);
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_sub.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_sub.h
deleted file mode 100644
index ef74a3def7abd..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_sub.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_sub
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h b/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h
deleted file mode 100644
index 8a7662ffc9dbf..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_xchg
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_and.h b/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_and.h
deleted file mode 100644
index a6aa525df2bde..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_and.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_and
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_max.h b/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_max.h
deleted file mode 100644
index 6b0570a765b11..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_max.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_max
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_min.h b/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_min.h
deleted file mode 100644
index 4286dfb98ffc4..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_min.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_min
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_or.h b/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_or.h
deleted file mode 100644
index 7352fa9b9ef40..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_or.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_or
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_xor.h b/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_xor.h
deleted file mode 100644
index 8696e2b3752b6..0000000000000
--- a/libclc/generic/include/clc/cl_khr_local_int32_extended_atomics/atom_xor.h
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_FUNCTION atom_xor
-#define __CLC_ADDRESS_SPACE local
-#include <clc/atom_decl_int32.inc>
diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h
index 51a4f3413e725..8223b529f09f9 100644
--- a/libclc/generic/include/clc/clc.h
+++ b/libclc/generic/include/clc/clc.h
@@ -239,54 +239,22 @@
 #include <clc/atomic/atomic_xchg.h>
 #include <clc/atomic/atomic_xor.h>
 
-/* cl_khr_global_int32_base_atomics Extension Functions */
-#include <clc/cl_khr_global_int32_base_atomics/atom_add.h>
-#include <clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h>
-#include <clc/cl_khr_global_int32_base_atomics/atom_dec.h>
-#include <clc/cl_khr_global_int32_base_atomics/atom_inc.h>
-#include <clc/cl_khr_global_int32_base_atomics/atom_sub.h>
-#include <clc/cl_khr_global_int32_base_atomics/atom_xchg.h>
-
-/* cl_khr_global_int32_extended_atomics Extension Functions */
-#include <clc/cl_khr_global_int32_extended_atomics/atom_and.h>
-#include <clc/cl_khr_global_int32_extended_atomics/atom_max.h>
-#include <clc/cl_khr_global_int32_extended_atomics/atom_min.h>
-#include <clc/cl_khr_global_int32_extended_atomics/atom_or.h>
-#include <clc/cl_khr_global_int32_extended_atomics/atom_xor.h>
-
-/* cl_khr_local_int32_base_atomics Extension Functions */
-#include <clc/cl_khr_local_int32_base_atomics/atom_add.h>
-#include <clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h>
-#include <clc/cl_khr_local_int32_base_atomics/atom_dec.h>
-#include <clc/cl_khr_local_int32_base_atomics/atom_inc.h>
-#include <clc/cl_khr_local_int32_base_atomics/atom_sub.h>
-#include <clc/cl_khr_local_int32_base_atomics/atom_xchg.h>
-
-/* cl_khr_local_int32_extended_atomics Extension Functions */
-#include <clc/cl_khr_local_int32_extended_atomics/atom_and.h>
-#include <clc/cl_khr_local_int32_extended_atomics/atom_max.h>
-#include <clc/cl_khr_local_int32_extended_atomics/atom_min.h>
-#include <clc/cl_khr_local_int32_extended_atomics/atom_or.h>
-#include <clc/cl_khr_local_int32_extended_atomics/atom_xor.h>
-
-/* cl_khr_int64_base_atomics Extension Functions */
-#ifdef cl_khr_int64_base_atomics
-#include <clc/cl_khr_int64_base_atomics/atom_add.h>
-#include <clc/cl_khr_int64_base_atomics/atom_cmpxchg.h>
-#include <clc/cl_khr_int64_base_atomics/atom_dec.h>
-#include <clc/cl_khr_int64_base_atomics/atom_inc.h>
-#include <clc/cl_khr_int64_base_atomics/atom_sub.h>
-#include <clc/cl_khr_int64_base_atomics/atom_xchg.h>
-#endif
-
-/* cl_khr_int64_extended_atomics Extension Functions */
-#ifdef cl_khr_int64_base_atomics
-#include <clc/cl_khr_int64_extended_atomics/atom_and.h>
-#include <clc/cl_khr_int64_extended_atomics/atom_max.h>
-#include <clc/cl_khr_int64_extended_atomics/atom_min.h>
-#include <clc/cl_khr_int64_extended_atomics/atom_or.h>
-#include <clc/cl_khr_int64_extended_atomics/atom_xor.h>
-#endif
+/* cl_khr_global_int32_base_atomics, cl_khr_local_int32_base_atomics and
+ * cl_khr_int64_base_atomics Extension Functions */
+#include <clc/atomic/atom_add.h>
+#include <clc/atomic/atom_cmpxchg.h>
+#include <clc/atomic/atom_dec.h>
+#include <clc/atomic/atom_inc.h>
+#include <clc/atomic/atom_sub.h>
+#include <clc/atomic/atom_xchg.h>
+
+/* cl_khr_global_int32_extended_atomics, cl_khr_local_int32_extended_atomics and
+ * cl_khr_int64_extended_atomics Extension Functions */
+#include <clc/atomic/atom_and.h>
+#include <clc/atomic/atom_max.h>
+#include <clc/atomic/atom_min.h>
+#include <clc/atomic/atom_or.h>
+#include <clc/atomic/atom_xor.h>
 
 /* 6.12.12 Miscellaneous Vector Functions */
 #include <clc/misc/shuffle.h>
diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES
index 5f473ff8b9424..1340e08453acf 100644
--- a/libclc/generic/lib/SOURCES
+++ b/libclc/generic/lib/SOURCES
@@ -4,6 +4,17 @@ async/async_work_group_copy.cl
 async/async_work_group_strided_copy.cl
 async/prefetch.cl
 async/wait_group_events.cl
+atomic/atom_add.cl
+atomic/atom_and.cl
+atomic/atom_cmpxchg.cl
+atomic/atom_dec.cl
+atomic/atom_inc.cl
+atomic/atom_max.cl
+atomic/atom_min.cl
+atomic/atom_or.cl
+atomic/atom_sub.cl
+atomic/atom_xchg.cl
+atomic/atom_xor.cl
 atomic/atomic_add.cl
 atomic/atomic_and.cl
 atomic/atomic_cmpxchg.cl
@@ -13,41 +24,8 @@ atomic/atomic_max.cl
 atomic/atomic_min.cl
 atomic/atomic_or.cl
 atomic/atomic_sub.cl
-atomic/atomic_xor.cl
 atomic/atomic_xchg.cl
-cl_khr_global_int32_base_atomics/atom_add.cl
-cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
-cl_khr_global_int32_base_atomics/atom_dec.cl
-cl_khr_global_int32_base_atomics/atom_inc.cl
-cl_khr_global_int32_base_atomics/atom_sub.cl
-cl_khr_global_int32_base_atomics/atom_xchg.cl
-cl_khr_global_int32_extended_atomics/atom_and.cl
-cl_khr_global_int32_extended_atomics/atom_max.cl
-cl_khr_global_int32_extended_atomics/atom_min.cl
-cl_khr_global_int32_extended_atomics/atom_or.cl
-cl_khr_global_int32_extended_atomics/atom_xor.cl
-cl_khr_local_int32_base_atomics/atom_add.cl
-cl_khr_local_int32_base_atomics/atom_cmpxchg.cl
-cl_khr_local_int32_base_atomics/atom_dec.cl
-cl_khr_local_int32_base_atomics/atom_inc.cl
-cl_khr_local_int32_base_atomics/atom_sub.cl
-cl_khr_local_int32_base_atomics/atom_xchg.cl
-cl_khr_local_int32_extended_atomics/atom_and.cl
-cl_khr_local_int32_extended_atomics/atom_max.cl
-cl_khr_local_int32_extended_atomics/atom_min.cl
-cl_khr_local_int32_extended_atomics/atom_or.cl
-cl_khr_local_int32_extended_atomics/atom_xor.cl
-cl_khr_int64_base_atomics/atom_add.cl
-cl_khr_int64_base_atomics/atom_cmpxchg.cl
-cl_khr_int64_base_atomics/atom_dec.cl
-cl_khr_int64_base_atomics/atom_inc.cl
-cl_khr_int64_base_atomics/atom_sub.cl
-cl_khr_int64_base_atomics/atom_xchg.cl
-cl_khr_int64_extended_atomics/atom_and.cl
-cl_khr_int64_extended_atomics/atom_max.cl
-cl_khr_int64_extended_atomics/atom_min.cl
-cl_khr_int64_extended_atomics/atom_or.cl
-cl_khr_int64_extended_atomics/atom_xor.cl
+atomic/atomic_xor.cl
 common/degrees.cl
 common/mix.cl
 common/radians.cl
diff --git a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_add.cl b/libclc/generic/lib/atomic/atom_add.cl
similarity index 65%
rename from libclc/generic/lib/cl_khr_int64_base_atomics/atom_add.cl
rename to libclc/generic/lib/atomic/atom_add.cl
index e06c21d4acb6c..89650ddf96d21 100644
--- a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_add.cl
+++ b/libclc/generic/lib/atomic/atom_add.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_add.h>
+
+// cl_khr_global_int32_base_atomics
+#define __CLC_ATOMIC_OP add
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_base_atomics
+#define __CLC_ATOMIC_OP add
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_base_atomics
 
@@ -21,4 +31,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_and.cl b/libclc/generic/lib/atomic/atom_and.cl
similarity index 64%
rename from libclc/generic/lib/cl_khr_int64_extended_atomics/atom_and.cl
rename to libclc/generic/lib/atomic/atom_and.cl
index 4c5dff5608d2d..e683a8bf9d501 100644
--- a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_and.cl
+++ b/libclc/generic/lib/atomic/atom_and.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_and.h>
+
+// cl_khr_global_int32_extended_atomics
+#define __CLC_ATOMIC_OP and
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_ATOMIC_OP and
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_extended_atomics
 
@@ -21,4 +31,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_local_int32_extended_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl b/libclc/generic/lib/atomic/atom_cmpxchg.cl
similarity index 54%
rename from libclc/generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl
rename to libclc/generic/lib/atomic/atom_cmpxchg.cl
index 21260103a673b..3d3cff358e3ad 100644
--- a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl
+++ b/libclc/generic/lib/atomic/atom_cmpxchg.cl
@@ -6,7 +6,28 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_cmpxchg.h>
+#include <clc/atomic/atomic_cmpxchg.h>
+
+// cl_khr_global_int32_base_atomics
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile global TYPE *p, TYPE cmp, TYPE val) { \
+  return atomic_cmpxchg(p, cmp, val); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
+#undef IMPL
+
+// cl_khr_local_int32_base_atomics
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile local TYPE *p, TYPE cmp, TYPE val) { \
+  return atomic_cmpxchg(p, cmp, val); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
+#undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
 
@@ -21,4 +42,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_dec.cl b/libclc/generic/lib/atomic/atom_dec.cl
similarity index 54%
rename from libclc/generic/lib/cl_khr_int64_base_atomics/atom_dec.cl
rename to libclc/generic/lib/atomic/atom_dec.cl
index a594f570ca851..926615a9423c3 100644
--- a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_dec.cl
+++ b/libclc/generic/lib/atomic/atom_dec.cl
@@ -6,7 +6,29 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_dec.h>
+#include <clc/atomic/atom_sub.h>
+#include <clc/atomic/atomic_dec.h>
+
+// cl_khr_global_int32_base_atomics
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile global TYPE *p) { \
+  return atomic_dec(p); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
+#undef IMPL
+
+// cl_khr_local_int32_base_atomics
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile local TYPE *p) { \
+  return atomic_dec(p); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
+#undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
 
@@ -21,4 +43,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_inc.cl b/libclc/generic/lib/atomic/atom_inc.cl
similarity index 54%
rename from libclc/generic/lib/cl_khr_int64_base_atomics/atom_inc.cl
rename to libclc/generic/lib/atomic/atom_inc.cl
index 2aa2f9d790770..d90480882ed82 100644
--- a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_inc.cl
+++ b/libclc/generic/lib/atomic/atom_inc.cl
@@ -6,7 +6,29 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_inc.h>
+#include <clc/atomic/atom_add.h>
+#include <clc/atomic/atomic_inc.h>
+
+// cl_khr_global_int32_base_atomics
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile global TYPE *p) { \
+  return atomic_inc(p); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
+#undef IMPL
+
+// cl_khr_local_int32_base_atomics
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile local TYPE *p) { \
+  return atomic_inc(p); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
+#undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
 
@@ -21,4 +43,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/atom_int32_binary.inc b/libclc/generic/lib/atomic/atom_int32_binary.inc
similarity index 64%
rename from libclc/generic/lib/atom_int32_binary.inc
rename to libclc/generic/lib/atomic/atom_int32_binary.inc
index dac9d19842dcb..81e6a8ebc7c8a 100644
--- a/libclc/generic/lib/atom_int32_binary.inc
+++ b/libclc/generic/lib/atomic/atom_int32_binary.inc
@@ -9,10 +9,11 @@
 #include <clc/clc.h>
 #include <clc/utils.h>
 
-#define __CLC_ATOM_IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE __CLC_XCONCAT(atom_, __CLC_ATOMIC_OP) (volatile AS TYPE *p, TYPE val) { \
-  return __CLC_XCONCAT(atomic_, __CLC_ATOMIC_OP) (p, val); \
-}
+#define __CLC_ATOM_IMPL(AS, TYPE)                                              \
+  _CLC_OVERLOAD _CLC_DEF TYPE __CLC_XCONCAT(atom_, __CLC_ATOMIC_OP)(           \
+      volatile AS TYPE * p, TYPE val) {                                        \
+    return __CLC_XCONCAT(atomic_, __CLC_ATOMIC_OP)(p, val);                    \
+  }
 
 __CLC_ATOM_IMPL(__CLC_ATOMIC_ADDRESS_SPACE, int)
 __CLC_ATOM_IMPL(__CLC_ATOMIC_ADDRESS_SPACE, uint)
diff --git a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_max.cl b/libclc/generic/lib/atomic/atom_max.cl
similarity index 74%
rename from libclc/generic/lib/cl_khr_int64_extended_atomics/atom_max.cl
rename to libclc/generic/lib/atomic/atom_max.cl
index 5440f0d89165d..c90da3e0b64c7 100644
--- a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_max.cl
+++ b/libclc/generic/lib/atomic/atom_max.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_max.h>
+
+// cl_khr_global_int32_extended_atomics
+#define __CLC_ATOMIC_OP max
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_ATOMIC_OP max
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_extended_atomics
 
@@ -26,4 +36,4 @@ IMPL(local, long, max)
 IMPL(local, unsigned long, umax)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_min.cl b/libclc/generic/lib/atomic/atom_min.cl
similarity index 74%
rename from libclc/generic/lib/cl_khr_int64_extended_atomics/atom_min.cl
rename to libclc/generic/lib/atomic/atom_min.cl
index 27f4112b9d994..5b2ebb2408392 100644
--- a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_min.cl
+++ b/libclc/generic/lib/atomic/atom_min.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_min.h>
+
+// cl_khr_global_int32_extended_atomics
+#define __CLC_ATOMIC_OP min
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_ATOMIC_OP min
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_extended_atomics
 
@@ -26,4 +36,4 @@ IMPL(local, long, min)
 IMPL(local, unsigned long, umin)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_or.cl b/libclc/generic/lib/atomic/atom_or.cl
similarity index 67%
rename from libclc/generic/lib/cl_khr_int64_extended_atomics/atom_or.cl
rename to libclc/generic/lib/atomic/atom_or.cl
index b822a77172802..7c3e9d2fcb632 100644
--- a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_or.cl
+++ b/libclc/generic/lib/atomic/atom_or.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_or.h>
+
+// cl_khr_global_int32_extended_atomics
+#define __CLC_ATOMIC_OP or
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_ATOMIC_OP or
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_extended_atomics
 
diff --git a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl b/libclc/generic/lib/atomic/atom_sub.cl
similarity index 65%
rename from libclc/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl
rename to libclc/generic/lib/atomic/atom_sub.cl
index a496c42105065..0eb1b6e06a530 100644
--- a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl
+++ b/libclc/generic/lib/atomic/atom_sub.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_sub.h>
+
+// cl_khr_global_int32_base_atomics
+#define __CLC_ATOMIC_OP sub
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_base_atomics
+#define __CLC_ATOMIC_OP sub
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_base_atomics
 
@@ -21,4 +31,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl b/libclc/generic/lib/atomic/atom_xchg.cl
similarity index 64%
rename from libclc/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl
rename to libclc/generic/lib/atomic/atom_xchg.cl
index 0bacfc863f5a4..8d101754eaa7d 100644
--- a/libclc/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl
+++ b/libclc/generic/lib/atomic/atom_xchg.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_xchg.h>
+
+// cl_khr_global_int32_base_atomics
+#define __CLC_ATOMIC_OP xchg
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_base_atomics
+#define __CLC_ATOMIC_OP xchg
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_base_atomics
 
@@ -21,4 +31,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_xor.cl b/libclc/generic/lib/atomic/atom_xor.cl
similarity index 67%
rename from libclc/generic/lib/cl_khr_int64_extended_atomics/atom_xor.cl
rename to libclc/generic/lib/atomic/atom_xor.cl
index f1dd28d796d0a..162ae544fa22a 100644
--- a/libclc/generic/lib/cl_khr_int64_extended_atomics/atom_xor.cl
+++ b/libclc/generic/lib/atomic/atom_xor.cl
@@ -6,7 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/clc.h>
+#include <clc/atomic/atom_xor.h>
+
+// cl_khr_global_int32_extended_atomics
+#define __CLC_ATOMIC_OP xor
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "atom_int32_binary.inc"
+
+// cl_khr_local_int32_extended_atomics
+#define __CLC_ATOMIC_OP xor
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "atom_int32_binary.inc"
 
 #ifdef cl_khr_int64_extended_atomics
 
diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl
deleted file mode 100644
index 6c6c919892aa9..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP add
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
deleted file mode 100644
index eb78b878109b6..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
+++ /dev/null
@@ -1,17 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile global TYPE *p, TYPE cmp, TYPE val) { \
-  return atomic_cmpxchg(p, cmp, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl
deleted file mode 100644
index 82b77ff31ce87..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl
+++ /dev/null
@@ -1,17 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile global TYPE *p) { \
-  return atomic_dec(p); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl
deleted file mode 100644
index f2147ccaf8d65..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl
+++ /dev/null
@@ -1,17 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile global TYPE *p) { \
-  return atomic_inc(p); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl
deleted file mode 100644
index 521d3cc633b30..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP sub
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl b/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
deleted file mode 100644
index 5e68b489171fe..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP xchg
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl b/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl
deleted file mode 100644
index fbfba0b1b698f..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP and
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl b/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl
deleted file mode 100644
index 78f98d7c19146..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP max
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl b/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl
deleted file mode 100644
index f031585cc246a..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP min
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl b/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl
deleted file mode 100644
index 95aa2c66a3276..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP or
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl b/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl
deleted file mode 100644
index 0613f08654940..0000000000000
--- a/libclc/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP xor
-#define __CLC_ATOMIC_ADDRESS_SPACE global
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl
deleted file mode 100644
index c561cc3f839d9..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP add
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl
deleted file mode 100644
index efa997e5b7021..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl
+++ /dev/null
@@ -1,17 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile local TYPE *p, TYPE cmp, TYPE val) { \
-  return atomic_cmpxchg(p, cmp, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl
deleted file mode 100644
index f3b30554ea9c8..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl
+++ /dev/null
@@ -1,17 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile local TYPE *p) { \
-  return atomic_dec(p); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl
deleted file mode 100644
index 9660f79046b38..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl
+++ /dev/null
@@ -1,17 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile local TYPE *p) { \
-  return atomic_inc(p); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl
deleted file mode 100644
index 44a8703aaa6cb..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP sub
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl b/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
deleted file mode 100644
index ae6c82036b7a7..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP xchg
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl b/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl
deleted file mode 100644
index c3cfd460338a8..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP and
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl b/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl
deleted file mode 100644
index 80dabbb239a77..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP max
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl b/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl
deleted file mode 100644
index 895dc8a256796..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP min
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl b/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl
deleted file mode 100644
index ee02b942a3397..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP or
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"
diff --git a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl b/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl
deleted file mode 100644
index d169899aa0784..0000000000000
--- a/libclc/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl
+++ /dev/null
@@ -1,11 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#define __CLC_ATOMIC_OP xor
-#define __CLC_ATOMIC_ADDRESS_SPACE local
-#include "../atom_int32_binary.inc"

>From 0d1a5a61aacba530086d820169d07a523482654c Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Tue, 8 Apr 2025 17:57:04 -0700
Subject: [PATCH 2/6] guard cl_khr_int64_base_atomics in headers

---
 libclc/generic/include/clc/atomic/atom_add.h     | 3 ++-
 libclc/generic/include/clc/atomic/atom_and.h     | 3 ++-
 libclc/generic/include/clc/atomic/atom_cmpxchg.h | 3 ++-
 libclc/generic/include/clc/atomic/atom_dec.h     | 3 ++-
 libclc/generic/include/clc/atomic/atom_inc.h     | 3 ++-
 libclc/generic/include/clc/atomic/atom_max.h     | 4 ++--
 libclc/generic/include/clc/atomic/atom_min.h     | 3 ++-
 libclc/generic/include/clc/atomic/atom_or.h      | 3 ++-
 libclc/generic/include/clc/atomic/atom_sub.h     | 3 ++-
 libclc/generic/include/clc/atomic/atom_xchg.h    | 3 ++-
 libclc/generic/include/clc/atomic/atom_xor.h     | 3 ++-
 11 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/libclc/generic/include/clc/atomic/atom_add.h b/libclc/generic/include/clc/atomic/atom_add.h
index 05797b6eabe2e..d6be0bffc8b48 100644
--- a/libclc/generic/include/clc/atomic/atom_add.h
+++ b/libclc/generic/include/clc/atomic/atom_add.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_add
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_and.h b/libclc/generic/include/clc/atomic/atom_and.h
index fd8435d07ef0d..a3dbb91995619 100644
--- a/libclc/generic/include/clc/atomic/atom_and.h
+++ b/libclc/generic/include/clc/atomic/atom_and.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_extended_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_and
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_cmpxchg.h b/libclc/generic/include/clc/atomic/atom_cmpxchg.h
index e737e1858592e..7074e3a099729 100644
--- a/libclc/generic/include/clc/atomic/atom_cmpxchg.h
+++ b/libclc/generic/include/clc/atomic/atom_cmpxchg.h
@@ -23,7 +23,7 @@ _CLC_OVERLOAD _CLC_DECL unsigned int
 atom_cmpxchg(volatile local unsigned int *p, unsigned int cmp,
              unsigned int val);
 
-// cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile global long *p, long cmp,
                                           long val);
 _CLC_OVERLOAD _CLC_DECL unsigned long
@@ -34,3 +34,4 @@ _CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile local long *p, long cmp,
 _CLC_OVERLOAD _CLC_DECL unsigned long
 atom_cmpxchg(volatile local unsigned long *p, unsigned long cmp,
              unsigned long val);
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_dec.h b/libclc/generic/include/clc/atomic/atom_dec.h
index cc5f94e828613..dca0231eb2554 100644
--- a/libclc/generic/include/clc/atomic/atom_dec.h
+++ b/libclc/generic/include/clc/atomic/atom_dec.h
@@ -17,9 +17,10 @@ _CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile global unsigned int *p);
 _CLC_OVERLOAD _CLC_DECL int atom_dec(volatile local int *p);
 _CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile local unsigned int *p);
 
-// cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_dec(volatile global long *p);
 _CLC_OVERLOAD _CLC_DECL unsigned long
 atom_dec(volatile global unsigned long *p);
 _CLC_OVERLOAD _CLC_DECL long atom_dec(volatile local long *p);
 _CLC_OVERLOAD _CLC_DECL unsigned long atom_dec(volatile local unsigned long *p);
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_inc.h b/libclc/generic/include/clc/atomic/atom_inc.h
index 093ae8a07d506..04dd404647b35 100644
--- a/libclc/generic/include/clc/atomic/atom_inc.h
+++ b/libclc/generic/include/clc/atomic/atom_inc.h
@@ -17,9 +17,10 @@ _CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile global unsigned int *p);
 _CLC_OVERLOAD _CLC_DECL int atom_inc(volatile local int *p);
 _CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile local unsigned int *p);
 
-// cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_inc(volatile global long *p);
 _CLC_OVERLOAD _CLC_DECL unsigned long
 atom_inc(volatile global unsigned long *p);
 _CLC_OVERLOAD _CLC_DECL long atom_inc(volatile local long *p);
 _CLC_OVERLOAD _CLC_DECL unsigned long atom_inc(volatile local unsigned long *p);
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_max.h b/libclc/generic/include/clc/atomic/atom_max.h
index 63bc91e4cd94e..50c43fece83b0 100644
--- a/libclc/generic/include/clc/atomic/atom_max.h
+++ b/libclc/generic/include/clc/atomic/atom_max.h
@@ -16,7 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_extended_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_max
 #include <clc/atomic/atom_decl_int64.inc>
-#undef __CLC_FUNCTION
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_min.h b/libclc/generic/include/clc/atomic/atom_min.h
index df91a6376d339..107e1bc770273 100644
--- a/libclc/generic/include/clc/atomic/atom_min.h
+++ b/libclc/generic/include/clc/atomic/atom_min.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_extended_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_min
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_or.h b/libclc/generic/include/clc/atomic/atom_or.h
index ef31f51ec1bd0..a2e80a7c6ae45 100644
--- a/libclc/generic/include/clc/atomic/atom_or.h
+++ b/libclc/generic/include/clc/atomic/atom_or.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_extended_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_or
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_sub.h b/libclc/generic/include/clc/atomic/atom_sub.h
index 0cc35a423c804..faf18dc3813d9 100644
--- a/libclc/generic/include/clc/atomic/atom_sub.h
+++ b/libclc/generic/include/clc/atomic/atom_sub.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_sub
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_xchg.h b/libclc/generic/include/clc/atomic/atom_xchg.h
index 302f6821d20ab..fe0496cdbab73 100644
--- a/libclc/generic/include/clc/atomic/atom_xchg.h
+++ b/libclc/generic/include/clc/atomic/atom_xchg.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_xchg
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_xor.h b/libclc/generic/include/clc/atomic/atom_xor.h
index ed7fac0de8e85..fa1a683269c5d 100644
--- a/libclc/generic/include/clc/atomic/atom_xor.h
+++ b/libclc/generic/include/clc/atomic/atom_xor.h
@@ -16,6 +16,7 @@
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
 
-// cl_khr_int64_extended_atomics
+#ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_xor
 #include <clc/atomic/atom_decl_int64.inc>
+#endif // cl_khr_int64_base_atomics

>From 3c3f06516b07c34b3211412904df05eef363fb40 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Tue, 8 Apr 2025 18:34:12 -0700
Subject: [PATCH 3/6] merge global_int32/local_int32 macros

---
 libclc/generic/lib/atomic/atom_cmpxchg.cl | 21 +++++++--------------
 libclc/generic/lib/atomic/atom_dec.cl     | 21 +++++++--------------
 libclc/generic/lib/atomic/atom_inc.cl     | 21 +++++++--------------
 3 files changed, 21 insertions(+), 42 deletions(-)

diff --git a/libclc/generic/lib/atomic/atom_cmpxchg.cl b/libclc/generic/lib/atomic/atom_cmpxchg.cl
index 3d3cff358e3ad..ad722c3a1bec9 100644
--- a/libclc/generic/lib/atomic/atom_cmpxchg.cl
+++ b/libclc/generic/lib/atomic/atom_cmpxchg.cl
@@ -9,24 +9,17 @@
 #include <clc/atomic/atom_cmpxchg.h>
 #include <clc/atomic/atomic_cmpxchg.h>
 
-// cl_khr_global_int32_base_atomics
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile global TYPE *p, TYPE cmp, TYPE val) { \
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile AS TYPE *p, TYPE cmp, TYPE val) { \
   return atomic_cmpxchg(p, cmp, val); \
 }
 
-IMPL(int)
-IMPL(unsigned int)
-#undef IMPL
-
+// cl_khr_global_int32_base_atomics
+IMPL(global, int)
+IMPL(global, unsigned int)
 // cl_khr_local_int32_base_atomics
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile local TYPE *p, TYPE cmp, TYPE val) { \
-  return atomic_cmpxchg(p, cmp, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+IMPL(local, int)
+IMPL(local, unsigned int)
 #undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/atomic/atom_dec.cl b/libclc/generic/lib/atomic/atom_dec.cl
index 926615a9423c3..06b9a4e24593d 100644
--- a/libclc/generic/lib/atomic/atom_dec.cl
+++ b/libclc/generic/lib/atomic/atom_dec.cl
@@ -10,24 +10,17 @@
 #include <clc/atomic/atom_sub.h>
 #include <clc/atomic/atomic_dec.h>
 
-// cl_khr_global_int32_base_atomics
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile global TYPE *p) { \
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile AS TYPE *p) { \
   return atomic_dec(p); \
 }
 
-IMPL(int)
-IMPL(unsigned int)
-#undef IMPL
-
+// cl_khr_global_int32_base_atomics
+IMPL(global, int)
+IMPL(global, unsigned int)
 // cl_khr_local_int32_base_atomics
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile local TYPE *p) { \
-  return atomic_dec(p); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+IMPL(local, int)
+IMPL(local, unsigned int)
 #undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/atomic/atom_inc.cl b/libclc/generic/lib/atomic/atom_inc.cl
index d90480882ed82..f93b2dd45dae1 100644
--- a/libclc/generic/lib/atomic/atom_inc.cl
+++ b/libclc/generic/lib/atomic/atom_inc.cl
@@ -10,24 +10,17 @@
 #include <clc/atomic/atom_add.h>
 #include <clc/atomic/atomic_inc.h>
 
-// cl_khr_global_int32_base_atomics
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile global TYPE *p) { \
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile AS TYPE *p) { \
   return atomic_inc(p); \
 }
 
-IMPL(int)
-IMPL(unsigned int)
-#undef IMPL
-
+// cl_khr_global_int32_base_atomics
+IMPL(global, int)
+IMPL(global, unsigned int)
 // cl_khr_local_int32_base_atomics
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile local TYPE *p) { \
-  return atomic_inc(p); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+IMPL(local, int)
+IMPL(local, unsigned int)
 #undef IMPL
 
 #ifdef cl_khr_int64_base_atomics

>From 46d2df78452cf3e4518e847a60330d6e32ed2ad4 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Tue, 8 Apr 2025 18:36:21 -0700
Subject: [PATCH 4/6] clang-format

---
 libclc/generic/lib/atomic/atom_add.cl     |  8 ++++----
 libclc/generic/lib/atomic/atom_and.cl     |  8 ++++----
 libclc/generic/lib/atomic/atom_cmpxchg.cl | 18 ++++++++++--------
 libclc/generic/lib/atomic/atom_dec.cl     | 16 ++++++++--------
 libclc/generic/lib/atomic/atom_inc.cl     | 18 +++++++++---------
 libclc/generic/lib/atomic/atom_max.cl     | 17 ++++++++++-------
 libclc/generic/lib/atomic/atom_min.cl     | 17 ++++++++++-------
 libclc/generic/lib/atomic/atom_or.cl      |  8 ++++----
 libclc/generic/lib/atomic/atom_sub.cl     |  8 ++++----
 libclc/generic/lib/atomic/atom_xchg.cl    |  8 ++++----
 libclc/generic/lib/atomic/atom_xor.cl     |  8 ++++----
 11 files changed, 71 insertions(+), 63 deletions(-)

diff --git a/libclc/generic/lib/atomic/atom_add.cl b/libclc/generic/lib/atomic/atom_add.cl
index 89650ddf96d21..bd835c00c5121 100644
--- a/libclc/generic/lib/atomic/atom_add.cl
+++ b/libclc/generic/lib/atomic/atom_add.cl
@@ -20,10 +20,10 @@
 
 #ifdef cl_khr_int64_base_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_add(volatile AS TYPE *p, TYPE val) { \
-  return __sync_fetch_and_add_8(p, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_add(volatile AS TYPE *p, TYPE val) {        \
+    return __sync_fetch_and_add_8(p, val);                                     \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_and.cl b/libclc/generic/lib/atomic/atom_and.cl
index e683a8bf9d501..7be821e6be569 100644
--- a/libclc/generic/lib/atomic/atom_and.cl
+++ b/libclc/generic/lib/atomic/atom_and.cl
@@ -20,10 +20,10 @@
 
 #ifdef cl_khr_int64_extended_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_and(volatile AS TYPE *p, TYPE val) { \
-  return __sync_fetch_and_and_8(p, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_and(volatile AS TYPE *p, TYPE val) {        \
+    return __sync_fetch_and_and_8(p, val);                                     \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_cmpxchg.cl b/libclc/generic/lib/atomic/atom_cmpxchg.cl
index ad722c3a1bec9..11101e8fda3a4 100644
--- a/libclc/generic/lib/atomic/atom_cmpxchg.cl
+++ b/libclc/generic/lib/atomic/atom_cmpxchg.cl
@@ -9,10 +9,11 @@
 #include <clc/atomic/atom_cmpxchg.h>
 #include <clc/atomic/atomic_cmpxchg.h>
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile AS TYPE *p, TYPE cmp, TYPE val) { \
-  return atomic_cmpxchg(p, cmp, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile AS TYPE *p, TYPE cmp,      \
+                                           TYPE val) {                         \
+    return atomic_cmpxchg(p, cmp, val);                                        \
+  }
 
 // cl_khr_global_int32_base_atomics
 IMPL(global, int)
@@ -24,10 +25,11 @@ IMPL(local, unsigned int)
 
 #ifdef cl_khr_int64_base_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile AS TYPE *p, TYPE cmp, TYPE val) { \
-  return __sync_val_compare_and_swap_8(p, cmp, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile AS TYPE *p, TYPE cmp,      \
+                                           TYPE val) {                         \
+    return __sync_val_compare_and_swap_8(p, cmp, val);                         \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_dec.cl b/libclc/generic/lib/atomic/atom_dec.cl
index 06b9a4e24593d..0023a505764c3 100644
--- a/libclc/generic/lib/atomic/atom_dec.cl
+++ b/libclc/generic/lib/atomic/atom_dec.cl
@@ -10,10 +10,10 @@
 #include <clc/atomic/atom_sub.h>
 #include <clc/atomic/atomic_dec.h>
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile AS TYPE *p) { \
-  return atomic_dec(p); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile AS TYPE *p) {                  \
+    return atomic_dec(p);                                                      \
+  }
 
 // cl_khr_global_int32_base_atomics
 IMPL(global, int)
@@ -25,10 +25,10 @@ IMPL(local, unsigned int)
 
 #ifdef cl_khr_int64_base_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile AS TYPE *p) { \
-  return atom_sub(p, (TYPE)1); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile AS TYPE *p) {                  \
+    return atom_sub(p, (TYPE)1);                                               \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_inc.cl b/libclc/generic/lib/atomic/atom_inc.cl
index f93b2dd45dae1..22074c714e344 100644
--- a/libclc/generic/lib/atomic/atom_inc.cl
+++ b/libclc/generic/lib/atomic/atom_inc.cl
@@ -6,14 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <clc/atomic/atom_inc.h>
 #include <clc/atomic/atom_add.h>
+#include <clc/atomic/atom_inc.h>
 #include <clc/atomic/atomic_inc.h>
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile AS TYPE *p) { \
-  return atomic_inc(p); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile AS TYPE *p) {                  \
+    return atomic_inc(p);                                                      \
+  }
 
 // cl_khr_global_int32_base_atomics
 IMPL(global, int)
@@ -25,10 +25,10 @@ IMPL(local, unsigned int)
 
 #ifdef cl_khr_int64_base_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile AS TYPE *p) { \
-  return atom_add(p, (TYPE)1); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile AS TYPE *p) {                  \
+    return atom_add(p, (TYPE)1);                                               \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_max.cl b/libclc/generic/lib/atomic/atom_max.cl
index c90da3e0b64c7..ce289ee18e9af 100644
--- a/libclc/generic/lib/atomic/atom_max.cl
+++ b/libclc/generic/lib/atomic/atom_max.cl
@@ -22,13 +22,16 @@
 
 unsigned long __clc__sync_fetch_and_max_local_8(volatile local long *, long);
 unsigned long __clc__sync_fetch_and_max_global_8(volatile global long *, long);
-unsigned long __clc__sync_fetch_and_umax_local_8(volatile local unsigned long *, unsigned long);
-unsigned long __clc__sync_fetch_and_umax_global_8(volatile global unsigned long *, unsigned long);
-
-#define IMPL(AS, TYPE, OP) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_max(volatile AS TYPE *p, TYPE val) { \
-  return __clc__sync_fetch_and_##OP##_##AS##_8(p, val); \
-}
+unsigned long __clc__sync_fetch_and_umax_local_8(volatile local unsigned long *,
+                                                 unsigned long);
+unsigned long
+__clc__sync_fetch_and_umax_global_8(volatile global unsigned long *,
+                                    unsigned long);
+
+#define IMPL(AS, TYPE, OP)                                                     \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_max(volatile AS TYPE *p, TYPE val) {        \
+    return __clc__sync_fetch_and_##OP##_##AS##_8(p, val);                      \
+  }
 
 IMPL(global, long, max)
 IMPL(global, unsigned long, umax)
diff --git a/libclc/generic/lib/atomic/atom_min.cl b/libclc/generic/lib/atomic/atom_min.cl
index 5b2ebb2408392..2fd0390885a28 100644
--- a/libclc/generic/lib/atomic/atom_min.cl
+++ b/libclc/generic/lib/atomic/atom_min.cl
@@ -22,13 +22,16 @@
 
 unsigned long __clc__sync_fetch_and_min_local_8(volatile local long *, long);
 unsigned long __clc__sync_fetch_and_min_global_8(volatile global long *, long);
-unsigned long __clc__sync_fetch_and_umin_local_8(volatile local unsigned long *, unsigned long);
-unsigned long __clc__sync_fetch_and_umin_global_8(volatile global unsigned long *, unsigned long);
-
-#define IMPL(AS, TYPE, OP) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_min(volatile AS TYPE *p, TYPE val) { \
-  return __clc__sync_fetch_and_##OP##_##AS##_8(p, val); \
-}
+unsigned long __clc__sync_fetch_and_umin_local_8(volatile local unsigned long *,
+                                                 unsigned long);
+unsigned long
+__clc__sync_fetch_and_umin_global_8(volatile global unsigned long *,
+                                    unsigned long);
+
+#define IMPL(AS, TYPE, OP)                                                     \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_min(volatile AS TYPE *p, TYPE val) {        \
+    return __clc__sync_fetch_and_##OP##_##AS##_8(p, val);                      \
+  }
 
 IMPL(global, long, min)
 IMPL(global, unsigned long, umin)
diff --git a/libclc/generic/lib/atomic/atom_or.cl b/libclc/generic/lib/atomic/atom_or.cl
index 7c3e9d2fcb632..9d8372369faaa 100644
--- a/libclc/generic/lib/atomic/atom_or.cl
+++ b/libclc/generic/lib/atomic/atom_or.cl
@@ -20,10 +20,10 @@
 
 #ifdef cl_khr_int64_extended_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_or(volatile AS TYPE *p, TYPE val) { \
-  return __sync_fetch_and_or_8(p, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_or(volatile AS TYPE *p, TYPE val) {         \
+    return __sync_fetch_and_or_8(p, val);                                      \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_sub.cl b/libclc/generic/lib/atomic/atom_sub.cl
index 0eb1b6e06a530..216bf726958b8 100644
--- a/libclc/generic/lib/atomic/atom_sub.cl
+++ b/libclc/generic/lib/atomic/atom_sub.cl
@@ -20,10 +20,10 @@
 
 #ifdef cl_khr_int64_base_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_sub(volatile AS TYPE *p, TYPE val) { \
-  return __sync_fetch_and_sub_8(p, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_sub(volatile AS TYPE *p, TYPE val) {        \
+    return __sync_fetch_and_sub_8(p, val);                                     \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_xchg.cl b/libclc/generic/lib/atomic/atom_xchg.cl
index 8d101754eaa7d..fe92eeb45ec02 100644
--- a/libclc/generic/lib/atomic/atom_xchg.cl
+++ b/libclc/generic/lib/atomic/atom_xchg.cl
@@ -20,10 +20,10 @@
 
 #ifdef cl_khr_int64_base_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(volatile AS TYPE *p, TYPE val) { \
-  return __sync_swap_8(p, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(volatile AS TYPE *p, TYPE val) {       \
+    return __sync_swap_8(p, val);                                              \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)
diff --git a/libclc/generic/lib/atomic/atom_xor.cl b/libclc/generic/lib/atomic/atom_xor.cl
index 162ae544fa22a..f9ea8675c45e3 100644
--- a/libclc/generic/lib/atomic/atom_xor.cl
+++ b/libclc/generic/lib/atomic/atom_xor.cl
@@ -20,10 +20,10 @@
 
 #ifdef cl_khr_int64_extended_atomics
 
-#define IMPL(AS, TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_xor(volatile AS TYPE *p, TYPE val) { \
-  return __sync_fetch_and_xor_8(p, val); \
-}
+#define IMPL(AS, TYPE)                                                         \
+  _CLC_OVERLOAD _CLC_DEF TYPE atom_xor(volatile AS TYPE *p, TYPE val) {        \
+    return __sync_fetch_and_xor_8(p, val);                                     \
+  }
 
 IMPL(global, long)
 IMPL(global, unsigned long)

>From 36964ad5778af0414e3b5c3d1eef65eee407c411 Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Wed, 9 Apr 2025 17:03:14 -0700
Subject: [PATCH 5/6] use #if to guard
 cl_khr_(local|global)_int32_(base|extended)_atomics

---
 libclc/generic/include/clc/atomic/atom_add.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_and.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_cmpxchg.h | 6 ++++--
 libclc/generic/include/clc/atomic/atom_dec.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_inc.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_max.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_min.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_or.h      | 6 ++++--
 libclc/generic/include/clc/atomic/atom_sub.h     | 6 ++++--
 libclc/generic/include/clc/atomic/atom_xchg.h    | 6 ++++--
 libclc/generic/include/clc/atomic/atom_xor.h     | 6 ++++--
 libclc/generic/lib/atomic/atom_add.cl            | 6 ++++--
 libclc/generic/lib/atomic/atom_and.cl            | 8 +++++---
 libclc/generic/lib/atomic/atom_cmpxchg.cl        | 7 +++++--
 libclc/generic/lib/atomic/atom_dec.cl            | 7 +++++--
 libclc/generic/lib/atomic/atom_inc.cl            | 7 +++++--
 libclc/generic/lib/atomic/atom_max.cl            | 6 ++++--
 libclc/generic/lib/atomic/atom_min.cl            | 6 ++++--
 libclc/generic/lib/atomic/atom_or.cl             | 6 ++++--
 libclc/generic/lib/atomic/atom_sub.cl            | 6 ++++--
 libclc/generic/lib/atomic/atom_xchg.cl           | 6 ++++--
 libclc/generic/lib/atomic/atom_xor.cl            | 6 ++++--
 22 files changed, 92 insertions(+), 45 deletions(-)

diff --git a/libclc/generic/include/clc/atomic/atom_add.h b/libclc/generic/include/clc/atomic/atom_add.h
index d6be0bffc8b48..b6eff1dea241a 100644
--- a/libclc/generic/include/clc/atomic/atom_add.h
+++ b/libclc/generic/include/clc/atomic/atom_add.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 #define __CLC_FUNCTION atom_add
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 #define __CLC_FUNCTION atom_add
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_add
diff --git a/libclc/generic/include/clc/atomic/atom_and.h b/libclc/generic/include/clc/atomic/atom_and.h
index a3dbb91995619..2a9993d3336d5 100644
--- a/libclc/generic/include/clc/atomic/atom_and.h
+++ b/libclc/generic/include/clc/atomic/atom_and.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_and
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_FUNCTION atom_and
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_and
diff --git a/libclc/generic/include/clc/atomic/atom_cmpxchg.h b/libclc/generic/include/clc/atomic/atom_cmpxchg.h
index 7074e3a099729..92d922b0d2766 100644
--- a/libclc/generic/include/clc/atomic/atom_cmpxchg.h
+++ b/libclc/generic/include/clc/atomic/atom_cmpxchg.h
@@ -9,19 +9,21 @@
 #include <clc/clcfunc.h>
 #include <clc/clctypes.h>
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 _CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(volatile global int *p, int cmp,
                                          int val);
 _CLC_OVERLOAD _CLC_DECL unsigned int
 atom_cmpxchg(volatile global unsigned int *p, unsigned int cmp,
              unsigned int val);
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 _CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(volatile local int *p, int cmp,
                                          int val);
 _CLC_OVERLOAD _CLC_DECL unsigned int
 atom_cmpxchg(volatile local unsigned int *p, unsigned int cmp,
              unsigned int val);
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile global long *p, long cmp,
diff --git a/libclc/generic/include/clc/atomic/atom_dec.h b/libclc/generic/include/clc/atomic/atom_dec.h
index dca0231eb2554..afb829bb83159 100644
--- a/libclc/generic/include/clc/atomic/atom_dec.h
+++ b/libclc/generic/include/clc/atomic/atom_dec.h
@@ -9,13 +9,15 @@
 #include <clc/clcfunc.h>
 #include <clc/clctypes.h>
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 _CLC_OVERLOAD _CLC_DECL int atom_dec(volatile global int *p);
 _CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile global unsigned int *p);
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 _CLC_OVERLOAD _CLC_DECL int atom_dec(volatile local int *p);
 _CLC_OVERLOAD _CLC_DECL unsigned int atom_dec(volatile local unsigned int *p);
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_dec(volatile global long *p);
diff --git a/libclc/generic/include/clc/atomic/atom_inc.h b/libclc/generic/include/clc/atomic/atom_inc.h
index 04dd404647b35..227538b153ab5 100644
--- a/libclc/generic/include/clc/atomic/atom_inc.h
+++ b/libclc/generic/include/clc/atomic/atom_inc.h
@@ -9,13 +9,15 @@
 #include <clc/clcfunc.h>
 #include <clc/clctypes.h>
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 _CLC_OVERLOAD _CLC_DECL int atom_inc(volatile global int *p);
 _CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile global unsigned int *p);
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 _CLC_OVERLOAD _CLC_DECL int atom_inc(volatile local int *p);
 _CLC_OVERLOAD _CLC_DECL unsigned int atom_inc(volatile local unsigned int *p);
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 _CLC_OVERLOAD _CLC_DECL long atom_inc(volatile global long *p);
diff --git a/libclc/generic/include/clc/atomic/atom_max.h b/libclc/generic/include/clc/atomic/atom_max.h
index 50c43fece83b0..f61f4d048b229 100644
--- a/libclc/generic/include/clc/atomic/atom_max.h
+++ b/libclc/generic/include/clc/atomic/atom_max.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_max
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_FUNCTION atom_max
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_max
diff --git a/libclc/generic/include/clc/atomic/atom_min.h b/libclc/generic/include/clc/atomic/atom_min.h
index 107e1bc770273..97576c661d5ac 100644
--- a/libclc/generic/include/clc/atomic/atom_min.h
+++ b/libclc/generic/include/clc/atomic/atom_min.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_min
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_FUNCTION atom_min
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_min
diff --git a/libclc/generic/include/clc/atomic/atom_or.h b/libclc/generic/include/clc/atomic/atom_or.h
index a2e80a7c6ae45..d359245acdf6e 100644
--- a/libclc/generic/include/clc/atomic/atom_or.h
+++ b/libclc/generic/include/clc/atomic/atom_or.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_or
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_FUNCTION atom_or
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_or
diff --git a/libclc/generic/include/clc/atomic/atom_sub.h b/libclc/generic/include/clc/atomic/atom_sub.h
index faf18dc3813d9..11eb25524c211 100644
--- a/libclc/generic/include/clc/atomic/atom_sub.h
+++ b/libclc/generic/include/clc/atomic/atom_sub.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 #define __CLC_FUNCTION atom_sub
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 #define __CLC_FUNCTION atom_sub
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_sub
diff --git a/libclc/generic/include/clc/atomic/atom_xchg.h b/libclc/generic/include/clc/atomic/atom_xchg.h
index fe0496cdbab73..4a46536c24512 100644
--- a/libclc/generic/include/clc/atomic/atom_xchg.h
+++ b/libclc/generic/include/clc/atomic/atom_xchg.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 #define __CLC_FUNCTION atom_xchg
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 #define __CLC_FUNCTION atom_xchg
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_xchg
diff --git a/libclc/generic/include/clc/atomic/atom_xor.h b/libclc/generic/include/clc/atomic/atom_xor.h
index fa1a683269c5d..72463b672e839 100644
--- a/libclc/generic/include/clc/atomic/atom_xor.h
+++ b/libclc/generic/include/clc/atomic/atom_xor.h
@@ -6,15 +6,17 @@
 //
 //===----------------------------------------------------------------------===//
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_FUNCTION atom_xor
 #define __CLC_ADDRESS_SPACE global
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_FUNCTION atom_xor
 #define __CLC_ADDRESS_SPACE local
 #include <clc/atomic/atom_decl_int32.inc>
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_base_atomics
 #define __CLC_FUNCTION atom_xor
diff --git a/libclc/generic/lib/atomic/atom_add.cl b/libclc/generic/lib/atomic/atom_add.cl
index bd835c00c5121..282b24dcbd1c9 100644
--- a/libclc/generic/lib/atomic/atom_add.cl
+++ b/libclc/generic/lib/atomic/atom_add.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_add.h>
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 #define __CLC_ATOMIC_OP add
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 #define __CLC_ATOMIC_OP add
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 
diff --git a/libclc/generic/lib/atomic/atom_and.cl b/libclc/generic/lib/atomic/atom_and.cl
index 7be821e6be569..0ad11930cb652 100644
--- a/libclc/generic/lib/atomic/atom_and.cl
+++ b/libclc/generic/lib/atomic/atom_and.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_and.h>
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_ATOMIC_OP and
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_ATOMIC_OP and
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_extended_atomics
 
@@ -31,4 +33,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif // cl_khr_local_int32_extended_atomics
+#endif #ifdef cl_khr_local_int32_extended_atomics
diff --git a/libclc/generic/lib/atomic/atom_cmpxchg.cl b/libclc/generic/lib/atomic/atom_cmpxchg.cl
index 11101e8fda3a4..e29707af84cb3 100644
--- a/libclc/generic/lib/atomic/atom_cmpxchg.cl
+++ b/libclc/generic/lib/atomic/atom_cmpxchg.cl
@@ -15,12 +15,15 @@
     return atomic_cmpxchg(p, cmp, val);                                        \
   }
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 IMPL(global, int)
 IMPL(global, unsigned int)
-// cl_khr_local_int32_base_atomics
+#endif // cl_khr_global_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 IMPL(local, int)
 IMPL(local, unsigned int)
+#endif // cl_khr_local_int32_base_atomics
+
 #undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/atomic/atom_dec.cl b/libclc/generic/lib/atomic/atom_dec.cl
index 0023a505764c3..8fb5495397d69 100644
--- a/libclc/generic/lib/atomic/atom_dec.cl
+++ b/libclc/generic/lib/atomic/atom_dec.cl
@@ -15,12 +15,15 @@
     return atomic_dec(p);                                                      \
   }
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 IMPL(global, int)
 IMPL(global, unsigned int)
-// cl_khr_local_int32_base_atomics
+#endif // cl_khr_global_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 IMPL(local, int)
 IMPL(local, unsigned int)
+#endif // cl_khr_local_int32_base_atomics
+
 #undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/atomic/atom_inc.cl b/libclc/generic/lib/atomic/atom_inc.cl
index 22074c714e344..c74df54eb4893 100644
--- a/libclc/generic/lib/atomic/atom_inc.cl
+++ b/libclc/generic/lib/atomic/atom_inc.cl
@@ -15,12 +15,15 @@
     return atomic_inc(p);                                                      \
   }
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 IMPL(global, int)
 IMPL(global, unsigned int)
-// cl_khr_local_int32_base_atomics
+#endif // cl_khr_global_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 IMPL(local, int)
 IMPL(local, unsigned int)
+#endif // cl_khr_local_int32_base_atomics
+
 #undef IMPL
 
 #ifdef cl_khr_int64_base_atomics
diff --git a/libclc/generic/lib/atomic/atom_max.cl b/libclc/generic/lib/atomic/atom_max.cl
index ce289ee18e9af..9427732fe7a4d 100644
--- a/libclc/generic/lib/atomic/atom_max.cl
+++ b/libclc/generic/lib/atomic/atom_max.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_max.h>
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_ATOMIC_OP max
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_ATOMIC_OP max
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_extended_atomics
 
diff --git a/libclc/generic/lib/atomic/atom_min.cl b/libclc/generic/lib/atomic/atom_min.cl
index 2fd0390885a28..881e832932910 100644
--- a/libclc/generic/lib/atomic/atom_min.cl
+++ b/libclc/generic/lib/atomic/atom_min.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_min.h>
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_ATOMIC_OP min
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_ATOMIC_OP min
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_extended_atomics
 
diff --git a/libclc/generic/lib/atomic/atom_or.cl b/libclc/generic/lib/atomic/atom_or.cl
index 9d8372369faaa..0a23f8945da9f 100644
--- a/libclc/generic/lib/atomic/atom_or.cl
+++ b/libclc/generic/lib/atomic/atom_or.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_or.h>
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_ATOMIC_OP or
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_ATOMIC_OP or
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_extended_atomics
 
diff --git a/libclc/generic/lib/atomic/atom_sub.cl b/libclc/generic/lib/atomic/atom_sub.cl
index 216bf726958b8..1951f985688b2 100644
--- a/libclc/generic/lib/atomic/atom_sub.cl
+++ b/libclc/generic/lib/atomic/atom_sub.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_sub.h>
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 #define __CLC_ATOMIC_OP sub
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 #define __CLC_ATOMIC_OP sub
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 
diff --git a/libclc/generic/lib/atomic/atom_xchg.cl b/libclc/generic/lib/atomic/atom_xchg.cl
index fe92eeb45ec02..6e9ef796d9c0d 100644
--- a/libclc/generic/lib/atomic/atom_xchg.cl
+++ b/libclc/generic/lib/atomic/atom_xchg.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_xchg.h>
 
-// cl_khr_global_int32_base_atomics
+#ifdef cl_khr_global_int32_base_atomics
 #define __CLC_ATOMIC_OP xchg
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_base_atomics
 
-// cl_khr_local_int32_base_atomics
+#ifdef cl_khr_local_int32_base_atomics
 #define __CLC_ATOMIC_OP xchg
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_base_atomics
 
 #ifdef cl_khr_int64_base_atomics
 
diff --git a/libclc/generic/lib/atomic/atom_xor.cl b/libclc/generic/lib/atomic/atom_xor.cl
index f9ea8675c45e3..3f032d9b4179f 100644
--- a/libclc/generic/lib/atomic/atom_xor.cl
+++ b/libclc/generic/lib/atomic/atom_xor.cl
@@ -8,15 +8,17 @@
 
 #include <clc/atomic/atom_xor.h>
 
-// cl_khr_global_int32_extended_atomics
+#ifdef cl_khr_global_int32_extended_atomics
 #define __CLC_ATOMIC_OP xor
 #define __CLC_ATOMIC_ADDRESS_SPACE global
 #include "atom_int32_binary.inc"
+#endif // cl_khr_global_int32_extended_atomics
 
-// cl_khr_local_int32_extended_atomics
+#ifdef cl_khr_local_int32_extended_atomics
 #define __CLC_ATOMIC_OP xor
 #define __CLC_ATOMIC_ADDRESS_SPACE local
 #include "atom_int32_binary.inc"
+#endif // cl_khr_local_int32_extended_atomics
 
 #ifdef cl_khr_int64_extended_atomics
 

>From de7d8b93e0f6f0e162f4672b98ce240ecbb419ea Mon Sep 17 00:00:00 2001
From: Wenju He <wenju.he at intel.com>
Date: Thu, 10 Apr 2025 17:00:38 -0700
Subject: [PATCH 6/6] cl_khr_int64_base_atomics ->
 cl_khr_int64_extended_atomics, fix a copy-paste error in atom_and.cl

---
 libclc/generic/include/clc/atomic/atom_and.h | 4 ++--
 libclc/generic/include/clc/atomic/atom_max.h | 4 ++--
 libclc/generic/include/clc/atomic/atom_min.h | 4 ++--
 libclc/generic/include/clc/atomic/atom_or.h  | 4 ++--
 libclc/generic/include/clc/atomic/atom_xor.h | 4 ++--
 libclc/generic/lib/atomic/atom_and.cl        | 2 +-
 libclc/generic/lib/atomic/atom_or.cl         | 2 +-
 libclc/generic/lib/atomic/atom_xor.cl        | 2 +-
 8 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/libclc/generic/include/clc/atomic/atom_and.h b/libclc/generic/include/clc/atomic/atom_and.h
index 2a9993d3336d5..96c4ebb126daa 100644
--- a/libclc/generic/include/clc/atomic/atom_and.h
+++ b/libclc/generic/include/clc/atomic/atom_and.h
@@ -18,7 +18,7 @@
 #include <clc/atomic/atom_decl_int32.inc>
 #endif // cl_khr_local_int32_extended_atomics
 
-#ifdef cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_extended_atomics
 #define __CLC_FUNCTION atom_and
 #include <clc/atomic/atom_decl_int64.inc>
-#endif // cl_khr_int64_base_atomics
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_max.h b/libclc/generic/include/clc/atomic/atom_max.h
index f61f4d048b229..8cb601be5d6ea 100644
--- a/libclc/generic/include/clc/atomic/atom_max.h
+++ b/libclc/generic/include/clc/atomic/atom_max.h
@@ -18,7 +18,7 @@
 #include <clc/atomic/atom_decl_int32.inc>
 #endif // cl_khr_local_int32_extended_atomics
 
-#ifdef cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_extended_atomics
 #define __CLC_FUNCTION atom_max
 #include <clc/atomic/atom_decl_int64.inc>
-#endif // cl_khr_int64_base_atomics
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_min.h b/libclc/generic/include/clc/atomic/atom_min.h
index 97576c661d5ac..67853c999b2e4 100644
--- a/libclc/generic/include/clc/atomic/atom_min.h
+++ b/libclc/generic/include/clc/atomic/atom_min.h
@@ -18,7 +18,7 @@
 #include <clc/atomic/atom_decl_int32.inc>
 #endif // cl_khr_local_int32_extended_atomics
 
-#ifdef cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_extended_atomics
 #define __CLC_FUNCTION atom_min
 #include <clc/atomic/atom_decl_int64.inc>
-#endif // cl_khr_int64_base_atomics
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_or.h b/libclc/generic/include/clc/atomic/atom_or.h
index d359245acdf6e..7930ab0c5692e 100644
--- a/libclc/generic/include/clc/atomic/atom_or.h
+++ b/libclc/generic/include/clc/atomic/atom_or.h
@@ -18,7 +18,7 @@
 #include <clc/atomic/atom_decl_int32.inc>
 #endif // cl_khr_local_int32_extended_atomics
 
-#ifdef cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_extended_atomics
 #define __CLC_FUNCTION atom_or
 #include <clc/atomic/atom_decl_int64.inc>
-#endif // cl_khr_int64_base_atomics
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/include/clc/atomic/atom_xor.h b/libclc/generic/include/clc/atomic/atom_xor.h
index 72463b672e839..ad8ae554e15a2 100644
--- a/libclc/generic/include/clc/atomic/atom_xor.h
+++ b/libclc/generic/include/clc/atomic/atom_xor.h
@@ -18,7 +18,7 @@
 #include <clc/atomic/atom_decl_int32.inc>
 #endif // cl_khr_local_int32_extended_atomics
 
-#ifdef cl_khr_int64_base_atomics
+#ifdef cl_khr_int64_extended_atomics
 #define __CLC_FUNCTION atom_xor
 #include <clc/atomic/atom_decl_int64.inc>
-#endif // cl_khr_int64_base_atomics
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/lib/atomic/atom_and.cl b/libclc/generic/lib/atomic/atom_and.cl
index 0ad11930cb652..2c95d2a7780c3 100644
--- a/libclc/generic/lib/atomic/atom_and.cl
+++ b/libclc/generic/lib/atomic/atom_and.cl
@@ -33,4 +33,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif #ifdef cl_khr_local_int32_extended_atomics
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/lib/atomic/atom_or.cl b/libclc/generic/lib/atomic/atom_or.cl
index 0a23f8945da9f..a9f9bb782fb2f 100644
--- a/libclc/generic/lib/atomic/atom_or.cl
+++ b/libclc/generic/lib/atomic/atom_or.cl
@@ -33,4 +33,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_extended_atomics
diff --git a/libclc/generic/lib/atomic/atom_xor.cl b/libclc/generic/lib/atomic/atom_xor.cl
index 3f032d9b4179f..bfa978d4b9a12 100644
--- a/libclc/generic/lib/atomic/atom_xor.cl
+++ b/libclc/generic/lib/atomic/atom_xor.cl
@@ -33,4 +33,4 @@ IMPL(local, long)
 IMPL(local, unsigned long)
 #undef IMPL
 
-#endif
+#endif // cl_khr_int64_extended_atomics



More information about the cfe-commits mailing list