coreutils
[Top][All Lists]
Advanced

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

[PATCH] factor: sync longlong.h adjustments from upstream


From: Pádraig Brady
Subject: [PATCH] factor: sync longlong.h adjustments from upstream
Date: Thu, 16 Sep 2021 15:43:55 +0100

* src/longlong.h: Sync changes from:
https://gmplib.org/repo/gmp/log/tip/longlong.h
---
 src/longlong.h | 59 ++++++++++++++++++++++++--------------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/src/longlong.h b/src/longlong.h
index 2c030b721..fbd3716d5 100644
--- a/src/longlong.h
+++ b/src/longlong.h
@@ -422,7 +422,7 @@ long __MPN(count_leading_zeros) (UDItype);
     && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
-    if (__builtin_constant_p (bl) && -(USItype)(bl) < 0x100)           \
+    if (__builtin_constant_p (bl) && -(USItype)(bl) < (USItype)(bl))   \
       __asm__ ("subs\t%1, %4, %5\n\tadc\t%0, %2, %3"                   \
           : "=r" (sh), "=&r" (sl)                                      \
               : "r" (ah), "rI" (bh),                                   \
@@ -433,8 +433,8 @@ long __MPN(count_leading_zeros) (UDItype);
           : "r" (ah), "rI" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC);   \
   } while (0)
 /* FIXME: Extend the immediate range for the low word by using both ADDS and
-   SUBS, since they set carry in the same way.  Note: We need separate
-   definitions for thumb and non-thumb due to the absence of RSC on thumb.  */
+   SUBS, since they set carry in the same way.  We need separate definitions
+   for thumb and non-thumb since thumb lacks RSC.  */
 #if defined (__thumb__)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
@@ -447,10 +447,6 @@ long __MPN(count_leading_zeros) (UDItype);
       __asm__ ("rsbs\t%1, %5, %4\n\tsbc\t%0, %2, %3"                   \
               : "=r" (sh), "=&r" (sl)                                  \
               : "r" (ah), "rI" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
-    else if (__builtin_constant_p (bl))                                        
\
-      __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"                   \
-              : "=r" (sh), "=&r" (sl)                                  \
-              : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
     else                                                               \
       __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"                   \
               : "=r" (sh), "=&r" (sl)                                  \
@@ -486,11 +482,7 @@ long __MPN(count_leading_zeros) (UDItype);
                   : "=r" (sh), "=&r" (sl)                              \
                   : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
       }                                                                        
\
-    else if (__builtin_constant_p (bl))                                        
\
-      __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"                   \
-              : "=r" (sh), "=&r" (sl)                                  \
-              : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
-    else /* only bh might be a constant */                             \
+    else                                                               \
       __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"                   \
               : "=r" (sh), "=&r" (sl)                                  \
               : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
@@ -546,11 +538,9 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, 
UWtype);
 #endif /* __arm__ */
 
 #if defined (__aarch64__) && W_TYPE_SIZE == 64
-/* FIXME: Extend the immediate range for the low word by using both
-   ADDS and SUBS, since they set carry in the same way.  */
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
-    if (__builtin_constant_p (bl) && -(UDItype)(bl) < 0x1000)          \
+    if (__builtin_constant_p (bl) && ~(UDItype)(bl) <= (UDItype)(bl))  \
       __asm__ ("subs\t%1, %x4, %5\n\tadc\t%0, %x2, %x3"                        
\
               : "=r" (sh), "=&r" (sl)                                  \
               : "rZ" ((UDItype)(ah)), "rZ" ((UDItype)(bh)),            \
@@ -563,7 +553,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, 
UWtype);
   } while (0)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
-    if (__builtin_constant_p (bl) && -(UDItype)(bl) < 0x1000)          \
+    if (__builtin_constant_p (bl) && ~(UDItype)(bl) <= (UDItype)(bl))  \
       __asm__ ("adds\t%1, %x4, %5\n\tsbc\t%0, %x2, %x3"                        
\
               : "=r,r" (sh), "=&r,&r" (sl)                             \
               : "rZ,rZ" ((UDItype)(ah)), "rZ,rZ" ((UDItype)(bh)),      \
@@ -856,6 +846,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, 
UWtype);
             : "0" ((UDItype)(ah)), "r" ((UDItype)(bh)),                \
               "1" ((UDItype)(al)), "r" ((UDItype)(bl)) __CLOBBER_CC);  \
   } while (0)
+#if !defined (__clang__)
 #define umul_ppmm(xh, xl, m0, m1)                                      \
   do {                                                                 \
     union {unsigned int __attribute__ ((mode(TI))) __ll;               \
@@ -877,6 +868,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, 
UWtype);
             : "0" (__x.__ll), "r" ((UDItype)(d)));                     \
     (q) = __x.__i.__l; (r) = __x.__i.__h;                              \
   } while (0)
+#endif
 #if 0 /* FIXME: Enable for z10 (?) */
 #define count_leading_zeros(cnt, x)                                    \
   do {                                                                 \
@@ -1042,7 +1034,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, 
UWtype, UWtype);
    && (HAVE_HOST_CPU_haswell || HAVE_HOST_CPU_broadwell \
        || HAVE_HOST_CPU_skylake || HAVE_HOST_CPU_bd4 || HAVE_HOST_CPU_zen)
 #define umul_ppmm(w1, w0, u, v) \
-  __asm__ ("mulx\t%3, %0, %1"                                          \
+  __asm__ ("mulx\t%3, %q0, %q1"                                                
\
           : "=r" (w0), "=r" (w1)                                       \
           : "%d" ((UDItype)(u)), "rm" ((UDItype)(v)))
 #else
@@ -1207,7 +1199,7 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, 
UWtype, UWtype);
 "      addx%.l %2,%0\n"                                                \
 "      | End inlined umul_ppmm"                                        \
              : "=&d" (xh), "=&d" (xl),                                 \
-               "=d" (__umul_tmp1), "=&d" (__umul_tmp2)                 \
+               "=&d" (__umul_tmp1), "=&d" (__umul_tmp2)                        
\
              : "%2" ((USItype)(a)), "d" ((USItype)(b)));               \
   } while (0)
 #endif /* not mc68020 */
@@ -1480,36 +1472,37 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, 
UWtype, UWtype);
    This might seem strange, but gcc folds away the dead code late.  */
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
-    if (__builtin_constant_p (bl) && bl > -0x8000 && bl <= 0x8000) {   \
+    if (__builtin_constant_p (bl)                                      \
+       && (bl) > -0x8000 && (bl) <= 0x8000 && (bl) != 0) {             \
        if (__builtin_constant_p (ah) && (ah) == 0)                     \
          __asm__ ("addic %1,%3,%4\n\tsubfze %0,%2"                     \
                   : "=r" (sh), "=&r" (sl)                              \
                   :                       "r" ((UDItype)(bh)),         \
-                    "rI" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))     \
+                    "r" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))      \
                     __CLOBBER_CC);                                     \
        else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0)     \
          __asm__ ("addic %1,%3,%4\n\tsubfme %0,%2"                     \
                   : "=r" (sh), "=&r" (sl)                              \
                   :                       "r" ((UDItype)(bh)),         \
-                    "rI" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))     \
+                    "r" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))      \
                     __CLOBBER_CC);                                     \
        else if (__builtin_constant_p (bh) && (bh) == 0)                \
          __asm__ ("addic %1,%3,%4\n\taddme %0,%2"                      \
                   : "=r" (sh), "=&r" (sl)                              \
-                  : "r"  ((UDItype)(ah)),                              \
-                    "rI" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))     \
+                  : "r" ((UDItype)(ah)),                               \
+                    "r" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))      \
                     __CLOBBER_CC);                                     \
        else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)     \
          __asm__ ("addic %1,%3,%4\n\taddze %0,%2"                      \
                   : "=r" (sh), "=&r" (sl)                              \
-                  : "r"  ((UDItype)(ah)),                              \
-                    "rI" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))     \
+                  : "r" ((UDItype)(ah)),                               \
+                    "r" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))      \
                     __CLOBBER_CC);                                     \
        else                                                            \
          __asm__ ("addic %1,%4,%5\n\tsubfe %0,%3,%2"                   \
                   : "=r" (sh), "=&r" (sl)                              \
-                  : "r"  ((UDItype)(ah)), "r" ((UDItype)(bh)),         \
-                    "rI" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))     \
+                  : "r" ((UDItype)(ah)), "r" ((UDItype)(bh)),          \
+                    "r" ((UDItype)(al)), "*rI" (-((UDItype)(bl)))      \
                     __CLOBBER_CC);                                     \
     } else {                                                           \
        if (__builtin_constant_p (ah) && (ah) == 0)                     \
@@ -2042,8 +2035,10 @@ extern __longlong_h_C UWtype mpn_udiv_qrnnd_r (UWtype, 
UWtype, UWtype, UWtype *)
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
     UWtype __x;                                                                
\
-    __x = (al) + (bl);                                                 \
-    (sh) = (ah) + (bh) + (__x < (al));                                 \
+    UWtype __al = (al);                                                        
\
+    UWtype __bl = (bl);                                                        
\
+    __x = __al + __bl;                                                 \
+    (sh) = (ah) + (bh) + (__x < __al);                                 \
     (sl) = __x;                                                                
\
   } while (0)
 #endif
@@ -2052,8 +2047,10 @@ extern __longlong_h_C UWtype mpn_udiv_qrnnd_r (UWtype, 
UWtype, UWtype, UWtype *)
 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   do {                                                                 \
     UWtype __x;                                                                
\
-    __x = (al) - (bl);                                                 \
-    (sh) = (ah) - (bh) - ((al) < (bl));                                        
\
+    UWtype __al = (al);                                                        
\
+    UWtype __bl = (bl);                                                        
\
+    __x = __al - __bl;                                                 \
+    (sh) = (ah) - (bh) - (__al < __bl);                                        
\
     (sl) = __x;                                                                
\
   } while (0)
 #endif
-- 
2.26.2




reply via email to

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