diff options
author | Yang Rong <rong.r.yang@intel.com> | 2015-10-21 15:27:10 +0800 |
---|---|---|
committer | Yang Rong <rong.r.yang@intel.com> | 2015-10-21 16:49:27 +0800 |
commit | 99041b53d94d4732d9b7d99fa44b06b88ddd71e9 (patch) | |
tree | 908cd38f99ce8ee369c1e16a43d54d9970636178 | |
parent | cbce909da1984136e77b9efd0b24f97b19e9cc6d (diff) |
LibOcl: Fix float convert to long/ulong bug.
If the float overflow, convert to long/ulong is undef. So must use long/ulong's max and min value
as return value.
Also refine long to other integer type sat convert. Use to statement to avoid generate if/else/endif.
Signed-off-by: Yang Rong <rong.r.yang@intel.com>
Reviewed-by: Ruiling Song <ruiling.song@intel.com>
-rwxr-xr-x | backend/src/libocl/script/ocl_convert.sh | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh index 4f720fe9..7599a66c 100755 --- a/backend/src/libocl/script/ocl_convert.sh +++ b/backend/src/libocl/script/ocl_convert.sh @@ -161,7 +161,8 @@ else echo ' #define DEF(DSTTYPE, SRCTYPE, MIN, MAX) \ OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \ - return x >= MAX ? (DSTTYPE)MAX : x <= MIN ? (DSTTYPE)MIN : x; \ + x = x >= MAX ? MAX : x; \ + return x <= MIN ? (DSTTYPE)MIN : (DSTTYPE)x; \ } ' fi @@ -173,8 +174,27 @@ DEF(short, long, -32768, 32767); DEF(ushort, long, 0, 65535); DEF(int, long, -0x7fffffff-1, 0x7fffffff); DEF(uint, long, 0, 0xffffffffu); -DEF(long, float, -9.223372036854776e+18f, 9.223372036854776e+18f); -DEF(ulong, float, 0, 1.8446744073709552e+19f); +#undef DEF +' + +if [ $1"a" = "-pa" ]; then + echo " +#define DEF(DSTTYPE, SRCTYPE, SRC_MIN, SRC_MAX, DST_MIN, DST_MAX) \ +OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x);" +else + echo ' +//convert float to long/ulong must take care of overflow, if overflow the value is undef. +#define DEF(DSTTYPE, SRCTYPE, SRC_MIN, SRC_MAX, DST_MIN, DST_MAX) \ +OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \ + DSTTYPE y = x >= SRC_MAX ? DST_MAX : (DSTTYPE)x; \ + return x <= SRC_MIN ? DST_MIN : y; \ +} +' +fi + +echo ' +DEF(long, float, -0x1.0p63, 0x1.0p63, 0x8000000000000000, 0x7fffffffffffffff); +DEF(ulong, float, 0, 0x1.0p64, 0, 0xffffffffffffffff); #undef DEF ' |