[libclc] r217917 - atomic: Implement generic atom[ic]_xchg

Aaron Watry awatry at gmail.com
Tue Sep 16 15:34:46 PDT 2014


Author: awatry
Date: Tue Sep 16 17:34:45 2014
New Revision: 217917

URL: http://llvm.org/viewvc/llvm-project?rev=217917&view=rev
Log:
atomic: Implement generic atom[ic]_xchg

Signed-off-by: Aaron Watry <awatry at gmail.com>
Reviewed-by: Tom Stellard <thomas.stellard at amd.com>

Added:
    libclc/trunk/generic/include/clc/atomic/atomic_xchg.h
    libclc/trunk/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h
    libclc/trunk/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h
    libclc/trunk/generic/lib/atomic/atomic_xchg.cl
    libclc/trunk/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
    libclc/trunk/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
Modified:
    libclc/trunk/generic/include/clc/clc.h
    libclc/trunk/generic/lib/SOURCES
    libclc/trunk/generic/lib/atomic/atomic_impl.ll

Added: libclc/trunk/generic/include/clc/atomic/atomic_xchg.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/atomic/atomic_xchg.h?rev=217917&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/atomic/atomic_xchg.h (added)
+++ libclc/trunk/generic/include/clc/atomic/atomic_xchg.h Tue Sep 16 17:34:45 2014
@@ -0,0 +1,5 @@
+#define __CLC_FUNCTION atomic_xchg
+#include <clc/atomic/atomic_decl.inc>
+__CLC_DECLARE_ATOMIC_ADDRSPACE(float);
+#undef __CLC_FUNCTION
+#undef __CLC_DECLARE_ATOMIC_ADDRSPACE

Added: libclc/trunk/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h?rev=217917&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h (added)
+++ libclc/trunk/generic/include/clc/cl_khr_global_int32_base_atomics/atom_xchg.h Tue Sep 16 17:34:45 2014
@@ -0,0 +1,2 @@
+_CLC_OVERLOAD _CLC_DECL int atom_xchg(global int *p, int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_xchg(global unsigned int *p, unsigned int val);

Added: libclc/trunk/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h?rev=217917&view=auto
==============================================================================
--- libclc/trunk/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h (added)
+++ libclc/trunk/generic/include/clc/cl_khr_local_int32_base_atomics/atom_xchg.h Tue Sep 16 17:34:45 2014
@@ -0,0 +1,2 @@
+_CLC_OVERLOAD _CLC_DECL int atom_xchg(local int *p, int val);
+_CLC_OVERLOAD _CLC_DECL unsigned int atom_xchg(local unsigned int *p, unsigned int val);

Modified: libclc/trunk/generic/include/clc/clc.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=217917&r1=217916&r2=217917&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Tue Sep 16 17:34:45 2014
@@ -148,6 +148,7 @@
 #include <clc/atomic/atomic_min.h>
 #include <clc/atomic/atomic_or.h>
 #include <clc/atomic/atomic_sub.h>
+#include <clc/atomic/atomic_xchg.h>
 #include <clc/atomic/atomic_xor.h>
 
 /* cl_khr_global_int32_base_atomics Extension Functions */
@@ -155,6 +156,7 @@
 #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>
@@ -168,6 +170,7 @@
 #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>

Modified: libclc/trunk/generic/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=217917&r1=217916&r2=217917&view=diff
==============================================================================
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Tue Sep 16 17:34:45 2014
@@ -1,9 +1,11 @@
 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_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
@@ -13,6 +15,7 @@ cl_khr_local_int32_base_atomics/atom_add
 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

Modified: libclc/trunk/generic/lib/atomic/atomic_impl.ll
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/atomic/atomic_impl.ll?rev=217917&r1=217916&r2=217917&view=diff
==============================================================================
--- libclc/trunk/generic/lib/atomic/atomic_impl.ll (original)
+++ libclc/trunk/generic/lib/atomic/atomic_impl.ll Tue Sep 16 17:34:45 2014
@@ -94,6 +94,18 @@ entry:
   ret i32 %0
 }
 
+define i32 @__clc_atomic_xchg_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline {
+entry:
+  %0 = atomicrmw volatile xchg i32 addrspace(1)* %ptr, i32 %value seq_cst
+  ret i32 %0
+}
+
+define i32 @__clc_atomic_xchg_addr3(i32 addrspace(3)* nocapture %ptr, i32 %value) nounwind alwaysinline {
+entry:
+  %0 = atomicrmw volatile xchg i32 addrspace(3)* %ptr, i32 %value seq_cst
+  ret i32 %0
+}
+
 define i32 @__clc_atomic_xor_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline {
 entry:
   %0 = atomicrmw volatile xor i32 addrspace(1)* %ptr, i32 %value seq_cst

Added: libclc/trunk/generic/lib/atomic/atomic_xchg.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/atomic/atomic_xchg.cl?rev=217917&view=auto
==============================================================================
--- libclc/trunk/generic/lib/atomic/atomic_xchg.cl (added)
+++ libclc/trunk/generic/lib/atomic/atomic_xchg.cl Tue Sep 16 17:34:45 2014
@@ -0,0 +1,9 @@
+#include <clc/clc.h>
+
+_CLC_OVERLOAD _CLC_DEF float atomic_xchg(volatile global float *p, float val) {
+  return as_float(atomic_xchg((volatile global int *)p, as_int(val)));
+}
+
+_CLC_OVERLOAD _CLC_DEF float atomic_xchg(volatile local float *p, float val) {
+  return as_float(atomic_xchg((volatile local int *)p, as_int(val)));
+}

Added: libclc/trunk/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl?rev=217917&view=auto
==============================================================================
--- libclc/trunk/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl (added)
+++ libclc/trunk/generic/lib/cl_khr_global_int32_base_atomics/atom_xchg.cl Tue Sep 16 17:34:45 2014
@@ -0,0 +1,9 @@
+#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)

Added: libclc/trunk/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl?rev=217917&view=auto
==============================================================================
--- libclc/trunk/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl (added)
+++ libclc/trunk/generic/lib/cl_khr_local_int32_base_atomics/atom_xchg.cl Tue Sep 16 17:34:45 2014
@@ -0,0 +1,9 @@
+#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)





More information about the cfe-commits mailing list