[Beignet] [PATCH] backend: add convert_float_rtp(double)
rander
rander.wang at intel.com
Mon Mar 20 06:03:09 UTC 2017
do bit operations according to IEEE754 spec
Signed-off-by: rander <rander.wang at intel.com>
---
backend/src/libocl/script/ocl_convert.sh | 36 ++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index aa36a67..6374946 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -717,6 +717,42 @@ OVERLOADABLE float convert_float_rtz(double x)
return ftemp;
}
+OVERLOADABLE float convert_float_rtp(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;
+ long ma = (lval &DF_MAN_MASK);
+
+ int fval = ((exp + 127) << 23) |convert_int(ma >> 29);
+ if((ma & 0x1FFFFFFF) && !sign) fval += 1;
+ ret = fval;
+
+ ma |= DF_IMPLICITE_ONE;
+ tmp = ma >> (-exp - 97);
+ long shift = (1UL << (-exp - 97)) -1UL;
+ if((ma & shift) && !sign) tmp += 1;
+ ret = (exp < -126) ? tmp:ret;
+
+ tmp = 0 ;
+ if(!sign) tmp |= 1;
+ ret = (exp < -149) ? tmp:ret;
+
+ tmp = 0x7F7FFFFF;
+ if(!sign) tmp = 0x7F800000;
+ ret = (exp > 127) ? tmp:ret;
+
+ tmp = (lval & DF_MAN_MASK) ? 0x7FFFFFFF:0x7F800000;
+ ret = (exp == 1024) ? tmp:ret;
+
+ ret = ((lval & DF_ABS_MASK) == 0) ? 0:ret;
+
+ ret |= (sign << 31);
+ float ftemp = as_float(ret);
+ return ftemp;
+}
+
OVERLOADABLE long convert_long_rte(double x)
{
long lval = as_long(x);
--
2.7.4
More information about the Beignet
mailing list