qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2] softfloat: float32_to_float16() should do inexac


From: Alexey Starikovskiy
Subject: [Qemu-devel] [PATCH v2] softfloat: float32_to_float16() should do inexact instead of underflow for rounding case
Date: Thu, 3 May 2012 18:37:56 +0400

IEEE Standard for Floating-Point Arithmetic:
7.5 Underflow
The underflow exception shall be signaled when a tiny non-zero result
is detected. For binary formats, this
shall be either:
a) after rounding — when a non-zero result computed as though the
exponent range were unbounded
would lie strictly between ± b emin, or
b) before rounding — when a non-zero result computed as though both
the exponent range and the
precision were unbounded would lie strictly between ± b emin.

The implementer shall choose how tininess is detected, but shall
detect tininess in the same way for all
operations in radix two, including conversion operations under a
binary rounding attribute.

....

In addition, under default exception handling for underflow, if the
rounded result is inexact — that is, it
differs from what would have been computed were both exponent range
and precision unbounded — the
underflow flag shall be raised and the inexact (see 7.6) exception
shall be signaled. If the rounded result is
exact, no flag is raised and no inexact exception is signaled.

....

7.6 Inexact
Unless stated otherwise, if the rounded result of an operation is
inexact — that is, it differs from what would
have been computed were both exponent range and precision unbounded —
then the inexact exception shall
be signaled. The rounded or overflowed result shall be delivered to
the destination.

Signed-off-by: Alexey Starikovskiy <address@hidden>
---
 fpu/softfloat.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 9e1b5f9..d4a963f 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -3067,7 +3067,11 @@ float16 float32_to_float16(float32 a, flag ieee
STATUS_PARAM)
         mask = 0x00001fff;
     }
     if (aSig & mask) {
-        float_raise( float_flag_underflow STATUS_VAR );
+        if (aExp < -14 &&
+            STATUS(float_detect_tininess) == float_tininess_before_rounding) {
+            float_raise( float_flag_underflow STATUS_VAR);
+        }
+        float_raise( float_flag_inexact STATUS_VAR );
         roundingMode = STATUS(float_rounding_mode);
         switch (roundingMode) {
         case float_round_nearest_even:
@@ -3091,9 +3095,6 @@ float16 float32_to_float16(float32 a, flag ieee
STATUS_PARAM)
             aSig >>= 1;
             aExp++;
         }
-    } else if (aExp < -14
-          && STATUS(float_detect_tininess) == float_tininess_before_rounding) {
-        float_raise( float_flag_underflow STATUS_VAR);
     }

     if (ieee) {

Attachment: float32_to_float16b-L2-RD0-1-app
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]