[Beignet] [PATCH] Backend: add double support to convert_u|long_rtn(double)

rander rander.wang at intel.com
Thu Mar 9 01:22:35 UTC 2017


Signed-off-by: rander <rander.wang at intel.com>
---
 backend/src/libocl/include/ocl_float.h   |  6 +++-
 backend/src/libocl/script/ocl_convert.sh | 54 +++++++++++++++++++++++++++++++-
 2 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/backend/src/libocl/include/ocl_float.h b/backend/src/libocl/include/ocl_float.h
index 39fd453..9058692 100644
--- a/backend/src/libocl/include/ocl_float.h
+++ b/backend/src/libocl/include/ocl_float.h
@@ -102,6 +102,10 @@ INLINE_OVERLOADABLE int __ocl_finitef (float x){
 #define DF_MIN_NORMAL 0x10000000000000UL
 #define DF_ABS_MASK 0x7FFFFFFFFFFFFFFFUL
 #define DF_POSITIVE_INF 0x7FF0000000000000UL
-
+#define DF_SIGN_MASK 0x8000000000000000UL
+#define DF_IMPLICITE_ONE 0x10000000000000UL
+#define DF_EXP_OFFSET 52
+#define DF_SIGN_OFFSET 63
+#define DF_EXP_BIAS 1023
 
 #endif /* __OCL_FLOAT_H__ */
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index adac9b1..460aefe 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -27,6 +27,9 @@ if [ $1"a" = "-pa" ]; then
     echo
 else
     echo "#include \"ocl_convert.h\""
+    echo "#include \"ocl_float.h\""
+    echo "#include \"ocl_as.h\""
+    echo "#include \"ocl_integer.h\""
     echo
 fi
 
@@ -546,6 +549,53 @@ OVERLOADABLE float __convert_float_rtn(uint x)
 {
     return __convert_float_rtz(x);
 }
+
+OVERLOADABLE long convert_long_rtn(double x)
+{
+	int iexp;
+	long ret;
+	ulong lval = as_ulong(x);
+	uint sign = (lval & DF_SIGN_MASK) >> DF_SIGN_OFFSET;
+	int exp = ((lval & DF_EXP_MASK) >> DF_EXP_OFFSET) - DF_EXP_BIAS;
+	ulong ma = (lval &DF_MAN_MASK);
+
+	ulong ldata = ma |DF_IMPLICITE_ONE;
+	uint shift = abs(exp -DF_EXP_OFFSET);
+	ulong ldataL = ldata << shift;
+	ulong ldataR = ldata >> shift;
+	ret    = (exp > DF_EXP_OFFSET) ? ldataL:ldataR;
+	ret    = (exp >= 0) ? ret:0;
+	iexp = (exp >= 0) ? exp:0;
+
+	ret = sign ? -ret:ret;
+	shift = convert_uint_sat(DF_EXP_OFFSET - iexp);
+	long mask = (1L << shift) - 1;
+	ret = ((ma & mask) || (exp < 0)) ? ret -sign:ret;
+	ret = (lval & DF_ABS_MASK) ? ret:0;
+
+	return ret;
+}
+
+OVERLOADABLE ulong convert_ulong_rtn(double x)
+{
+	int iexp;
+	long ret;
+	long lval = as_long(x);
+	int exp = ((lval & DF_EXP_MASK) >> DF_EXP_OFFSET) - DF_EXP_BIAS;
+	long ma = (lval &DF_MAN_MASK);
+
+	ulong ldata = ma |DF_IMPLICITE_ONE;
+	int shift = abs(exp -DF_EXP_OFFSET);
+	ulong ldataL = ldata << shift;
+	ulong ldataR = ldata >> shift;
+	ret    = (exp > DF_EXP_OFFSET) ? ldataL:ldataR;
+	ret    = (exp >= 0) ? ret:0;
+	iexp = (exp >= 0) ? exp:0;
+	ret    = (lval & DF_ABS_MASK) ? ret:0;
+
+	return ret;
+}
+
 '
 fi
 
@@ -553,7 +603,7 @@ fi
 for vector_length in $VECTOR_LENGTHS; do
     for ftype in $TYPES; do
 	fbasetype=`IFS=:; set -- dummy $ftype; echo $2`
-	if test $fbasetype = "double"; then continue; fi
+	#if test $fbasetype = "double"; then continue; fi
 
 	for ttype in $TYPES; do
 	    tbasetype=`IFS=:; set -- dummy $ttype; echo $2`
@@ -596,6 +646,8 @@ for vector_length in $VECTOR_LENGTHS; do
 			echo "{ return __gen_ocl_rndd(x); }"
 		    elif [ "$fbasetype" = "int" -o "$fbasetype" = "uint" -o "$fbasetype" = "long" -o "$fbasetype" = "ulong" ] && [ "$tbasetype" = "float" ]; then
 			echo "{ return __convert_${tbasetype}_rtn(x); }"
+		    elif [ "$fbasetype" = "double" ]; then
+			echo ";"
 		    else
 			echo "{ return x; }"
 		    fi
-- 
2.7.4



More information about the Beignet mailing list