qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] softfloat: roundAndPackFloat16 should return FPInfinity and FPMaxNormal based on overflow_to_inf.
@ 2015-02-09 14:56 Xiangyu Hu
  2015-02-11 13:23 ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Xiangyu Hu @ 2015-02-09 14:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, alex.bennee, Xiangyu Hu

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 <libhu.so@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-12  6:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-09 14:56 [Qemu-devel] [PATCH] softfloat: roundAndPackFloat16 should return FPInfinity and FPMaxNormal based on overflow_to_inf Xiangyu Hu
2015-02-11 13:23 ` Peter Maydell
2015-02-12  6:25   ` Xiangyu Hu
2015-02-12  6:32     ` Peter Maydell
2015-02-12  6:29   ` Xiangyu Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).