[PATCH v2 06/32] mpi: Fix the m68k longlong.h for the 68060 and CPU32.

Matt Turner mattst88 at gmail.com
Wed Nov 25 21:19:43 CET 2026


* mpi/longlong.h [__mc68000__] (umul_ppmm, udiv_qrnnd, sdiv_qrnnd):
Do not use the 68020 versions when __mc68060__ is defined.
(count_leading_zeros): Do not define when __mcpu32__ is defined.

--

The 68060 does not implement the 64-bit forms of mulu.l, divu.l and
divs.l, and traps to emulate them.  GCC defines __mc68060__ along with
__mc68020__ for -m68020-60, so use the 68000 umul_ppmm there instead.
GCC did the same in its copy of longlong.h in commit 3704aae954e,
whose ChangeLog entry reads "longlong.h: Make code 68060 clean when
compiling for m68060."

CPU32 has no bit field instructions, so bfffo is an illegal instruction
there, yet GCC defines __mc68020__ for -mcpu=cpu32.  GCC excluded CPU32
from the bfffo count_leading_zeros in commit 32247ce9e49 (PR
target/11777).

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 mpi/longlong.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/mpi/longlong.h b/mpi/longlong.h
index 3ca473e0..a09dc491 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -624,7 +624,8 @@ extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
 	     "d" ((USItype)(bh)),                                       \
 	     "1" ((USItype)(al)),                                       \
 	     "g" ((USItype)(bl)))
-# if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
+# if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) \
+     && !defined (__mc68060__)
 #  define umul_ppmm(w1, w0, u, v) \
   __asm__ ("mulu%.l %3,%1:%0"                                           \
 	   : "=d" __ll_check_output (USItype, w0),                      \
@@ -647,11 +648,6 @@ extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
 	   : "0" ((USItype)(n0)),                                       \
 	     "1" ((USItype)(n1)),                                       \
 	     "dmi" ((USItype)(d)))
-#  define count_leading_zeros(count, x) \
-  __asm__ ("bfffo %1{%b2:%b2},%0"                                       \
-	   : "=d" __ll_check_output (USItype, count)                    \
-	   : "od" ((USItype)(x)), "n" (0))
-#  define COUNT_LEADING_ZEROS_0 32
 # else /* not mc68020 */
 #  define umul_ppmm(xh, xl, a, b) \
   do { USItype __umul_tmp1, __umul_tmp2;			  \
@@ -685,6 +681,14 @@ extern USItype __udiv_qrnnd (USItype *, USItype, USItype, USItype);
 #  define UMUL_TIME 100
 #  define UDIV_TIME 400
 # endif /* not mc68020 */
+# if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020)) \
+     && !defined (__mcpu32__)
+#  define count_leading_zeros(count, x) \
+  __asm__ ("bfffo %1{%b2:%b2},%0"                                       \
+	   : "=d" __ll_check_output (USItype, count)                    \
+	   : "od" ((USItype)(x)), "n" (0))
+#  define COUNT_LEADING_ZEROS_0 32
+# endif
 #endif /* mc68000 */
 
 

-- 
2.56.1



More information about the Gcrypt-devel mailing list