summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Watry <awatry@gmail.com>2013-04-17 18:05:15 -0500
committerAaron Watry <awatry@gmail.com>2013-04-17 18:05:15 -0500
commit0e7f8e746530d5bad3634c6ca73f35b221709b01 (patch)
treeac930152997d7e3bbbf72d0f88c9e59de0a05f82
parent0f8bba36d1ce486d30ce552038128ea5076cb458 (diff)
libclc: Initial vstore*() implementation
Caveats: 1) Does NOT implement half operations. 2) Assumes that cl_khr_byte_addressable_store is available for the char/short store operations.
-rw-r--r--generic/include/clc/clc.h1
-rw-r--r--generic/include/clc/shared/vstore.h36
-rw-r--r--generic/lib/SOURCES1
-rw-r--r--generic/lib/shared/vstore.cl54
4 files changed, 92 insertions, 0 deletions
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index e43910b..ffa2a24 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -74,6 +74,7 @@
#include <clc/shared/max.h>
#include <clc/shared/min.h>
#include <clc/shared/vload.h>
+#include <clc/shared/vstore.h>
/* 6.11.5 Geometric Functions */
#include <clc/geometric/cross.h>
diff --git a/generic/include/clc/shared/vstore.h b/generic/include/clc/shared/vstore.h
new file mode 100644
index 0000000..1f784f8
--- /dev/null
+++ b/generic/include/clc/shared/vstore.h
@@ -0,0 +1,36 @@
+#define _CLC_VSTORE_DECL(PRIM_TYPE, VEC_TYPE, WIDTH, ADDR_SPACE) \
+ _CLC_OVERLOAD _CLC_DECL void vstore##WIDTH(VEC_TYPE vec, size_t offset, ADDR_SPACE PRIM_TYPE *out);
+
+#define _CLC_VECTOR_VSTORE_DECL(PRIM_TYPE, ADDR_SPACE) \
+ _CLC_VSTORE_DECL(PRIM_TYPE, PRIM_TYPE##2, 2, ADDR_SPACE) \
+ _CLC_VSTORE_DECL(PRIM_TYPE, PRIM_TYPE##3, 3, ADDR_SPACE) \
+ _CLC_VSTORE_DECL(PRIM_TYPE, PRIM_TYPE##4, 4, ADDR_SPACE) \
+ _CLC_VSTORE_DECL(PRIM_TYPE, PRIM_TYPE##8, 8, ADDR_SPACE) \
+ _CLC_VSTORE_DECL(PRIM_TYPE, PRIM_TYPE##16, 16, ADDR_SPACE)
+
+#define _CLC_VECTOR_VSTORE_PRIM1(PRIM_TYPE) \
+ _CLC_VECTOR_VSTORE_DECL(PRIM_TYPE, __private) \
+ _CLC_VECTOR_VSTORE_DECL(PRIM_TYPE, __local) \
+ _CLC_VECTOR_VSTORE_DECL(PRIM_TYPE, __global) \
+
+#define _CLC_VECTOR_VSTORE_PRIM() \
+ _CLC_VECTOR_VSTORE_PRIM1(char) \
+ _CLC_VECTOR_VSTORE_PRIM1(uchar) \
+ _CLC_VECTOR_VSTORE_PRIM1(short) \
+ _CLC_VECTOR_VSTORE_PRIM1(ushort) \
+ _CLC_VECTOR_VSTORE_PRIM1(int) \
+ _CLC_VECTOR_VSTORE_PRIM1(uint) \
+ _CLC_VECTOR_VSTORE_PRIM1(long) \
+ _CLC_VECTOR_VSTORE_PRIM1(ulong) \
+ _CLC_VECTOR_VSTORE_PRIM1(float) \
+
+#ifdef cl_khr_fp64
+#define _CLC_VECTOR_VSTORE() \
+ _CLC_VECTOR_VSTORE_PRIM1(double) \
+ _CLC_VECTOR_VSTORE_PRIM()
+#else
+#define _CLC_VECTOR_VSTORE() \
+ _CLC_VECTOR_VSTORE_PRIM()
+#endif
+
+_CLC_VECTOR_VSTORE()
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 2703fbe..ccbb59a 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -26,5 +26,6 @@ shared/clamp.cl
shared/max.cl
shared/min.cl
shared/vload.cl
+shared/vstore.cl
workitem/get_global_id.cl
workitem/get_global_size.cl
diff --git a/generic/lib/shared/vstore.cl b/generic/lib/shared/vstore.cl
new file mode 100644
index 0000000..522b1d6
--- /dev/null
+++ b/generic/lib/shared/vstore.cl
@@ -0,0 +1,54 @@
+#include <clc/clc.h>
+
+#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
+
+#define VSTORE_VECTORIZE(PRIM_TYPE, ADDR_SPACE) \
+ _CLC_OVERLOAD _CLC_DEF void vstore2(PRIM_TYPE##2 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \
+ mem[offset] = vec.s0; \
+ mem[offset+1] = vec.s1; \
+ } \
+\
+ _CLC_OVERLOAD _CLC_DEF void vstore3(PRIM_TYPE##3 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \
+ mem[offset] = vec.s0; \
+ mem[offset+1] = vec.s1; \
+ mem[offset+2] = vec.s2; \
+ } \
+\
+ _CLC_OVERLOAD _CLC_DEF void vstore4(PRIM_TYPE##4 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \
+ vstore2(vec.lo, offset, mem); \
+ vstore2(vec.hi, offset+2, mem); \
+ } \
+\
+ _CLC_OVERLOAD _CLC_DEF void vstore8(PRIM_TYPE##8 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \
+ vstore4(vec.lo, offset, mem); \
+ vstore4(vec.hi, offset+4, mem); \
+ } \
+\
+ _CLC_OVERLOAD _CLC_DEF void vstore16(PRIM_TYPE##16 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \
+ vstore8(vec.lo, offset, mem); \
+ vstore8(vec.hi, offset+8, mem); \
+ } \
+
+#define VSTORE_ADDR_SPACES(SCALAR_GENTYPE) \
+ VSTORE_VECTORIZE(SCALAR_GENTYPE, __private) \
+ VSTORE_VECTORIZE(SCALAR_GENTYPE, __local) \
+ VSTORE_VECTORIZE(SCALAR_GENTYPE, __global) \
+
+#define VSTORE_TYPES() \
+ VSTORE_ADDR_SPACES(char) \
+ VSTORE_ADDR_SPACES(uchar) \
+ VSTORE_ADDR_SPACES(short) \
+ VSTORE_ADDR_SPACES(ushort) \
+ VSTORE_ADDR_SPACES(int) \
+ VSTORE_ADDR_SPACES(uint) \
+ VSTORE_ADDR_SPACES(long) \
+ VSTORE_ADDR_SPACES(ulong) \
+ VSTORE_ADDR_SPACES(float) \
+
+VSTORE_TYPES()
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+ VSTORE_ADDR_SPACES(double)
+#endif
+