[PATCH v2 10/32] mpi: Sync the Alpha longlong.h with GCC.

Matt Turner mattst88 at gmail.com
Wed Nov 25 21:19:47 CET 2026


* mpi/longlong.h [__alpha] (umul_ppmm): Do not define for C++ before
GCC 5.
(count_leading_zeros, count_trailing_zeros, COUNT_LEADING_ZEROS_0):
New.
[__alpha && !__alpha_cix__] (MPI_INTERNAL_NEED_CLZ_TAB): Define.

--

Take the Alpha block from GCC's copy of longlong.h.  With CIX
(-mcpu=ev67 and later) count_leading_zeros and count_trailing_zeros
are ctlz and cttz.  Without it they use cmpbge and extbl to find the
right byte and __clz_tab to finish, instead of the generic C version.
GCC added these in commits 8f4773eae70 ("longlong.h [__alpha]
(count_leading_zeros): New.") and 1efd0b97d6e, which replaced their
asm with builtins.  The C++ guard is from GCC commit 99630555c22
("longlong.h: Disable alpha umul_ppmm for old g++").

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 mpi/longlong.h | 51 +++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/mpi/longlong.h b/mpi/longlong.h
index a745e12d..9375338d 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -149,22 +149,57 @@ extern const UQItype __clz_tab[256] attribute_hidden;
  ***************************************/
 
 #if defined (__alpha) && W_TYPE_SIZE == 64
-# define umul_ppmm(ph, pl, m0, m1) \
+/* There is a bug in g++ before version 5 that
+   errors on __builtin_alpha_umulh.  */
+#if !defined(__cplusplus) || __GNUC__ >= 5
+#define umul_ppmm(ph, pl, m0, m1) \
   do {									\
     UDItype __m0 = (m0), __m1 = (m1);					\
     (ph) = __builtin_alpha_umulh (__m0, __m1);				\
-    (pl) = __m0 * __m1; 						\
+    (pl) = __m0 * __m1;							\
   } while (0)
-# define UMUL_TIME 46
-# ifndef LONGLONG_STANDALONE
-#  define udiv_qrnnd(q, r, n1, n0, d) \
+#define UMUL_TIME 46
+#endif /* !c++ */
+#ifndef LONGLONG_STANDALONE
+#define udiv_qrnnd(q, r, n1, n0, d) \
   do { UDItype __r;							\
-    (q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); 			\
+    (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));				\
     (r) = __r;								\
   } while (0)
 extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
-#  define UDIV_TIME 220
-# endif /* !LONGLONG_STANDALONE */
+#define UDIV_TIME 220
+#endif /* LONGLONG_STANDALONE */
+#ifdef __alpha_cix__
+#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clzl (X))
+#define count_trailing_zeros(COUNT,X)	((COUNT) = __builtin_ctzl (X))
+#define COUNT_LEADING_ZEROS_0 64
+#else
+#define MPI_INTERNAL_NEED_CLZ_TAB 1
+#define count_leading_zeros(COUNT,X) \
+  do {									\
+    UDItype __xr = (X), __t, __a;					\
+    __t = __builtin_alpha_cmpbge (0, __xr);				\
+    __a = __clz_tab[__t ^ 0xff] - 1;					\
+    __t = __builtin_alpha_extbl (__xr, __a);				\
+    (COUNT) = 64 - (__clz_tab[__t] + __a*8);				\
+  } while (0)
+#define count_trailing_zeros(COUNT,X) \
+  do {									\
+    UDItype __xr = (X), __t, __a;					\
+    __t = __builtin_alpha_cmpbge (0, __xr);				\
+    __t = ~__t & -~__t;							\
+    __a = ((__t & 0xCC) != 0) * 2;					\
+    __a += ((__t & 0xF0) != 0) * 4;					\
+    __a += ((__t & 0xAA) != 0);						\
+    __t = __builtin_alpha_extbl (__xr, __a);				\
+    __a <<= 3;								\
+    __t &= -__t;							\
+    __a += ((__t & 0xCC) != 0) * 2;					\
+    __a += ((__t & 0xF0) != 0) * 4;					\
+    __a += ((__t & 0xAA) != 0);						\
+    (COUNT) = __a;							\
+  } while (0)
+#endif /* __alpha_cix__ */
 #endif /* __alpha */
 
 /***************************************

-- 
2.56.1



More information about the Gcrypt-devel mailing list