[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/4] softfloat: fix floatx80 pseudo-denormal comparisons
From: |
Joseph Myers |
Subject: |
[PATCH v2 3/4] softfloat: fix floatx80 pseudo-denormal comparisons |
Date: |
Mon, 4 May 2020 23:39:39 +0000 |
User-agent: |
Alpine 2.21 (DEB 202 2017-01-01) |
The softfloat floatx80 comparisons fail to allow for pseudo-denormals,
which should compare equal to corresponding values with biased
exponent 1 rather than 0. Add an adjustment for that case when
comparing numbers with the same sign.
Note that this fix only changes floatx80_compare_internal, not the
other more specific comparison operations. That is the only
comparison function for floatx80 used in the i386 port, which is the
only supported port with these pseudo-denormal semantics.
Signed-off-by: Joseph Myers <address@hidden>
---
fpu/softfloat.c | 5 +++++
tests/tcg/i386/test-i386-pseudo-denormal.c | 4 ++++
2 files changed, 9 insertions(+)
diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 6094d267b5..8e9c714e6f 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -7966,6 +7966,11 @@ static inline int floatx80_compare_internal(floatx80 a,
floatx80 b,
return 1 - (2 * aSign);
}
} else {
+ /* Normalize pseudo-denormals before comparison. */
+ if ((a.high & 0x7fff) == 0 && a.low & UINT64_C(0x8000000000000000))
+ ++a.high;
+ if ((b.high & 0x7fff) == 0 && b.low & UINT64_C(0x8000000000000000))
+ ++b.high;
if (a.low == b.low && a.high == b.high) {
return float_relation_equal;
} else {
diff --git a/tests/tcg/i386/test-i386-pseudo-denormal.c
b/tests/tcg/i386/test-i386-pseudo-denormal.c
index cfa2a500b0..acf2b9cf03 100644
--- a/tests/tcg/i386/test-i386-pseudo-denormal.c
+++ b/tests/tcg/i386/test-i386-pseudo-denormal.c
@@ -20,5 +20,9 @@ int main(void)
printf("FAIL: pseudo-denormal add\n");
ret = 1;
}
+ if (ld_pseudo_m16382.ld != 0x1p-16382L) {
+ printf("FAIL: pseudo-denormal compare\n");
+ ret = 1;
+ }
return ret;
}
--
2.17.1
--
Joseph S. Myers
address@hidden