[PATCH v2 19/32] mpi: Sync the PowerPC longlong.h with GCC.

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


* mpi/longlong.h [_ARCH_PPC || __powerpc__ || ...]: Use GCC's
conditions for 32-bit PowerPC, and its text for both blocks.

--

Take the 32-bit and 64-bit PowerPC blocks from GCC's copy of
longlong.h, keeping libgcrypt's __PPC_CLOBBER_CC on the add_ssaaaa
and sub_ddmmss asm.  The 32-bit block now also matches __POWERPC__,
__ppc__ and the old PPC macros, as GCC's does.  The generated code
is the same with GCC and Clang on powerpc, powerpc64 and
powerpc64le.

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

diff --git a/mpi/longlong.h b/mpi/longlong.h
index cbd86fe0..c17ac622 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -828,130 +828,145 @@ typedef unsigned int UTItype __attribute__ ((mode (TI)));
 #else
 # define __PPC_CLOBBER_CC
 #endif
-/* Powerpc 32 bit support taken from GCC longlong.h. */
-#if (defined (_ARCH_PPC) || defined (__powerpc__)) && W_TYPE_SIZE == 32
-# define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+/* FIXME: We should test _IBMR2 here when we add assembly support for the
+   system vendor compilers.
+   FIXME: What's needed for gcc PowerPC VxWorks?  __vxworks__ is not good
+   enough, since that hits ARM and m68k too.  */
+#if (defined (_ARCH_PPC)	/* AIX */				\
+     || defined (__powerpc__)	/* gcc */				\
+     || defined (__POWERPC__)	/* BEOS */				\
+     || defined (__ppc__)	/* Darwin */				\
+     || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */    \
+     || (defined (PPC) && defined (CPU_FAMILY)    /* VxWorks */               \
+	 && CPU_FAMILY == PPC)                                                \
+     ) && W_TYPE_SIZE == 32
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   do {									\
     if (__builtin_constant_p (bh) && (bh) == 0)				\
-      __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2"		\
+	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
+	       __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
-      __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2"		\
+	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
+	       __PPC_CLOBBER_CC);					\
     else								\
-      __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3"			\
-              : "=r" (sh), "=&r" (sl)					\
-              : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)		\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3"		\
+	     : "=r" (sh), "=&r" (sl)					\
+	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)		\
+	       __PPC_CLOBBER_CC);					\
   } while (0)
-# define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   do {									\
     if (__builtin_constant_p (ah) && (ah) == 0)				\
-      __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0)		\
-      __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (bh) && (bh) == 0)			\
-      __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
-      __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else								\
-      __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2"			\
-              : "=r" (sh), "=&r" (sl)					\
-              : "r" (ah), "r" (bh), "rI" (al), "r" (bl)			\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2"	\
+	       : "=r" (sh), "=&r" (sl)					\
+	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl)		\
+	         __PPC_CLOBBER_CC);					\
   } while (0)
-# define count_leading_zeros(count, x) \
+#define count_leading_zeros(count, x) \
   __asm__ ("cntlzw %0,%1" : "=r" (count) : "r" (x))
-# define COUNT_LEADING_ZEROS_0 32
-# define umul_ppmm(ph, pl, m0, m1) \
+#define COUNT_LEADING_ZEROS_0 32
+#if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
+  || defined (__ppc__)                                                    \
+  || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */       \
+  || (defined (PPC) && defined (CPU_FAMILY)    /* VxWorks */                  \
+	 && CPU_FAMILY == PPC)
+#define umul_ppmm(ph, pl, m0, m1) \
   do {									\
     USItype __m0 = (m0), __m1 = (m1);					\
     __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
     (pl) = __m0 * __m1;							\
   } while (0)
-# define UMUL_TIME 15
-# define smul_ppmm(ph, pl, m0, m1) \
+#define UMUL_TIME 15
+#define smul_ppmm(ph, pl, m0, m1) \
   do {									\
     SItype __m0 = (m0), __m1 = (m1);					\
     __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
     (pl) = __m0 * __m1;							\
   } while (0)
-# define SMUL_TIME 14
-# define UDIV_TIME 120
+#define SMUL_TIME 14
+#define UDIV_TIME 120
+#endif
 #endif /* 32-bit POWER architecture variants.  */
 
-/* Powerpc 64 bit support taken from GCC longlong.h. */
 /* We should test _IBMR2 here when we add assembly support for the system
    vendor compilers.  */
 #if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64
-# define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   do {									\
     if (__builtin_constant_p (bh) && (bh) == 0)				\
-      __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("add%I4c %1,%3,%4\n\taddze %0,%2"		\
+	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
+	       __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)		\
-      __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("add%I4c %1,%3,%4\n\taddme %0,%2"		\
+	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl)	\
+	       __PPC_CLOBBER_CC);					\
     else								\
-      __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3"			\
-              : "=r" (sh), "=&r" (sl)					\
-              : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)		\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("add%I5c %1,%4,%5\n\tadde %0,%2,%3"		\
+	     : "=r" (sh), "=&r" (sl)					\
+	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl)		\
+	       __PPC_CLOBBER_CC);					\
   } while (0)
-# define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
   do {									\
     if (__builtin_constant_p (ah) && (ah) == 0)				\
-      __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\tsubfze %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0)		\
-      __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\tsubfme %0,%2"	\
+	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (bh) && (bh) == 0)			\
-      __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\taddme %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)		\
-      __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2"			\
-              : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I3c %1,%4,%3\n\taddze %0,%2"		\
+	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl)	\
+	         __PPC_CLOBBER_CC);					\
     else								\
-      __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2"			\
-              : "=r" (sh), "=&r" (sl)					\
-              : "r" (ah), "r" (bh), "rI" (al), "r" (bl)			\
-              __PPC_CLOBBER_CC);					\
+      __asm__ ("subf%I4c %1,%5,%4\n\tsubfe %0,%3,%2"	\
+	       : "=r" (sh), "=&r" (sl)					\
+	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl)		\
+	         __PPC_CLOBBER_CC);					\
   } while (0)
-# define count_leading_zeros(count, x) \
+#define count_leading_zeros(count, x) \
   __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
-# define COUNT_LEADING_ZEROS_0 64
-# define umul_ppmm(ph, pl, m0, m1) \
+#define COUNT_LEADING_ZEROS_0 64
+#define umul_ppmm(ph, pl, m0, m1) \
   do {									\
     UDItype __m0 = (m0), __m1 = (m1);					\
     __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
     (pl) = __m0 * __m1;							\
   } while (0)
-# define UMUL_TIME 15
-# define smul_ppmm(ph, pl, m0, m1) \
+#define UMUL_TIME 15
+#define smul_ppmm(ph, pl, m0, m1) \
   do {									\
     DItype __m0 = (m0), __m1 = (m1);					\
     __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
     (pl) = __m0 * __m1;							\
   } while (0)
-# define SMUL_TIME 14  /* ??? */
-# define UDIV_TIME 120 /* ??? */
+#define SMUL_TIME 14  /* ??? */
+#define UDIV_TIME 120 /* ??? */
 #endif /* 64-bit PowerPC.  */
 
 /***************************************

-- 
2.56.1



More information about the Gcrypt-devel mailing list