diff mbox

[v2,02/16] softloat: disable floatx80_invalid_encoding() for m68k

Message ID 20170130181634.13934-3-laurent@vivier.eu (mailing list archive)
State New, archived
Headers show

Commit Message

Laurent Vivier Jan. 30, 2017, 6:16 p.m. UTC
According to the comment, this definition of invalid encoding is given
by intel developer's manual, and doesn't work with the behavior
of 680x0 FPU.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 fpu/softfloat.c         | 20 ++++++++++++++++++++
 include/fpu/softfloat.h | 15 ---------------
 2 files changed, 20 insertions(+), 15 deletions(-)

Comments

Peter Maydell Jan. 30, 2017, 7:15 p.m. UTC | #1
On 30 January 2017 at 18:16, Laurent Vivier <laurent@vivier.eu> wrote:
> According to the comment, this definition of invalid encoding is given
> by intel developer's manual, and doesn't work with the behavior
> of 680x0 FPU.
>
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>

Part of the reason these checks are here is that the code
behind them doesn't always cope nicely with the invalid
encodings.
https://lists.nongnu.org/archive/html/qemu-devel/2016-08/msg01991.html
has an x86 test case for certain sqrt inputs that cause
the floatx80_sqrt() function to go into an infinite loop,
for instance.

I guess we need to look more carefully at exactly what the
m68k does for these encodings (maybe have a 'normalize value'
function which squashes them down to whatever the equivalent
non-weird encoding is?).

thanks
-- PMM
Andreas Schwab Jan. 30, 2017, 10:47 p.m. UTC | #2
On Jan 30 2017, Peter Maydell <peter.maydell@linaro.org> wrote:

> I guess we need to look more carefully at exactly what the
> m68k does for these encodings (maybe have a 'normalize value'
> function which squashes them down to whatever the equivalent
> non-weird encoding is?).

On the m68k, the concept of pseudo-inf/nan doesn't exist, because the
integer bit is don't-care for inf and nan.  The combination of a zero
integer bit with other non-zero biased exponents is called unnormal, and
the 68881/2 will always convert them to normal/denormal/zero on input.
(The 68040/60 don't support denormal/unnormal in hardware and lets the
support library handle them, which presumably works the same way as the
68881/2.)

Andreas.
diff mbox

Patch

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index c295f31..3aa05c1 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -4799,6 +4799,26 @@  int float64_unordered_quiet(float64 a, float64 b, float_status *status)
 }
 
 /*----------------------------------------------------------------------------
+| Return whether the given value is an invalid floatx80 encoding.
+| Invalid floatx80 encodings arise when the integer bit is not set, but
+| the exponent is not zero. The only times the integer bit is permitted to
+| be zero is in subnormal numbers and the value zero.
+| This includes what the Intel software developer's manual calls pseudo-NaNs,
+| pseudo-infinities and un-normal numbers. It does not include
+| pseudo-denormals, which must still be correctly handled as inputs even
+| if they are never generated as outputs.
+*----------------------------------------------------------------------------*/
+static inline bool floatx80_invalid_encoding(floatx80 a)
+{
+#if defined(TARGET_M68K)
+    return 0;
+#else
+    return (a.low & (1ULL << 63)) == 0 && (a.high & 0x7FFF) != 0;
+#endif
+}
+
+
+/*----------------------------------------------------------------------------
 | Returns the result of converting the extended double-precision floating-
 | point value `a' to the 32-bit two's complement integer format.  The
 | conversion is performed according to the IEC/IEEE Standard for Binary
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index 14f8383..1bde349 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -658,21 +658,6 @@  static inline int floatx80_is_any_nan(floatx80 a)
     return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
 }
 
-/*----------------------------------------------------------------------------
-| Return whether the given value is an invalid floatx80 encoding.
-| Invalid floatx80 encodings arise when the integer bit is not set, but
-| the exponent is not zero. The only times the integer bit is permitted to
-| be zero is in subnormal numbers and the value zero.
-| This includes what the Intel software developer's manual calls pseudo-NaNs,
-| pseudo-infinities and un-normal numbers. It does not include
-| pseudo-denormals, which must still be correctly handled as inputs even
-| if they are never generated as outputs.
-*----------------------------------------------------------------------------*/
-static inline bool floatx80_invalid_encoding(floatx80 a)
-{
-    return (a.low & (1ULL << 63)) == 0 && (a.high & 0x7FFF) != 0;
-}
-
 #define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)
 #define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)
 #define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)