[Libclc-dev] [PATCH 6/7] atom: Consolidate cl_khr_{local, global}_int32_{base, extended}_atomics implementation
Jan Vesely via Libclc-dev
libclc-dev at lists.llvm.org
Wed Jun 20 13:35:03 PDT 2018
These are just atomic_* wrappers.
Switch inc,dec to use atomic_* wrappers as well.
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
generic/lib/atom_int32_binary.inc | 14 ++++++++++++++
generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl | 12 +++---------
generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl | 2 +-
generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl | 2 +-
generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl | 12 +++---------
generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl | 12 +++---------
.../lib/cl_khr_global_int32_extended_atomics/atom_and.cl | 12 +++---------
.../lib/cl_khr_global_int32_extended_atomics/atom_max.cl | 12 +++---------
.../lib/cl_khr_global_int32_extended_atomics/atom_min.cl | 12 +++---------
.../lib/cl_khr_global_int32_extended_atomics/atom_or.cl | 12 +++---------
.../lib/cl_khr_global_int32_extended_atomics/atom_xor.cl | 12 +++---------
generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl | 12 +++---------
generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl | 2 +-
generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl | 2 +-
generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl | 12 +++---------
generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl | 12 +++---------
.../lib/cl_khr_local_int32_extended_atomics/atom_and.cl | 12 +++---------
.../lib/cl_khr_local_int32_extended_atomics/atom_max.cl | 12 +++---------
.../lib/cl_khr_local_int32_extended_atomics/atom_min.cl | 12 +++---------
generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl | 12 +++---------
.../lib/cl_khr_local_int32_extended_atomics/atom_xor.cl | 12 +++---------
21 files changed, 66 insertions(+), 148 deletions(-)
create mode 100644 generic/lib/atom_int32_binary.inc
diff --git a/generic/lib/atom_int32_binary.inc b/generic/lib/atom_int32_binary.inc
new file mode 100644
index 0000000..185144c
--- /dev/null
+++ b/generic/lib/atom_int32_binary.inc
@@ -0,0 +1,14 @@
+#include <clc/clc.h>
+#include "utils.h"
+
+#define __CLC_ATOM_IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE __CLC_XCONCAT(atom_, __CLC_ATOMIC_OP) (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)
+
+#undef __CLC_ATOM_IMPL
+#undef __CLC_ATOMIC_OP
+#undef __CLC_ATOMIC_ADDRESS_SPACE
diff --git a/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl b/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl
index 9151b0c..69f1875 100644
--- a/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl
+++ b/generic/lib/cl_khr_global_int32_base_atomics/atom_add.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_add(global TYPE *p, TYPE val) { \
- return atomic_add(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP add
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl b/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl
index cc24d2f..290bec2 100644
--- a/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl
+++ b/generic/lib/cl_khr_global_int32_base_atomics/atom_dec.cl
@@ -2,7 +2,7 @@
#define IMPL(TYPE) \
_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(global TYPE *p) { \
- return atom_sub(p, (TYPE)1); \
+ return atomic_dec(p); \
}
IMPL(int)
diff --git a/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl b/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl
index 9193ae3..422bb78 100644
--- a/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl
+++ b/generic/lib/cl_khr_global_int32_base_atomics/atom_inc.cl
@@ -2,7 +2,7 @@
#define IMPL(TYPE) \
_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(global TYPE *p) { \
- return atom_add(p, (TYPE)1); \
+ return atomic_inc(p); \
}
IMPL(int)
diff --git a/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl b/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl
index 7faa3cc..e3ca935 100644
--- a/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl
+++ b/generic/lib/cl_khr_global_int32_base_atomics/atom_sub.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_sub(global TYPE *p, TYPE val) { \
- return atomic_sub(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP sub
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl b/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
index 9c77db1..3389c86 100644
--- a/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
+++ b/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(global TYPE *p, TYPE val) { \
- return atomic_xchg(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP xchg
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl b/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl
index e587969..da002d5 100644
--- a/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl
+++ b/generic/lib/cl_khr_global_int32_extended_atomics/atom_and.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_and(global TYPE *p, TYPE val) { \
- return atomic_and(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
\ No newline at end of file
+#define __CLC_ATOMIC_OP and
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl b/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl
index 09177ed..9b7975f 100644
--- a/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl
+++ b/generic/lib/cl_khr_global_int32_extended_atomics/atom_max.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_max(global TYPE *p, TYPE val) { \
- return atomic_max(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP max
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl b/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl
index 277c41b..04b5f75 100644
--- a/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl
+++ b/generic/lib/cl_khr_global_int32_extended_atomics/atom_min.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_min(global TYPE *p, TYPE val) { \
- return atomic_min(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP min
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl b/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl
index a936a8e..dbf4e15 100644
--- a/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl
+++ b/generic/lib/cl_khr_global_int32_extended_atomics/atom_or.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_or(global TYPE *p, TYPE val) { \
- return atomic_or(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP or
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl b/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl
index 1a8e350..40a403d 100644
--- a/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl
+++ b/generic/lib/cl_khr_global_int32_extended_atomics/atom_xor.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_xor(global TYPE *p, TYPE val) { \
- return atomic_xor(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP xor
+#define __CLC_ATOMIC_ADDRESS_SPACE global
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl b/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl
index a5dea18..55dd78c 100644
--- a/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl
+++ b/generic/lib/cl_khr_local_int32_base_atomics/atom_add.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_add(local TYPE *p, TYPE val) { \
- return atomic_add(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP add
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl b/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl
index cfb3d80..d708a6d 100644
--- a/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl
+++ b/generic/lib/cl_khr_local_int32_base_atomics/atom_dec.cl
@@ -2,7 +2,7 @@
#define IMPL(TYPE) \
_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(local TYPE *p) { \
- return atom_sub(p, (TYPE)1); \
+ return atomic_dec(p); \
}
IMPL(int)
diff --git a/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl b/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl
index 8ea4738..8878673 100644
--- a/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl
+++ b/generic/lib/cl_khr_local_int32_base_atomics/atom_inc.cl
@@ -2,7 +2,7 @@
#define IMPL(TYPE) \
_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(local TYPE *p) { \
- return atom_add(p, (TYPE)1); \
+ return atomic_inc(p); \
}
IMPL(int)
diff --git a/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl b/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl
index c96696a..c0af334 100644
--- a/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl
+++ b/generic/lib/cl_khr_local_int32_base_atomics/atom_sub.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_sub(local TYPE *p, TYPE val) { \
- return atomic_sub(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP sub
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl b/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
index 7d4bcca..7120068 100644
--- a/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
+++ b/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(local TYPE *p, TYPE val) { \
- return atomic_xchg(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP xchg
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl b/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl
index 180103a..62b6ae7 100644
--- a/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl
+++ b/generic/lib/cl_khr_local_int32_extended_atomics/atom_and.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_and(local TYPE *p, TYPE val) { \
- return atomic_and(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
\ No newline at end of file
+#define __CLC_ATOMIC_OP and
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl b/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl
index b90301b..8f03b9d 100644
--- a/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl
+++ b/generic/lib/cl_khr_local_int32_extended_atomics/atom_max.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_max(local TYPE *p, TYPE val) { \
- return atomic_max(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP max
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl b/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl
index 3acedd8..59a3252 100644
--- a/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl
+++ b/generic/lib/cl_khr_local_int32_extended_atomics/atom_min.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_min(local TYPE *p, TYPE val) { \
- return atomic_min(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP min
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl b/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl
index 338ff2c..8ea408e 100644
--- a/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl
+++ b/generic/lib/cl_khr_local_int32_extended_atomics/atom_or.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_or(local TYPE *p, TYPE val) { \
- return atomic_or(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP or
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
diff --git a/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl b/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl
index 51ae3c0..8c28662 100644
--- a/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl
+++ b/generic/lib/cl_khr_local_int32_extended_atomics/atom_xor.cl
@@ -1,9 +1,3 @@
-#include <clc/clc.h>
-
-#define IMPL(TYPE) \
-_CLC_OVERLOAD _CLC_DEF TYPE atom_xor(local TYPE *p, TYPE val) { \
- return atomic_xor(p, val); \
-}
-
-IMPL(int)
-IMPL(unsigned int)
+#define __CLC_ATOMIC_OP xor
+#define __CLC_ATOMIC_ADDRESS_SPACE local
+#include "../atom_int32_binary.inc"
--
2.16.4
More information about the Libclc-dev
mailing list