[Beignet] [PATCH] Backend: add double support to convert_float_rtn(double x)

rander rander.wang at intel.com
Fri Mar 10 01:42:36 UTC 2017


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

diff --git a/backend/src/libocl/include/ocl_float.h b/backend/src/libocl/include/ocl_float.h
index 9058692..e78d38b 100644
--- a/backend/src/libocl/include/ocl_float.h
+++ b/backend/src/libocl/include/ocl_float.h
@@ -108,4 +108,9 @@ INLINE_OVERLOADABLE int __ocl_finitef (float x){
 #define DF_SIGN_OFFSET 63
 #define DF_EXP_BIAS 1023
 
+#define SF_POSITIVE_INF 0x7F800000
+#define SF_NAN 0x7FFFFFFF
+
+#define M_PI 3.1415926535897384626
+
 #endif /* __OCL_FLOAT_H__ */
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index fe5c1ec..add2c56 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -651,6 +651,32 @@ OVERLOADABLE ulong convert_ulong_rtn(double x)
 	return ret;
 }
 
+OVERLOADABLE float  convert_float_rtn(double x)
+{
+	int ret, tmp;
+	long lval = as_long(x);
+	int exp = ((lval & DF_EXP_MASK) >> DF_EXP_OFFSET) - DF_EXP_BIAS;
+	int sign = (lval & DF_SIGN_MASK)?1:0;
+
+	ret = sign;
+	ret = (lval & DF_ABS_MASK) ? ret:0;
+	tmp = 0x1000000 >> (23 - (exp + 149));
+	ret = (exp < -126) ? tmp:ret;
+	long ma = (lval &DF_MAN_MASK);
+	tmp = (lval & DF_MAN_MASK) ? SF_NAN:SF_POSITIVE_INF;
+	ret = (exp == 1024) ? tmp:ret;
+	tmp = SF_POSITIVE_INF;
+	ret = (exp > 127) ? tmp:ret;
+	ret = (lval & DF_ABS_MASK) ? ret:0;
+	tmp = ((exp + 127) << 23) |convert_int(ma >> 29);
+	if((ma & 0x1FFFFFFF) && sign) tmp += 1;
+	ret = ((exp >= -126) && (exp <= 127)) ? tmp:ret;
+	ret |= (sign << 31);
+	float ftemp = as_float(ret);
+
+	return ftemp;
+}
+
 '
 fi
 
-- 
2.7.4



More information about the Beignet mailing list