[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] softfloat: roundAndPackFloat16 should return FPInfi
From: |
Xiangyu Hu |
Subject: |
[Qemu-devel] [PATCH] softfloat: roundAndPackFloat16 should return FPInfinity and FPMaxNormal based on overflow_to_inf. |
Date: |
Mon, 9 Feb 2015 14:56:07 +0000 |
Flag overflow_to_inf is specified by ARM manual to decide if
FPInfinity(sign) or FPMaxNormal(sign) is returned. Current
codepath fails to check it.
Fixed by adding overflow_to_inf flag to return infinity when it's
true and maxnormal otherwise.
Signed-off-by: Xiangyu Hu <address@hidden>
---
fpu/softfloat.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index f1170fe..409a574 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -3377,6 +3377,7 @@ static float32 roundAndPackFloat16(flag zSign,
int_fast16_t zExp,
uint32_t increment;
bool rounding_bumps_exp;
bool is_tiny = false;
+ bool overflow_to_inf = false;
/* Calculate the mask of bits of the mantissa which are not
* representable in half-precision and will be lost.
@@ -3398,18 +3399,23 @@ static float32 roundAndPackFloat16(flag zSign,
int_fast16_t zExp,
if ((zSig & mask) == increment) {
increment = zSig & (increment << 1);
}
+ overflow_to_inf = true;
break;
case float_round_ties_away:
increment = (mask + 1) >> 1;
+ overflow_to_inf = true;
break;
case float_round_up:
increment = zSign ? 0 : mask;
+ overflow_to_inf = (zSign == 0);
break;
case float_round_down:
increment = zSign ? mask : 0;
+ overflow_to_inf = (zSign == 1);
break;
default: /* round_to_zero */
increment = 0;
+ overflow_to_inf = false;
break;
}
@@ -3418,7 +3424,11 @@ static float32 roundAndPackFloat16(flag zSign,
int_fast16_t zExp,
if (zExp > maxexp || (zExp == maxexp && rounding_bumps_exp)) {
if (ieee) {
float_raise(float_flag_overflow | float_flag_inexact, status);
- return packFloat16(zSign, 0x1f, 0);
+ if (overflow_to_inf) {
+ return packFloat16(zSign, 0x1f, 0);
+ } else {
+ return packFloat16(zSign, 0x1e, 0x3ff);
+ }
} else {
float_raise(float_flag_invalid, status);
return packFloat16(zSign, 0x1f, 0x3ff);
--
1.9.1
- [Qemu-devel] [PATCH] softfloat: roundAndPackFloat16 should return FPInfinity and FPMaxNormal based on overflow_to_inf.,
Xiangyu Hu <=