[PATCH v2 00/32] mpi: Sync longlong.h with GCC
Matt Turner
mattst88 at gmail.com
Wed Nov 25 21:19:37 CET 2026
This is v2 of "mpi: Drop casts from inline asm output operands." [1],
which has grown into a series.
In reply to v1 you pointed out that the upstream for longlong.h is now
GCC's include/longlong.h, and asked that we not add differences of our
own from it. Fair enough, so I took the clang fix to GCC first. That
turned out to be a lot of hassle. The cast change landed in GCC on
September 21 as b6a6fe2438d ("include: Wrap the casts on asm output
operands in longlong.h in a macro"), and to get the rest of the
longlong.h fixes in I ultimately had to become a GCC committer.
Along the way it became clear that "no differences from upstream" was
not where Libgcrypt's copy started. Before this series, a diff against
GCC's longlong.h is about 3000 lines. Much of that is fixes GCC made
years or decades ago and Libgcrypt never picked up, for example:
- the SPARClite count_leading_zeros has its operands swapped, so it
clobbers its argument and never sets the count (fixed in GCC in
1998);
- the NS32000, i960 and 88110 code does not compile at all;
- 32-bit SPARC built for V9 falls back to the V7 mulscc loop and ends
up with an undefined reference to __udiv_qrnnd;
- the generic smul_ppmm initializes temporaries from themselves when
umul_ppmm declares __m0 and __m1;
- 31-bit s390 fails to build because __udiv_w_sdiv is never declared;
- the 68060 and CPU32 get instructions they do not implement.
This series fixes those and syncs each architecture block, and the
generic code, with GCC. It also takes the IA-64, RISC-V, 64-bit SPARC
and LoongArch code from GCC, and removes the blocks for CPUs that GCC
itself no longer supports. After it, the diff against GCC's copy is
about 650 lines, and what remains is Libgcrypt's own: the type
definitions, the _gcry_clz_tab name, the __udiv_qrnnd assembly
fallbacks for HPPA and 32-bit SPARC, __PPC_CLOBBER_CC, the clang
workarounds for SPARC, and the 64-bit MIPS block.
Each patch says how it was tested: which compilers and CPUs give
unchanged object code, and which macros were run under qemu.
Changes in v2:
- Wrap the casts on asm output operands in a macro,
__ll_check_output, as GCC now does, instead of dropping them. This
keeps GCC's check that the output has the right type.
- Remove the blocks for CPUs GCC no longer has rather than converting
them.
- Add the bug fixes and the syncs with GCC described above.
[1] Message-ID: <20260902131720.409681-1-mattst88 at gmail.com>
Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
Matt Turner (32):
mpi: Remove longlong.h support for CPUs GCC no longer has.
mpi: Wrap the casts on asm output operands in a macro.
mpi: Fix operands of sparclite count_leading_zeros.
mpi: Use the SPARC V8 umul_ppmm and udiv_qrnnd for V9.
mpi: Use %o5 instead of %g2 in the SPARC V7 umul_ppmm.
mpi: Fix the m68k longlong.h for the 68060 and CPU32.
mpi: Use __builtin_alpha_umulh in the Alpha umul_ppmm.
mpi: Declare the clz table at the top of longlong.h as __clz_tab.
mpi: Fix the generic smul_ppmm when umul_ppmm uses __m0 and __m1.
mpi: Sync the Alpha longlong.h with GCC.
mpi: Use builtins for the AArch64 count_leading_zeros.
mpi: Sync the HPPA longlong.h with GCC.
mpi: Sync the i370 longlong.h with GCC.
mpi: Sync the i386 and x86-64 longlong.h with GCC.
mpi: Sync the i960 longlong.h with GCC.
mpi: Sync the m68k longlong.h with GCC.
mpi: Sync the m88k longlong.h with GCC.
mpi: Sync the 32-bit MIPS longlong.h with GCC.
mpi: Sync the PowerPC longlong.h with GCC.
mpi: Sync the IBM RT longlong.h with GCC.
mpi: Sync the VAX longlong.h with GCC.
mpi: Sync the SH longlong.h with GCC.
mpi: Sync the 32-bit SPARC longlong.h with GCC.
mpi: Sync the ARM longlong.h with GCC.
mpi: Use builtins for the LoongArch count_leading_zeros.
mpi: Add the RISC-V longlong.h from GCC.
mpi: Add the 64-bit SPARC longlong.h from GCC.
mpi: Match the comments and layout of GCC's longlong.h.
mpi: Add the IA-64 longlong.h from GCC.
mpi: Remove the AArch64 add_ssaaaa, sub_ddmmss and umul_ppmm.
mpi: Remove the 64-bit MIPS umul_ppmm.
mpi: Match the generic longlong.h code to GCC.
mpi/longlong.h | 2496 ++++++++++++++++++++++++++------------------------------
1 file changed, 1169 insertions(+), 1327 deletions(-)
---
base-commit: f54ce47180e23850fa1ff3f76cd3d880fb99808a
change-id: 20261125-dead-ports-bc7dd35f8372
Best regards,
--
Matt Turner <mattst88 at gmail.com>
More information about the Gcrypt-devel
mailing list