summaryrefslogtreecommitdiffstats
path: root/libclc
diff options
context:
space:
mode:
authorAaron Watry <awatry@gmail.com>2013-09-05 16:04:01 +0000
committerAaron Watry <awatry@gmail.com>2013-09-05 16:04:01 +0000
commit50a7bcbac92afc472f381f4dde694a613f411daf (patch)
tree4e7bc5551942abe06081ea5b42726ae404a478c7 /libclc
parent785ee472a35148486f024c85191df8364ed4f35d (diff)
downloadbcm5719-llvm-50a7bcbac92afc472f381f4dde694a613f411daf.tar.gz
bcm5719-llvm-50a7bcbac92afc472f381f4dde694a613f411daf.zip
Add atomic_inc and atomic_add builtins
Reviewed-by: Aaron Watry <awatry@gmail.com> llvm-svn: 190058
Diffstat (limited to 'libclc')
-rw-r--r--libclc/generic/include/clc/atomic/atomic_add.h3
-rw-r--r--libclc/generic/include/clc/atomic/atomic_decl.inc10
-rw-r--r--libclc/generic/include/clc/atomic/atomic_inc.h1
-rw-r--r--libclc/generic/include/clc/clc.h4
-rw-r--r--libclc/generic/lib/SOURCES1
-rw-r--r--libclc/generic/lib/atomic/atomic_impl.ll11
-rw-r--r--libclc/r600/lib/SOURCES1
-rw-r--r--libclc/r600/lib/atomic/atomic.cl20
8 files changed, 51 insertions, 0 deletions
diff --git a/libclc/generic/include/clc/atomic/atomic_add.h b/libclc/generic/include/clc/atomic/atomic_add.h
new file mode 100644
index 00000000000..66d897805ca
--- /dev/null
+++ b/libclc/generic/include/clc/atomic/atomic_add.h
@@ -0,0 +1,3 @@
+#define __CLC_FUNCTION atomic_add
+#include <clc/atomic/atomic_decl.inc>
+#undef __CLC_FUNCTION
diff --git a/libclc/generic/include/clc/atomic/atomic_decl.inc b/libclc/generic/include/clc/atomic/atomic_decl.inc
new file mode 100644
index 00000000000..03d01aa045e
--- /dev/null
+++ b/libclc/generic/include/clc/atomic/atomic_decl.inc
@@ -0,0 +1,10 @@
+
+#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE) \
+ _CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION (volatile ADDRSPACE TYPE *, TYPE);
+
+#define __CLC_DECLARE_ATOMIC_ADDRSPACE(TYPE) \
+ __CLC_DECLARE_ATOMIC(global, TYPE); \
+ __CLC_DECLARE_ATOMIC(local, TYPE);
+
+__CLC_DECLARE_ATOMIC_ADDRSPACE(int);
+__CLC_DECLARE_ATOMIC_ADDRSPACE(uint);
diff --git a/libclc/generic/include/clc/atomic/atomic_inc.h b/libclc/generic/include/clc/atomic/atomic_inc.h
new file mode 100644
index 00000000000..21373919804
--- /dev/null
+++ b/libclc/generic/include/clc/atomic/atomic_inc.h
@@ -0,0 +1 @@
+#define atomic_inc(p) atomic_add(p, 1);
diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h
index 305f0585d88..105180e12e7 100644
--- a/libclc/generic/include/clc/clc.h
+++ b/libclc/generic/include/clc/clc.h
@@ -99,4 +99,8 @@
#include <clc/synchronization/cl_mem_fence_flags.h>
#include <clc/synchronization/barrier.h>
+/* 6.11.11 Atomic Functins */
+#include <clc/atomic/atomic_add.h>
+#include <clc/atomic/atomic_inc.h>
+
#pragma OPENCL EXTENSION all : disable
diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES
index d6e2d8c7a02..16db9bc87ba 100644
--- a/libclc/generic/lib/SOURCES
+++ b/libclc/generic/lib/SOURCES
@@ -1,3 +1,4 @@
+atomic/atomic_impl.ll
convert.cl
geometric/cross.cl
geometric/dot.cl
diff --git a/libclc/generic/lib/atomic/atomic_impl.ll b/libclc/generic/lib/atomic/atomic_impl.ll
new file mode 100644
index 00000000000..c11383be983
--- /dev/null
+++ b/libclc/generic/lib/atomic/atomic_impl.ll
@@ -0,0 +1,11 @@
+define i32 @__clc_atomic_add_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline {
+entry:
+ %0 = atomicrmw volatile add i32 addrspace(1)* %ptr, i32 %value seq_cst
+ ret i32 %0
+}
+
+define i32 @__clc_atomic_add_addr3(i32 addrspace(3)* nocapture %ptr, i32 %value) nounwind alwaysinline {
+entry:
+ %0 = atomicrmw volatile add i32 addrspace(3)* %ptr, i32 %value seq_cst
+ ret i32 %0
+}
diff --git a/libclc/r600/lib/SOURCES b/libclc/r600/lib/SOURCES
index 38919ab1d5b..de30f6e0038 100644
--- a/libclc/r600/lib/SOURCES
+++ b/libclc/r600/lib/SOURCES
@@ -1,3 +1,4 @@
+atomic/atomic.cl
workitem/get_num_groups.ll
workitem/get_group_id.ll
workitem/get_local_size.ll
diff --git a/libclc/r600/lib/atomic/atomic.cl b/libclc/r600/lib/atomic/atomic.cl
new file mode 100644
index 00000000000..e80180ca535
--- /dev/null
+++ b/libclc/r600/lib/atomic/atomic.cl
@@ -0,0 +1,20 @@
+#include <clc/clc.h>
+
+#define ATOMIC_FUNC_TYPE(SIGN, TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
+_CLC_OVERLOAD _CLC_DEF SIGN TYPE FUNCTION (volatile CL_ADDRSPACE SIGN TYPE *p, SIGN TYPE val) { \
+ return (SIGN TYPE)__clc_##FUNCTION##_addr##LLVM_ADDRSPACE((volatile CL_ADDRSPACE signed TYPE*)p, (signed TYPE)val); \
+}
+
+#define ATOMIC_FUNC_SIGN(TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
+ _CLC_DECL signed TYPE __clc_##FUNCTION##_addr##LLVM_ADDRSPACE(volatile CL_ADDRSPACE signed TYPE*, signed TYPE); \
+ ATOMIC_FUNC_TYPE(signed, TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \
+ ATOMIC_FUNC_TYPE(unsigned, TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE)
+
+#define ATOMIC_FUNC_ADDRSPACE(TYPE, FUNCTION) \
+ ATOMIC_FUNC_SIGN(TYPE, FUNCTION, global, 1) \
+ ATOMIC_FUNC_SIGN(TYPE, FUNCTION, local, 3)
+
+#define ATOMIC_FUNC(FUNCTION) \
+ ATOMIC_FUNC_ADDRSPACE(int, FUNCTION)
+
+ATOMIC_FUNC(atomic_add)
OpenPOWER on IntegriCloud