From cd3c2a8077b5d84a75a7c8f2894a6eb5c878712e Mon Sep 17 00:00:00 2001 From: Homer Hsing Date: Fri, 4 Jan 2013 09:45:00 +0800 Subject: [PATCH] support OpenCL conversions & type casting function "as_uchar4(float f)" --- backend/src/ocl_stdlib.h | 9 +++++++++ backend/src/ocl_stdlib_str.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/backend/src/ocl_stdlib.h b/backend/src/ocl_stdlib.h index 7b12fde..32ed118 100644 --- a/backend/src/ocl_stdlib.h +++ b/backend/src/ocl_stdlib.h @@ -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)); \ } diff --git a/backend/src/ocl_stdlib_str.cpp b/backend/src/ocl_stdlib_str.cpp index 88eb80f..62e0386 100644 --- a/backend/src/ocl_stdlib_str.cpp +++ b/backend/src/ocl_stdlib_str.cpp @@ -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" -- 2.7.4