]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgcc: Fix a bug in _BitInt -> dfp conversions
authorJakub Jelinek <jakub@redhat.com>
Sat, 10 Feb 2024 11:51:39 +0000 (12:51 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sat, 10 Feb 2024 11:51:39 +0000 (12:51 +0100)
The ia32 _BitInt support revealed a bug in floatbitint?d.c.
As can be even guessed from how the code is written in the loop,
the intention was to set inexact to non-zero whenever the remainder
after division wasn't zero, but I've ended up just checking whether
the 2 least significant limbs of the remainder were non-zero.
Now, in the dfp/bitint-4.c test in one case the remainder happens
to have least significant 64 bits zero and then the higher limbs are
non-zero; with 32-bit limbs that means 2 least significant limbs are zero
and so the code acted as if it was exactly divisible.

Fixed thusly.

2024-02-10  Jakub Jelinek  <jakub@redhat.com>

* soft-fp/floatbitintdd.c (__bid_floatbitintdd): Or in all remainder
limbs into inexact rather than just first two.
* soft-fp/floatbitintsd.c (__bid_floatbitintsd): Likewise.
* soft-fp/floatbitinttd.c (__bid_floatbitinttd): Likewise.

libgcc/soft-fp/floatbitintdd.c
libgcc/soft-fp/floatbitintsd.c
libgcc/soft-fp/floatbitinttd.c

index 77c5fd75e0e3db6ac163e5af3271c0f45dbce890..456557294e7eb084c4ef81357cf059376cab2501 100644 (file)
@@ -114,7 +114,7 @@ __bid_floatbitintdd (const UBILtype *i, SItype iprec)
                           buf + BITINT_END (q_limbs - 1, 0), q_limbs);
          inexact = buf[q_limbs + pow10_limbs];
          for (j = 1; j < pow10_limbs; ++j)
-           inexact |= buf[q_limbs + pow10_limbs + 1];
+           inexact |= buf[q_limbs + pow10_limbs + j];
        }
       else
        {
index 5c5ed6cfb7e0edd874c712b25cecdea4ebf83c37..4901aa82af7cb8a3c42aab1a697a18e6ec5b25d7 100644 (file)
@@ -113,7 +113,7 @@ __bid_floatbitintsd (const UBILtype *i, SItype iprec)
                           buf + BITINT_END (q_limbs - 1, 0), q_limbs);
          inexact = buf[q_limbs + pow10_limbs];
          for (j = 1; j < pow10_limbs; ++j)
-           inexact |= buf[q_limbs + pow10_limbs + 1];
+           inexact |= buf[q_limbs + pow10_limbs + j];
        }
       else
        {
index 3bc18e20102197b6b1fa278c64b7b46e75b03ed3..5fff339a8675a34dc448d75881b5b379ea8e058e 100644 (file)
@@ -113,7 +113,7 @@ __bid_floatbitinttd (const UBILtype *i, SItype iprec)
                           buf + BITINT_END (q_limbs - 1, 0), q_limbs);
          inexact = buf[q_limbs + pow10_limbs];
          for (j = 1; j < pow10_limbs; ++j)
-           inexact |= buf[q_limbs + pow10_limbs + 1];
+           inexact |= buf[q_limbs + pow10_limbs + j];
        }
       else
        {