[PATCH v2 29/32] mpi: Add the IA-64 longlong.h from GCC.
Matt Turner
mattst88 at gmail.com
Wed Nov 25 21:20:06 CET 2026
* mpi/longlong.h [__ia64 && W_TYPE_SIZE == 64] (sub_ddmmss)
(umul_ppmm, count_leading_zeros, count_trailing_zeros, UMUL_TIME):
New, from GCC.
--
Take the IA-64 block from GCC, as of commit 77063f809a7 ("include: Use
builtins for the IA-64 clz and ctz in longlong.h").
In a function that stores both results, GCC's sub_ddmmss gives three
bundles where the generic code gives five. GCC's umul_ppmm gives the
same code as the generic one when both halves are used.
Tested under qemu-ia64.
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
mpi/longlong.h | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/mpi/longlong.h b/mpi/longlong.h
index 43d8f66e..ea11e410 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -514,6 +514,34 @@ extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
__w; })
#endif /* __i960__ */
+#if defined (__ia64) && W_TYPE_SIZE == 64
+/* This form encourages gcc (pre-release 3.4 at least) to emit predicated
+ "sub r=r,r" and "sub r=r,r,1", giving a 2 cycle latency. The generic
+ code using "al<bl" arithmetically comes out making an actual 0 or 1 in a
+ register, which takes an extra cycle. */
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+ do { \
+ UWtype __x; \
+ __x = (al) - (bl); \
+ if ((al) < (bl)) \
+ (sh) = (ah) - (bh) - 1; \
+ else \
+ (sh) = (ah) - (bh); \
+ (sl) = __x; \
+ } while (0)
+
+/* Do both product parts in assembly, since that gives better code with
+ all gcc versions. Some callers will just use the upper part, and in
+ that situation we waste an instruction, but not any cycles. */
+#define umul_ppmm(ph, pl, m0, m1) \
+ __asm__ ("xma.hu %0 = %2, %3, f0\n\txma.l %1 = %2, %3, f0" \
+ : "=&f" (ph), "=f" (pl) \
+ : "f" (m0), "f" (m1))
+#define count_leading_zeros(count, x) ((count) = __builtin_clzll (x))
+#define count_trailing_zeros(count, x) ((count) = __builtin_ctzll (x))
+#define UMUL_TIME 14
+#endif
+
#ifdef __loongarch__
# if W_TYPE_SIZE == 64
# define count_leading_zeros(count, x) ((count) = __builtin_clzll (x))
--
2.56.1
More information about the Gcrypt-devel
mailing list