[Libclc-dev] [PATCH 08/15] atomic: Add generic atom[ic]_cmpxchg

Aaron Watry awatry at gmail.com
Tue Sep 9 16:24:41 PDT 2014


Signed-off-by: Aaron Watry <awatry at gmail.com>
---
 generic/include/clc/atomic/atomic_cmpxchg.h               | 15 +++++++++++++++
 .../clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h   |  2 ++
 .../clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h    |  2 ++
 generic/include/clc/clc.h                                 |  3 +++
 generic/lib/SOURCES                                       |  2 ++
 generic/lib/atomic/atomic_impl.ll                         | 14 ++++++++++++++
 .../lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl  |  9 +++++++++
 .../lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl   |  9 +++++++++
 8 files changed, 56 insertions(+)
 create mode 100644 generic/include/clc/atomic/atomic_cmpxchg.h
 create mode 100644 generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h
 create mode 100644 generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h
 create mode 100644 generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
 create mode 100644 generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl

diff --git a/generic/include/clc/atomic/atomic_cmpxchg.h b/generic/include/clc/atomic/atomic_cmpxchg.h
new file mode 100644
index 0000000..aac7631
--- /dev/null
+++ b/generic/include/clc/atomic/atomic_cmpxchg.h
@@ -0,0 +1,15 @@
+#define __CLC_FUNCTION atomic_cmpxchg
+
+#define __CLC_DECLARE_ATOMIC_3_ARG(ADDRSPACE, TYPE) \
+	_CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION (volatile ADDRSPACE TYPE *, TYPE, TYPE);
+
+#define __CLC_DECLARE_ATOMIC_ADDRSPACE_3_ARG(TYPE) \
+	__CLC_DECLARE_ATOMIC_3_ARG(global, TYPE); \
+	__CLC_DECLARE_ATOMIC_3_ARG(local, TYPE);
+
+__CLC_DECLARE_ATOMIC_ADDRSPACE_3_ARG(int);
+__CLC_DECLARE_ATOMIC_ADDRSPACE_3_ARG(uint);
+
+#undef __CLC_FUNCTION
+#undef __CLC_DECLARE_ATOMIC_3_ARG
+#undef __CLC_DECLARE_ATOMIC_ADDRESS_SPACE_3_ARG
\ No newline at end of file
diff --git a/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h b/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h
new file mode 100644
index 0000000..168f423
--- /dev/null
+++ b/generic/include/clc/cl_khr_global_int32_base_atomics/atom_cmpxchg.h
@@ -0,0 +1,2 @@
+_CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(global int *p, int cmp, int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_cmpxchg(global unsigned int *p, unsigned int cmp, unsigned int val);
diff --git a/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h b/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h
new file mode 100644
index 0000000..e10a84f
--- /dev/null
+++ b/generic/include/clc/cl_khr_local_int32_base_atomics/atom_cmpxchg.h
@@ -0,0 +1,2 @@
+_CLC_OVERLOAD _CLC_DECL int atom_cmpxchg(local int *p, int cmp, int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_cmpxchg(local unsigned int *p, unsigned int cmp, unsigned int val);
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index d26bd2d..c39c9c8 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -143,6 +143,7 @@
 /* 6.11.11 Atomic Functions */
 #include <clc/atomic/atomic_add.h>
 #include <clc/atomic/atomic_and.h>
+#include <clc/atomic/atomic_cmpxchg.h>
 #include <clc/atomic/atomic_dec.h>
 #include <clc/atomic/atomic_inc.h>
 #include <clc/atomic/atomic_max.h>
@@ -154,6 +155,7 @@
 
 /* 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>
@@ -168,6 +170,7 @@
 
 /* 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>
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index d23370e..6f7b1e8 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -2,6 +2,7 @@ async/prefetch.cl
 atomic/atomic_xchg.cl
 atomic/atomic_impl.ll
 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
@@ -12,6 +13,7 @@ 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
diff --git a/generic/lib/atomic/atomic_impl.ll b/generic/lib/atomic/atomic_impl.ll
index b5495cc..019147f 100644
--- a/generic/lib/atomic/atomic_impl.ll
+++ b/generic/lib/atomic/atomic_impl.ll
@@ -22,6 +22,20 @@ entry:
   ret i32 %0
 }
 
+define i32 @__clc_atomic_cmpxchg_addr1(i32 addrspace(1)* nocapture %ptr, i32 %compare, i32 %value) nounwind alwaysinline {
+entry:
+  %0 = cmpxchg volatile i32 addrspace(1)* %ptr, i32 %compare, i32 %value seq_cst seq_cst
+  %1 = extractvalue { i32, i1 } %0, 0
+  ret i32 %1
+}
+
+define i32 @__clc_atomic_cmpxchg_addr3(i32 addrspace(3)* nocapture %ptr, i32 %compare, i32 %value) nounwind alwaysinline {
+entry:
+  %0 = cmpxchg volatile i32 addrspace(3)* %ptr, i32 %compare, i32 %value seq_cst seq_cst
+  %1 = extractvalue { i32, i1 } %0, 0
+  ret i32 %1
+}
+
 define i32 @__clc_atomic_max_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline {
 entry:
   %0 = atomicrmw volatile max i32 addrspace(1)* %ptr, i32 %value seq_cst
diff --git a/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl b/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
new file mode 100644
index 0000000..7647740
--- /dev/null
+++ b/generic/lib/cl_khr_global_int32_base_atomics/atom_cmpxchg.cl
@@ -0,0 +1,9 @@
+#include <clc/clc.h>
+
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(global TYPE *p, TYPE cmp, TYPE val) { \
+  return atomic_cmpxchg(p, cmp, val); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
diff --git a/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl b/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl
new file mode 100644
index 0000000..16e9579
--- /dev/null
+++ b/generic/lib/cl_khr_local_int32_base_atomics/atom_cmpxchg.cl
@@ -0,0 +1,9 @@
+#include <clc/clc.h>
+
+#define IMPL(TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(local TYPE *p, TYPE cmp, TYPE val) { \
+  return atomic_cmpxchg(p, cmp, val); \
+}
+
+IMPL(int)
+IMPL(unsigned int)
-- 
1.9.1





More information about the Libclc-dev mailing list