summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomer Hsing <homer.xing@intel.com>2013-01-04 09:40:58 +0800
committerZhigang Gong <zhigang.gong@linux.intel.com>2013-04-10 14:51:30 +0800
commit6795d04dd0de4420ea7dc1330f238e9f9fa7e81c (patch)
tree75634b2332e07704c368fd7b05e718bfc8754315
parente6b7c1bc015f924402ae2dcb40ecd304e0d2bece (diff)
support OpenCL conversions & type casting function "convert_type_4"
-rw-r--r--backend/src/ocl_stdlib.h26
-rw-r--r--backend/src/ocl_stdlib_str.cpp26
2 files changed, 52 insertions, 0 deletions
diff --git a/backend/src/ocl_stdlib.h b/backend/src/ocl_stdlib.h
index b261b0d6..7b12fde2 100644
--- a/backend/src/ocl_stdlib.h
+++ b/backend/src/ocl_stdlib.h
@@ -65,6 +65,32 @@ typedef struct _image3d_t* image3d_t;
typedef uint sampler_t;
typedef size_t event_t;
/////////////////////////////////////////////////////////////////////////////
+// OpenCL conversions & type casting
+/////////////////////////////////////////////////////////////////////////////
+#define DEF(type, n, type2) type##n INLINE_OVERLOADABLE convert_##type##n(type2##n d) { \
+ return (type##n)((type)(d.s0), (type)(d.s1), (type)(d.s2), (type)(d.s3)); \
+ }
+#define DEF2(type) DEF(type, 4, char); \
+ DEF(type, 4, uchar); \
+ DEF(type, 4, short); \
+ DEF(type, 4, ushort); \
+ DEF(type, 4, int); \
+ DEF(type, 4, uint); \
+ DEF(type, 4, long); \
+ DEF(type, 4, ulong); \
+ DEF(type, 4, float);
+DEF2(char);
+DEF2(uchar);
+DEF2(short);
+DEF2(ushort);
+DEF2(int);
+DEF2(uint);
+DEF2(long);
+DEF2(ulong);
+DEF2(float);
+#undef DEF2
+#undef DEF
+/////////////////////////////////////////////////////////////////////////////
// OpenCL preprocessor directives & macros
/////////////////////////////////////////////////////////////////////////////
#define __OPENCL_VERSION__ 110
diff --git a/backend/src/ocl_stdlib_str.cpp b/backend/src/ocl_stdlib_str.cpp
index c2c6309f..88eb80f7 100644
--- a/backend/src/ocl_stdlib_str.cpp
+++ b/backend/src/ocl_stdlib_str.cpp
@@ -69,6 +69,32 @@ std::string ocl_stdlib_str =
"typedef uint sampler_t;\n"
"typedef size_t event_t;\n"
"/////////////////////////////////////////////////////////////////////////////\n"
+"// OpenCL conversions & type casting\n"
+"/////////////////////////////////////////////////////////////////////////////\n"
+"#define DEF(type, n, type2) type##n INLINE_OVERLOADABLE convert_##type##n(type2##n d) {\\\n"
+" return (type##n)((type)(d.s0), (type)(d.s1), (type)(d.s2), (type)(d.s3));\\\n"
+"}\n"
+"#define DEF2(type) DEF(type, 4, char); \\\n"
+" DEF(type, 4, uchar); \\\n"
+" DEF(type, 4, short); \\\n"
+" DEF(type, 4, ushort); \\\n"
+" DEF(type, 4, int); \\\n"
+" DEF(type, 4, uint); \\\n"
+" DEF(type, 4, long); \\\n"
+" DEF(type, 4, ulong); \\\n"
+" DEF(type, 4, float);\n"
+"DEF2(char);\n"
+"DEF2(uchar);\n"
+"DEF2(short);\n"
+"DEF2(ushort);\n"
+"DEF2(int);\n"
+"DEF2(uint);\n"
+"DEF2(long);\n"
+"DEF2(ulong);\n"
+"DEF2(float);\n"
+"#undef DEF2\n"
+"#undef DEF\n"
+"/////////////////////////////////////////////////////////////////////////////\n"
"// OpenCL preprocessor directives & macros\n"
"/////////////////////////////////////////////////////////////////////////////\n"
"#define __OPENCL_VERSION__ 110\n"