summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrander <rander.wang@intel.com>2017-03-20 13:46:46 +0800
committerYang Rong <rong.r.yang@intel.com>2017-04-17 16:08:48 +0800
commitf123b40c7888fa2f34971c0b61d51e75dcd44aa7 (patch)
treec47a69cba757292649e4bddc6956dff42787e26f
parentaa4c02eac877cbd9bbaed2da42ffa215da0d4726 (diff)
backend: refine convert_float_rtn(double x)
deal with every corner case (-+inf, NAN...)when convert Signed-off-by: rander <rander.wang@intel.com> Tested-by: Yang Rong <rong.r.yang@intel.com>
-rwxr-xr-xbackend/src/libocl/script/ocl_convert.sh35
1 files changed, 23 insertions, 12 deletions
diff --git a/backend/src/libocl/script/ocl_convert.sh b/backend/src/libocl/script/ocl_convert.sh
index bc02de38..f063f095 100755
--- a/backend/src/libocl/script/ocl_convert.sh
+++ b/backend/src/libocl/script/ocl_convert.sh
@@ -657,23 +657,34 @@ OVERLOADABLE float convert_float_rtn(double x)
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);
- ret = sign;
- ret = (lval & DF_ABS_MASK) ? ret:0;
- tmp = 0x1000000 >> (23 - (exp + 149));
+ 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;
- 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;
+
+ tmp = sign;
+ ret = (exp < -149) ? tmp:ret;
+
+ tmp = sign ? 0x7F800000:0x7F7FFFFF;
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;
+
+ tmp = (lval & DF_MAN_MASK) ? 0x7FFFFFFF:0x7F800000;
+ ret = (exp == 1024) ? tmp:ret;
+
+ tmp = sign ? (0xFF800000) : (0x7F7FFFFF);
+ ret = ((exp == 1023) && (ma == DF_MAN_MASK)) ? tmp:ret;
+
+ ret = ((lval & DF_ABS_MASK) == 0) ? 0:ret;
+
ret |= (sign << 31);
float ftemp = as_float(ret);
-
return ftemp;
}