]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgcc: Small bitint_reduce_prec big-endian fixes
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 May 2025 06:20:16 +0000 (08:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 May 2025 06:20:16 +0000 (08:20 +0200)
The big-endian _BitInt support in libgcc was written without any
testing and so I haven't discovered I've made one mistake in it
(in multiple places).
The bitint_reduce_prec function attempts to optimize inputs
which have some larger precision but at runtime they are found
to need smaller number of limbs.
For little-endian that is handled just by returning smaller
precision (or negative precision for signed), but for
big-endian we need to adjust the passed in limb pointer so that
when it returns smaller precision the argument still contains
the least significant limbs for the returned precision.

2025-05-20  Jakub Jelinek  <jakub@redhat.com>

* libgcc2.c (bitint_reduce_prec): For big endian
__LIBGCC_BITINT_ORDER__ use ++*p and --*p instead of
++p and --p.
* soft-fp/bitint.h (bitint_reduce_prec): Likewise.

libgcc/libgcc2.c
libgcc/soft-fp/bitint.h

index 92cb79dc8f8de0b59f94ca65369c1e56a911845c..faefff3730ca1e45c79390271b3687bfda7e26b3 100644 (file)
@@ -1333,7 +1333,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
                  if (prec >= -1)
                    return -2;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-                 ++p;
+                 ++*p;
 #else
                  --i;
 #endif
@@ -1347,7 +1347,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
              if (prec >= -1)
                return -2;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-             ++p;
+             ++*p;
 #else
              --i;
 #endif
@@ -1358,7 +1358,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
              if ((Wtype) mslimb >= 0)
                {
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-                 --p;
+                 --*p;
 #endif
                  return prec - 1;
                }
@@ -1387,7 +1387,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
          if (prec == 0)
            return 1;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-         ++p;
+         ++*p;
 #else
          --i;
 #endif
@@ -1400,7 +1400,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
       if (prec == 0)
        return 1;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-      ++p;
+      ++*p;
 #else
       --i;
 #endif
index 07a7bcbb0b995306d93dc8b7edaf60ead62c4f19..8d489e65a622909c555eaa9f84d174f2ee68420c 100644 (file)
@@ -76,7 +76,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
                  if (prec >= -1)
                    return -2;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-                 ++p;
+                 ++*p;
 #else
                  --i;
 #endif
@@ -90,7 +90,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
              if (prec >= -1)
                return -2;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-             ++p;
+             ++*p;
 #else
              --i;
 #endif
@@ -101,7 +101,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
              if ((BILtype) mslimb >= 0)
                {
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-                 --p;
+                 --*p;
 #endif
                  return prec - 1;
                }
@@ -130,7 +130,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
          if (prec == 0)
            return 1;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-         ++p;
+         ++*p;
 #else
          --i;
 #endif
@@ -143,7 +143,7 @@ bitint_reduce_prec (const UBILtype **p, SItype prec)
       if (prec == 0)
        return 1;
 #if __LIBGCC_BITINT_ORDER__ == __ORDER_BIG_ENDIAN__
-      ++p;
+      ++*p;
 #else
       --i;
 #endif