[PATCH v2 12/32] mpi: Sync the HPPA longlong.h with GCC.
Matt Turner
mattst88 at gmail.com
Wed Nov 25 21:19:49 CET 2026
* mpi/longlong.h [__hppa] (add_ssaaaa, sub_ddmmss): Do not clobber
"cc".
[_PA_RISC1_1] (umul_ppmm): Use the "x" constraint and GCC's names.
(UMUL_TIME, UDIV_TIME): Use GCC's values.
(count_leading_zeros): Reformat the asm as in GCC.
--
Take the HPPA block from GCC's copy of longlong.h, keeping the call
to __udiv_qrnnd, which GCC does not have. "x" is the same register
class as "f" on PA. GCC generates the same code as before, except
for whitespace in the count_leading_zeros asm.
The timings change from 8 and 60 to 8 and 40 for PA 1.1, and from 40
and 80 to 30 and 40 for PA 1.0. _gcry_mpih_mod_1 and
_gcry_mpih_divmod_1 use them to choose between udiv_qrnnd and
multiplying by the inverse of the divisor: with PA 1.1 they now choose
the inverse for 3 or more limbs instead of 2, and with PA 1.0 they
still never choose it.
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
mpi/longlong.h | 119 ++++++++++++++++++++++++++++-----------------------------
1 file changed, 59 insertions(+), 60 deletions(-)
diff --git a/mpi/longlong.h b/mpi/longlong.h
index a27ee71b..402d85d1 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -343,73 +343,72 @@ extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
************** HPPA *****************
***************************************/
#if defined (__hppa) && W_TYPE_SIZE == 32
-# define add_ssaaaa(sh, sl, ah, al, bh, bl) \
- __asm__ ("add %4,%5,%1\n\t" \
- "addc %2,%3,%0" \
- : "=r" __ll_check_output (USItype, sh), \
- "=&r" __ll_check_output (USItype, sl) \
- : "%rM" ((USItype)(ah)), \
- "rM" ((USItype)(bh)), \
- "%rM" ((USItype)(al)), \
- "rM" ((USItype)(bl)) __CLOBBER_CC)
-# define sub_ddmmss(sh, sl, ah, al, bh, bl) \
- __asm__ ("sub %4,%5,%1\n\t" \
- "subb %2,%3,%0" \
- : "=r" __ll_check_output (USItype, sh), \
- "=&r" __ll_check_output (USItype, sl) \
- : "rM" ((USItype)(ah)), \
- "rM" ((USItype)(bh)), \
- "rM" ((USItype)(al)), \
- "rM" ((USItype)(bl)) __CLOBBER_CC)
-# if defined (_PA_RISC1_1)
-# define umul_ppmm(wh, wl, u, v) \
+#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
+ __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0" \
+ : "=r" __ll_check_output (USItype, sh), \
+ "=&r" __ll_check_output (USItype, sl) \
+ : "%rM" ((USItype) (ah)), \
+ "rM" ((USItype) (bh)), \
+ "%rM" ((USItype) (al)), \
+ "rM" ((USItype) (bl)))
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0" \
+ : "=r" __ll_check_output (USItype, sh), \
+ "=&r" __ll_check_output (USItype, sl) \
+ : "rM" ((USItype) (ah)), \
+ "rM" ((USItype) (bh)), \
+ "rM" ((USItype) (al)), \
+ "rM" ((USItype) (bl)))
+#if defined (_PA_RISC1_1)
+#define umul_ppmm(w1, w0, u, v) \
do { \
- union {UDItype __ll; \
- struct {USItype __h, __l;} __i; \
- } __xx; \
- __asm__ (" xmpyu %1,%2,%0" \
- : "=*f" (__xx.__ll) \
- : "*f" ((USItype)(u)), \
- "*f" ((USItype)(v))); \
- (wh) = __xx.__i.__h; \
- (wl) = __xx.__i.__l; \
- } while (0)
-# define UMUL_TIME 8
-# define UDIV_TIME 60
-# else
-# define UMUL_TIME 40
-# define UDIV_TIME 80
-# endif
-# if !defined(LONGLONG_STANDALONE) && !defined(ASM_DISABLED)
-# define udiv_qrnnd(q, r, n1, n0, d) \
+ union \
+ { \
+ UDItype __f; \
+ struct {USItype __w1, __w0;} __w1w0; \
+ } __t; \
+ __asm__ ("xmpyu %1,%2,%0" \
+ : "=x" (__t.__f) \
+ : "x" ((USItype) (u)), \
+ "x" ((USItype) (v))); \
+ (w1) = __t.__w1w0.__w1; \
+ (w0) = __t.__w1w0.__w0; \
+ } while (0)
+#define UMUL_TIME 8
+#else
+#define UMUL_TIME 30
+#endif
+#define UDIV_TIME 40
+#if !defined(LONGLONG_STANDALONE) && !defined(ASM_DISABLED)
+#define udiv_qrnnd(q, r, n1, n0, d) \
do { USItype __r; \
(q) = __udiv_qrnnd (&__r, (n1), (n0), (d)); \
(r) = __r; \
} while (0)
extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
-# endif /* !LONGLONG_STANDALONE && !ASM_DISABLED */
-# define count_leading_zeros(count, x) \
- do { \
- USItype __tmp; \
- __asm__ ( \
- " ldi 1,%0 \n" \
- " extru,= %1,15,16,%%r0 ; Bits 31..16 zero? \n" \
- " extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n" \
- " ldo 16(%0),%0 ; Yes. Perform add. \n" \
- " extru,= %1,23,8,%%r0 ; Bits 15..8 zero? \n" \
- " extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n" \
- " ldo 8(%0),%0 ; Yes. Perform add. \n" \
- " extru,= %1,27,4,%%r0 ; Bits 7..4 zero? \n" \
- " extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n" \
- " ldo 4(%0),%0 ; Yes. Perform add. \n" \
- " extru,= %1,29,2,%%r0 ; Bits 3..2 zero? \n" \
- " extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n" \
- " ldo 2(%0),%0 ; Yes. Perform add. \n" \
- " extru %1,30,1,%1 ; Extract bit 1. \n" \
- " sub %0,%1,%0 ; Subtract it. " \
- : "=r" (count), "=r" (__tmp) : "1" (x)); \
+#endif /* !LONGLONG_STANDALONE && !ASM_DISABLED */
+#define count_leading_zeros(count, x) \
+ do { \
+ USItype __tmp; \
+ __asm__ ( \
+ "ldi 1,%0\n" \
+" extru,= %1,15,16,%%r0 ; Bits 31..16 zero?\n" \
+" extru,tr %1,15,16,%1 ; No. Shift down, skip add.\n"\
+" ldo 16(%0),%0 ; Yes. Perform add.\n" \
+" extru,= %1,23,8,%%r0 ; Bits 15..8 zero?\n" \
+" extru,tr %1,23,8,%1 ; No. Shift down, skip add.\n"\
+" ldo 8(%0),%0 ; Yes. Perform add.\n" \
+" extru,= %1,27,4,%%r0 ; Bits 7..4 zero?\n" \
+" extru,tr %1,27,4,%1 ; No. Shift down, skip add.\n"\
+" ldo 4(%0),%0 ; Yes. Perform add.\n" \
+" extru,= %1,29,2,%%r0 ; Bits 3..2 zero?\n" \
+" extru,tr %1,29,2,%1 ; No. Shift down, skip add.\n"\
+" ldo 2(%0),%0 ; Yes. Perform add.\n" \
+" extru %1,30,1,%1 ; Extract bit 1.\n" \
+" sub %0,%1,%0 ; Subtract it.\n" \
+ : "=r" (count), "=r" (__tmp) : "1" (x)); \
} while (0)
-#endif /* hppa */
+#endif
/***************************************
--
2.56.1
More information about the Gcrypt-devel
mailing list