support OpenCL conversions & type casting function "as_uchar4(float f)"
authorHomer Hsing <homer.xing@intel.com>
Fri, 4 Jan 2013 01:45:00 +0000 (09:45 +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 7b12fde..32ed118 100644 (file)
@@ -67,6 +67,15 @@ typedef size_t event_t;
 /////////////////////////////////////////////////////////////////////////////
 // OpenCL conversions & type casting
 /////////////////////////////////////////////////////////////////////////////
+union type_cast_4_b {
+  float f;
+  uchar4 u4;
+};
+uchar4 INLINE_OVERLOADABLE as_uchar4(float f) {
+    union type_cast_4_b u;
+    u.f = f;
+    return u.u4;
+}
 #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)); \
  }
index 88eb80f..62e0386 100644 (file)
@@ -71,6 +71,15 @@ std::string ocl_stdlib_str =
 "/////////////////////////////////////////////////////////////////////////////\n"
 "// OpenCL conversions & type casting\n"
 "/////////////////////////////////////////////////////////////////////////////\n"
+"union type_cast_4_b {\n"
+"  float f;\n"
+"  uchar4 u4;\n"
+"};\n"
+"uchar4 INLINE_OVERLOADABLE as_uchar4(float f) {\n"
+"    union type_cast_4_b u;\n"
+"    u.f = f;\n"
+"    return u.u4;\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"