summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorrander <rander.wang@intel.com>2017-03-21 15:28:58 +0800
committerYang Rong <rong.r.yang@intel.com>2017-04-17 16:08:48 +0800
commitc73c1bb648acaa2cf41ccabd66b3b644fcae2a63 (patch)
tree48c39a59b9ea628a2ea3f1d1b041a7614f76e6bf /backend
parent6b25d544daf7d2771d31fc24e854d684e6876c8d (diff)
backend: add convert_double_rtn(long)
do bit operations according to IEEE754 spec Signed-off-by: rander <rander.wang@intel.com> Tested-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'backend')
-rwxr-xr-xbackend/src/libocl/script/ocl_convert.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index e7969b76..3061bcc1 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -1348,6 +1348,30 @@ OVERLOADABLE double convert_double_rtp(long x)
ret |= (x & DF_SIGN_MASK);
return as_double(ret);
}
+
+OVERLOADABLE double convert_double_rtn(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