[PATCH v2 13/32] mpi: Sync the i370 longlong.h with GCC.
Matt Turner
mattst88 at gmail.com
Wed Nov 25 21:19:50 CET 2026
* mpi/longlong.h [__i370__ || __mvs__]: Also use for __s390__.
(umul_ppmm): Remove.
(smul_ppmm): Fix the asm constraints.
[__zarch__] (smul_ppmm, sdiv_qrnnd): New.
--
Take the i370 block from GCC's copy of longlong.h. mr writes the
product to an even/odd register pair, which two separate "=r" outputs
do not give it. GCC fixed this in commit 7e765675931 ("longlong.h:
Partially synchronize with GMP-4.1 version: Use i370 definitions also
for s390."), which also removed the umul_ppmm and used the block for
31-bit s390. The z/Architecture versions, which use register asm
for r0 and r1, are from GCC commit 9602b6a1b8d ("s390.md: Replace
TARGET_64BIT with TARGET_ZARCH.").
On s390 the generic UDWtype versions of umul_ppmm and udiv_qrnnd come
first, so the code generated for -m31 does not change.
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
mpi/longlong.h | 70 ++++++++++++++++++++++++++++++++--------------------------
1 file changed, 39 insertions(+), 31 deletions(-)
diff --git a/mpi/longlong.h b/mpi/longlong.h
index 402d85d1..50fa5e98 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -414,48 +414,56 @@ extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
/***************************************
************** I370 *****************
***************************************/
-#if (defined (__i370__) || defined (__mvs__)) && W_TYPE_SIZE == 32
-# define umul_ppmm(xh, xl, m0, m1) \
+#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
+#if !defined (__zarch__)
+#define smul_ppmm(xh, xl, m0, m1) \
do { \
- union {UDItype __ll; \
+ union {DItype __ll; \
struct {USItype __h, __l;} __i; \
- } __xx; \
- USItype __m0 = (m0), __m1 = (m1); \
- __asm__ ("mr %0,%3" \
- : "=r" (__xx.__i.__h), \
- "=r" (__xx.__i.__l) \
- : "%1" (__m0), \
- "r" (__m1)); \
- (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
- (xh) += ((((SItype) __m0 >> 31) & __m1) \
- + (((SItype) __m1 >> 31) & __m0)); \
+ } __x; \
+ __asm__ ("lr %N0,%1\n\tmr %0,%2" \
+ : "=&r" (__x.__ll) \
+ : "r" (m0), "r" (m1)); \
+ (xh) = __x.__i.__h; (xl) = __x.__i.__l; \
} while (0)
-# define smul_ppmm(xh, xl, m0, m1) \
+#define sdiv_qrnnd(q, r, n1, n0, d) \
do { \
- union {DItype __ll; \
+ union {DItype __ll; \
struct {USItype __h, __l;} __i; \
- } __xx; \
- __asm__ ("mr %0,%3" \
- : "=r" (__xx.__i.__h), \
- "=r" (__xx.__i.__l) \
- : "%1" (m0), \
- "r" (m1)); \
- (xh) = __xx.__i.__h; (xl) = __xx.__i.__l; \
+ } __x; \
+ __x.__i.__h = (n1); __x.__i.__l = (n0); \
+ __asm__ ("dr %0,%2" \
+ : "=r" (__x.__ll) \
+ : "0" (__x.__ll), "r" (d)); \
+ (q) = __x.__i.__l; (r) = __x.__i.__h; \
} while (0)
-# define sdiv_qrnnd(q, r, n1, n0, d) \
+#else
+#define smul_ppmm(xh, xl, m0, m1) \
+ do { \
+ register SItype __r0 __asm__ ("0"); \
+ register SItype __r1 __asm__ ("1") = (m0); \
+ \
+ __asm__ ("mr\t%%r0,%3" \
+ : "=r" (__r0), "=r" (__r1) \
+ : "r" (__r1), "r" (m1)); \
+ (xh) = __r0; (xl) = __r1; \
+ } while (0)
+
+#define sdiv_qrnnd(q, r, n1, n0, d) \
do { \
- union {DItype __ll; \
- struct {USItype __h, __l;} __i; \
- } __xx; \
- __xx.__i.__h = (n1); __xx.__i.__l = (n0); \
- __asm__ ("dr %0,%2" \
- : "=r" (__xx.__ll) \
- : "0" (__xx.__ll), "r" (d)); \
- (q) = __xx.__i.__l; (r) = __xx.__i.__h; \
+ register SItype __r0 __asm__ ("0") = (n1); \
+ register SItype __r1 __asm__ ("1") = (n0); \
+ \
+ __asm__ ("dr\t%%r0,%4" \
+ : "=r" (__r0), "=r" (__r1) \
+ : "r" (__r0), "r" (__r1), "r" (d)); \
+ (q) = __r1; (r) = __r0; \
} while (0)
+#endif /* __zarch__ */
#endif
+
/***************************************
************** I386 *****************
***************************************/
--
2.56.1
More information about the Gcrypt-devel
mailing list