Build failure on MIPS R6 (Patch attached)

Jiaxun Yang <[email protected]>
Newsgroups gmane.comp.mathematics.pari.devel
Message-ID <[email protected]>
Hi there,

Pari build is failing on MIPS Release 6 system because it’s using MULTU instruction which is removed on MIPS R6.

We should use MUHU/MULU pair instead.

Patch attached for fix.

Thanks
—
Jiaxun Yang
0001-Use-new-multiply-instructions-for-MIPS-R6.patch (application/octet-stream, 4.4 KB)
From 5dc2a6db5d150119dcfe4c3fa9093a187cc43716 Mon Sep 17 00:00:00 2001
From: Jiaxun Yang <[email protected]>
Date: Tue, 2 Aug 2022 13:32:23 +0100
Subject: [PATCH 1/2] Use new multiply instructions for MIPS R6

MIPS R6 Removed Hi,Lo registers and introduced new instructions
to multiply targeting GPR, use those instructions to workaround
build failure.

Signed-off-by: Jiaxun Yang <[email protected]>
---
 src/kernel/mips/asm0.h   | 22 ++++++++++++++++++++++
 src/kernel/mips64/asm0.h | 23 ++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/kernel/mips/asm0.h b/src/kernel/mips/asm0.h
index f9cbab83b..f250417e8 100644
--- a/src/kernel/mips/asm0.h
+++ b/src/kernel/mips/asm0.h
@@ -20,6 +20,27 @@ NOASM addll bfffo divll
 #define LOCAL_HIREMAINDER  ulong hiremainder
 #define LOCAL_OVERFLOW     ulong overflow
 
+#if defined(__mips_isa_rev) && __mips_isa_rev >= 6
+#define mulll(a, b)                                         \
+__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
+ __asm__ ("muhu %0,%2,%3\n\tmulu %1,%2,%3"                  \
+   : "=&r" (__value), "=&r" (hiremainder)                   \
+   : "r" (__arg1), "r" (__arg2)                             \
+   : );                                                     \
+ __value;                                                   \
+})
+
+#define addmul(a, b)                                                    \
+__extension__ ({                                                        \
+  ulong __arg1 = (a), __arg2 = (b), __value, __tmp;                     \
+  __asm__ ("muhu %0,%3,%4\n\tmulu %2,%3,%4\n\t"                      \
+           "addu %1,%2,%5\n\tsltu %2,%1,%5\n\taddu %0,%0,%2"            \
+           : "=&r" (hiremainder), "=&r" (__value), "=&r" (__tmp)        \
+           : "r" (__arg1), "r" (__arg2), "r" (hiremainder)              \
+           : "hi", "lo");                                               \
+  __value;                                                              \
+})
+#else
 #define mulll(a, b)                                         \
 __extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
  __asm__ ("multu %2,%3\n\tmfhi %1"                          \
@@ -39,5 +60,6 @@ __extension__ ({                                                        \
            : "hi", "lo");                                               \
   __value;                                                              \
 })
+#endif
 
 #endif
diff --git a/src/kernel/mips64/asm0.h b/src/kernel/mips64/asm0.h
index 0e7073799..f65cab6f5 100644
--- a/src/kernel/mips64/asm0.h
+++ b/src/kernel/mips64/asm0.h
@@ -20,6 +20,27 @@ NOASM addll bfffo divll
 #define LOCAL_HIREMAINDER  ulong hiremainder
 #define LOCAL_OVERFLOW     ulong overflow
 
+#if defined(__mips_isa_rev) && __mips_isa_rev >= 6
+#define mulll(a, b)                                         \
+__extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
+ __asm__ ("dmuhu %1,%2,%3\n\tdmulu %0,%2,%3"                                  \
+   : "=&r" (__value), "=&r" (hiremainder)                   \
+   : "r" (__arg1), "r" (__arg2)                             \
+   : );                                                     \
+ __value;                                                   \
+})
+
+#define addmul(a, b)                                                    \
+__extension__ ({                                                        \
+  ulong __arg1 = (a), __arg2 = (b), __value, __tmp;                     \
+  __asm__ ("dmuhu %0,%3,%4\n\tdmulu %2,%3,%4\n\t"                       \
+           "daddu %1,%2,%5\n\tsltu %2,%1,%5\n\tdaddu %0,%0,%2"          \
+           : "=&r" (hiremainder), "=&r" (__value), "=&r" (__tmp)        \
+           : "r" (__arg1), "r" (__arg2), "r" (hiremainder)              \
+           : );                                                         \
+  __value;                                                              \
+})
+#else
 #define mulll(a, b)                                         \
 __extension__ ({ ulong __value, __arg1 = (a), __arg2 = (b); \
  __asm__ ("dmultu %2,%3\n\tmfhi %1"                         \
@@ -39,5 +60,5 @@ __extension__ ({                                                        \
            : "hi", "lo");                                               \
   __value;                                                              \
 })
-
+#endif
 #endif
-- 
2.32.1 (Apple Git-133)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.