[Mesa-dev] [PATCH 2/4] libclc: Initial vstore implementation

Aaron Watry awatry at gmail.com
Thu May 23 17:49:41 PDT 2013


Assumes that the target supports byte-addressable stores.

Completely unoptimized.
---
 generic/include/clc/clc.h           |  1 +
 generic/include/clc/shared/vstore.h | 36 ++++++++++++++++++++++++
 generic/lib/SOURCES                 |  1 +
 generic/lib/shared/vstore.cl        | 56 +++++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+)
 create mode 100644 generic/include/clc/shared/vstore.h
 create mode 100644 generic/lib/shared/vstore.cl

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 7937003..10d30e0 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -72,6 +72,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 5d9e3fa..50cc9bd 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -24,5 +24,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..e88ccc5
--- /dev/null
+++ b/generic/lib/shared/vstore.cl
@@ -0,0 +1,56 @@
+#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) { \
+    mem[offset] = vec.s0; \
+    mem[offset+1] = vec.s1; \
+    mem[offset+2] = vec.s2; \
+    mem[offset+3] = vec.s3; \
+  } \
+\
+  _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
+
-- 
1.8.1.2



More information about the mesa-dev mailing list