[PATCH v2 18/32] mpi: Sync the 32-bit MIPS longlong.h with GCC.
Matt Turner
mattst88 at gmail.com
Wed Nov 25 21:19:55 CET 2026
* mpi/longlong.h [__mips__ && W_TYPE_SIZE == 32] (umul_ppmm): Use C
with every compiler. Cast the operands to USItype.
(count_leading_zeros, COUNT_LEADING_ZEROS_0): New for MIPS32 and
MIPS64.
--
Take the 32-bit MIPS block from GCC's copy of longlong.h. GCC
replaced its asm umul_ppmm with C in commit 21dfc6dc74a, when it made
the "h" constraint NO_REGS, and added count_leading_zeros in commit
44f9fcef63f ("longlong.h [__mips__] (count_leading_zeros, [...]):
Define for MIPS32 and MIPS64."). Libgcrypt used the C version only
with GCC 4.4 and later and Clang, and asm before that. The generated
code is the same, except that count_leading_zeros is a clz for MIPS32
and MIPS64 instead of the generic C version.
The 64-bit MIPS block has no counterpart in GCC and stays.
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
mpi/longlong.h | 39 ++++++++++++---------------------------
1 file changed, 12 insertions(+), 27 deletions(-)
diff --git a/mpi/longlong.h b/mpi/longlong.h
index a69cd794..cbd86fe0 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -768,34 +768,19 @@ extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
************** MIPS *****************
***************************************/
#if defined (__mips__) && W_TYPE_SIZE == 32
-# if defined (__clang__) || (__GNUC__ >= 5) || (__GNUC__ == 4 && \
- __GNUC_MINOR__ >= 4)
-# define umul_ppmm(w1, w0, u, v) \
- do { \
- UDItype __r; \
- __r = (UDItype)(u) * (v); \
- (w1) = __r >> 32; \
- (w0) = (USItype) __r; \
+#define umul_ppmm(w1, w0, u, v) \
+ do { \
+ UDItype __x = (UDItype) (USItype) (u) * (USItype) (v); \
+ (w1) = (USItype) (__x >> 32); \
+ (w0) = (USItype) (__x); \
} while (0)
-# elif __GNUC__ > 2 || __GNUC_MINOR__ >= 7
-# define umul_ppmm(w1, w0, u, v) \
- __asm__ ("multu %2,%3" \
- : "=l" __ll_check_output (USItype, w0), \
- "=h" __ll_check_output (USItype, w1) \
- : "d" ((USItype)(u)), \
- "d" ((USItype)(v)))
-# else
-# define umul_ppmm(w1, w0, u, v) \
- __asm__ ("multu %2,%3 \n" \
- "mflo %0 \n" \
- "mfhi %1" \
- : "=d" __ll_check_output (USItype, w0), \
- "=d" __ll_check_output (USItype, w1) \
- : "d" ((USItype)(u)), \
- "d" ((USItype)(v)))
-# endif
-# define UMUL_TIME 10
-# define UDIV_TIME 100
+#define UMUL_TIME 10
+#define UDIV_TIME 100
+
+#if (__mips == 32 || __mips == 64) && ! defined (__mips16)
+#define count_leading_zeros(COUNT,X) ((COUNT) = __builtin_clz (X))
+#define COUNT_LEADING_ZEROS_0 32
+#endif
#endif /* __mips__ */
/***************************************
--
2.56.1
More information about the Gcrypt-devel
mailing list