support OpenCL conversions & type casting function "convert_type_4"
authorHomer Hsing <homer.xing@intel.com>
Fri, 4 Jan 2013 01:40:58 +0000 (09:40 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Wed, 10 Apr 2013 06:51:30 +0000 (14:51 +0800)
backend/src/ocl_stdlib.h
backend/src/ocl_stdlib_str.cpp

index b261b0d..7b12fde 100644 (file)
@@ -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
index c2c6309..88eb80f 100644 (file)
@@ -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"