[Beignet] [PATCH] Backend: add double support to convert_u|char|short|int|long_rtz(double x) rtz can be done with rtn with usigned type. for signed type, rtn with abs(x), then add the sign effect

rander rander.wang at intel.com
Fri Mar 10 01:43:44 UTC 2017


Signed-off-by: rander <rander.wang at intel.com>
---
 backend/src/libocl/script/ocl_convert.sh | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index 53fb82c..ffe9397 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -557,7 +557,7 @@ OVERLOADABLE char convert_char_rtn(double x)
 
 OVERLOADABLE uchar convert_uchar_rtn(double x)
 {
-	return (uchar)convert_int_rtn(x);
+	return (uchar)convert_uint_rtn(x);
 }
 
 OVERLOADABLE short convert_short_rtn(double x)
@@ -567,7 +567,7 @@ OVERLOADABLE short convert_short_rtn(double x)
 
 OVERLOADABLE ushort convert_ushort_rtn(double x)
 {
-	return (ushort)convert_int_rtn(x);
+	return (ushort)convert_uint_rtn(x);
 }
 
 OVERLOADABLE int convert_int_rtn(double x)
@@ -722,6 +722,27 @@ for ttype in $ITYPES; do
 	fi
 done
 
+IUTYPES="ulong:8 uint:4 ushort:2 uchar:1"
+for ttype in $IUTYPES; do
+	tbasetype=`IFS=:; set -- dummy $ttype; echo $2`
+	if [ $1"a" != "-pa" ]; then
+	echo "OVERLOADABLE $tbasetype convert_${tbasetype}_rtz(double x)"
+	echo "{ double lx = (x < 0) ? 0:x;"
+	echo " return convert_${tbasetype}_rtn(lx);}"
+	fi
+done
+
+ITYPES="long:8 int:4 short:2 char:1"
+for ttype in $ITYPES; do
+	tbasetype=`IFS=:; set -- dummy $ttype; echo $2`
+	if [ $1"a" != "-pa" ]; then
+	echo "OVERLOADABLE $tbasetype convert_${tbasetype}_rtz(double x)"
+	echo "{ double lx = (x < 0) ? -x:x;"
+	echo " $tbasetype tmp = convert_u${tbasetype}_rtn(lx);"
+	echo "return (x < 0) ? -tmp:tmp;}"
+	fi
+done
+
 # convert_DSTTYPE_ROUNDING function
 for vector_length in $VECTOR_LENGTHS; do
     for ftype in $TYPES; do
-- 
2.7.4



More information about the Beignet mailing list