atomic: Provide function implementation of atomic_{dec,inc}
authorJan Vesely <jan.vesely@rutgers.edu>
Thu, 21 Jun 2018 19:27:26 +0000 (19:27 +0000)
committerJan Vesely <jan.vesely@rutgers.edu>
Thu, 21 Jun 2018 19:27:26 +0000 (19:27 +0000)
Reviewed-By: Aaron Watry <awatry@gmail.com>
Tested-By: Aaron Watry <awatry@gmail.com>
Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu>
llvm-svn: 335278

libclc/generic/include/clc/atomic/atomic_dec.h
libclc/generic/include/clc/atomic/atomic_inc.h
libclc/generic/lib/SOURCES
libclc/generic/lib/atomic/atomic_dec.cl [new file with mode: 0644]
libclc/generic/lib/atomic/atomic_inc.cl [new file with mode: 0644]

index 15d0588..a2d82bb 100644 (file)
@@ -1 +1,4 @@
-#define atomic_dec(p) atomic_sub(p, 1)
+_CLC_OVERLOAD _CLC_DECL int atomic_dec (volatile local int *);
+_CLC_OVERLOAD _CLC_DECL int atomic_dec (volatile global int *);
+_CLC_OVERLOAD _CLC_DECL uint atomic_dec (volatile local uint *);
+_CLC_OVERLOAD _CLC_DECL uint atomic_dec (volatile global uint *);
index d8bc342..950a1e1 100644 (file)
@@ -1 +1,4 @@
-#define atomic_inc(p) atomic_add(p, 1)
+_CLC_OVERLOAD _CLC_DECL int atomic_inc (volatile local int *);
+_CLC_OVERLOAD _CLC_DECL int atomic_inc (volatile global int *);
+_CLC_OVERLOAD _CLC_DECL uint atomic_inc (volatile local uint *);
+_CLC_OVERLOAD _CLC_DECL uint atomic_inc (volatile global uint *);
index 565750e..788aee6 100644 (file)
@@ -7,6 +7,8 @@ async/wait_group_events.cl
 atomic/atomic_add.cl
 atomic/atomic_and.cl
 atomic/atomic_cmpxchg.cl
+atomic/atomic_dec.cl
+atomic/atomic_inc.cl
 atomic/atomic_max.cl
 atomic/atomic_min.cl
 atomic/atomic_or.cl
diff --git a/libclc/generic/lib/atomic/atomic_dec.cl b/libclc/generic/lib/atomic/atomic_dec.cl
new file mode 100644 (file)
index 0000000..829aff4
--- /dev/null
@@ -0,0 +1,12 @@
+#include <clc/clc.h>
+
+#define IMPL(TYPE, AS) \
+_CLC_OVERLOAD _CLC_DEF TYPE atomic_dec(volatile AS TYPE *p) { \
+  return __sync_fetch_and_sub(p, (TYPE)1); \
+}
+
+IMPL(int, global)
+IMPL(unsigned int, global)
+IMPL(int, local)
+IMPL(unsigned int, local)
+#undef IMPL
diff --git a/libclc/generic/lib/atomic/atomic_inc.cl b/libclc/generic/lib/atomic/atomic_inc.cl
new file mode 100644 (file)
index 0000000..67a7e8d
--- /dev/null
@@ -0,0 +1,12 @@
+#include <clc/clc.h>
+
+#define IMPL(TYPE, AS) \
+_CLC_OVERLOAD _CLC_DEF TYPE atomic_inc(volatile AS TYPE *p) { \
+  return __sync_fetch_and_add(p, (TYPE)1); \
+}
+
+IMPL(int, global)
+IMPL(unsigned int, global)
+IMPL(int, local)
+IMPL(unsigned int, local)
+#undef IMPL