[Beignet] [PATCH] backend: add convert_double(long)
rander
rander.wang at intel.com
Tue Mar 21 05:15:02 UTC 2017
add rounding mode rtp. Do bit operations
according to IEEE754 spec
Signed-off-by: rander <rander.wang at intel.com>
---
backend/src/libocl/script/ocl_convert.sh | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index e1b4c90..e7969b7 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -1324,6 +1324,30 @@ OVERLOADABLE double convert_double_rte(ulong x)
return as_double(ret);
}
+
+OVERLOADABLE double convert_double_rtp(long x)
+{
+ long exp;
+ long ret, ma, tmp;
+ int sign = (x & DF_SIGN_MASK) ? 1:0;
+
+ long absX = abs(x);
+ int msbOne = 64 -clz(absX);
+ exp = msbOne + DF_EXP_BIAS - 1;
+ ret = (exp << 52);
+ int shift = abs(53 - msbOne);
+ tmp = ret | ((absX << shift) &DF_MAN_MASK);
+
+ ma = (absX & ((0x1 << shift) - 1));
+ ret |= (absX >> shift) &DF_MAN_MASK;
+ if(ma && !sign) ret += 1;
+
+ ret = (msbOne < 54) ? tmp:ret;
+ ret = (msbOne == 0) ? 0:ret;
+
+ ret |= (x & DF_SIGN_MASK);
+ return as_double(ret);
+}
'
fi
--
2.7.4
More information about the Beignet
mailing list