[Beignet] [PATCH] Fix a convert float to long bug.

Yang Rong rong.r.yang at intel.com
Sun Mar 2 19:25:19 PST 2014


When convert some special float values, slight large than LONG_MAX, to long with sat,
will error. Simply using LONG_MAX when float value equal to LONG_MAX.

Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
 backend/src/gen_convert.sh | 8 ++++----
 backend/src/ocl_convert.h  | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/backend/src/gen_convert.sh b/backend/src/gen_convert.sh
index f0562a7..b940222 100755
--- a/backend/src/gen_convert.sh
+++ b/backend/src/gen_convert.sh
@@ -99,7 +99,7 @@ DEF(uint, float);
 
 #define DEF(DSTTYPE, SRCTYPE, MIN, MAX) \
   INLINE_OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
-    return x > MAX ? (DSTTYPE)MAX : x < MIN ? (DSTTYPE)MIN : x; \
+    return x >= MAX ? (DSTTYPE)MAX : x <= MIN ? (DSTTYPE)MIN : x; \
   }
 DEF(char, long, -128, 127);
 DEF(uchar, long, 0, 255);
@@ -113,7 +113,7 @@ DEF(ulong, float, 0, 1.8446744073709552e+19f);
 
 #define DEF(DSTTYPE, SRCTYPE, MAX) \
   INLINE_OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
-    return x > MAX ? (DSTTYPE)MAX : x; \
+    return x >= MAX ? (DSTTYPE)MAX : x; \
   }
 DEF(char, ulong, 127);
 DEF(uchar, ulong, 255);
@@ -125,12 +125,12 @@ DEF(uint, ulong, 0xffffffffu);
 
 INLINE_OVERLOADABLE long convert_long_sat(ulong x) {
   ulong MAX = 0x7ffffffffffffffful;
-  return x > MAX ? MAX : x;
+  return x >= MAX ? MAX : x;
 }
 
 #define DEF(DSTTYPE, SRCTYPE) \
   INLINE_OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
-    return x < 0 ? 0 : x; \
+    return x <= 0 ? 0 : x; \
   }
 DEF(ushort, char);
 DEF(uint, char);
diff --git a/backend/src/ocl_convert.h b/backend/src/ocl_convert.h
index 7ec2aec..8326768 100644
--- a/backend/src/ocl_convert.h
+++ b/backend/src/ocl_convert.h
@@ -2281,7 +2281,7 @@ DEF(uint, float);
 
 #define DEF(DSTTYPE, SRCTYPE, MIN, MAX) \
   INLINE_OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
-    return x > MAX ? (DSTTYPE)MAX : x < MIN ? (DSTTYPE)MIN : x; \
+    return x >= MAX ? (DSTTYPE)MAX : x <= MIN ? (DSTTYPE)MIN : x; \
   }
 DEF(char, long, -128, 127);
 DEF(uchar, long, 0, 255);
@@ -2295,7 +2295,7 @@ DEF(ulong, float, 0, 1.8446744073709552e+19f);
 
 #define DEF(DSTTYPE, SRCTYPE, MAX) \
   INLINE_OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
-    return x > MAX ? (DSTTYPE)MAX : x; \
+    return x >= MAX ? (DSTTYPE)MAX : x; \
   }
 DEF(char, ulong, 127);
 DEF(uchar, ulong, 255);
@@ -2307,12 +2307,12 @@ DEF(uint, ulong, 0xffffffffu);
 
 INLINE_OVERLOADABLE long convert_long_sat(ulong x) {
   ulong MAX = 0x7ffffffffffffffful;
-  return x > MAX ? MAX : x;
+  return x >= MAX ? MAX : x;
 }
 
 #define DEF(DSTTYPE, SRCTYPE) \
   INLINE_OVERLOADABLE DSTTYPE convert_ ## DSTTYPE ## _sat(SRCTYPE x) { \
-    return x < 0 ? 0 : x; \
+    return x <= 0 ? 0 : x; \
   }
 DEF(ushort, char);
 DEF(uint, char);
-- 
1.8.3.2



More information about the Beignet mailing list