qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 5/5] tests/tcg/mips: Test user mode DMULT for the R5900


From: Philippe Mathieu-Daudé
Subject: [PATCH v3 5/5] tests/tcg/mips: Test user mode DMULT for the R5900
Date: Fri, 12 Mar 2021 17:24:34 +0100

From: Fredrik Noring <noring@nocrew.org>

The R5900 reports itself as MIPS III but does not implement DMULT.
Verify that DMULT is emulated properly in user mode by multiplying
two 64-bit numbers to produce a 128-bit number.

Signed-off-by: Fredrik Noring <noring@nocrew.org>
Message-Id: 
<b04427024562b10c852a5519b57033e094fcdc3b.1541701393.git.noring@nocrew.org>
[PMD: Moved to tests/tcg/mips/]
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/tcg/mips/test-r5900-dmult.c | 40 +++++++++++++++++++++++++++++++
 tests/tcg/mips/Makefile.target    | 11 ++++++---
 2 files changed, 48 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/mips/test-r5900-dmult.c

diff --git a/tests/tcg/mips/test-r5900-dmult.c 
b/tests/tcg/mips/test-r5900-dmult.c
new file mode 100644
index 00000000000..2827ab5358f
--- /dev/null
+++ b/tests/tcg/mips/test-r5900-dmult.c
@@ -0,0 +1,40 @@
+/*
+ * Test DMULT.
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+#include <assert.h>
+
+struct hi_lo { int64_t hi; uint64_t lo; };
+
+static struct hi_lo dmult(int64_t rs, int64_t rt)
+{
+    int64_t hi;
+    uint64_t lo;
+
+    /*
+     * The R5900 reports itself as MIPS III but does not implement DMULT.
+     * Verify that DMULT is emulated properly in user mode.
+     */
+    __asm__ __volatile__ (
+            "    .set  mips3\n"
+            "    dmult %2, %3\n"
+            "    mfhi  %0\n"
+            "    mflo  %1\n"
+            : "=r" (hi), "=r" (lo)
+            : "r" (rs), "r" (rt));
+
+    return (struct hi_lo) { .hi = hi, .lo = lo };
+}
+
+int main()
+{
+    /* Verify that multiplying two 64-bit numbers yields a 128-bit number. */
+    struct hi_lo r = dmult(2760727302517, 5665449960167);
+
+    assert(r.hi == 847887);
+    assert(r.lo == 7893651516417804947);
+
+    return 0;
+}
diff --git a/tests/tcg/mips/Makefile.target b/tests/tcg/mips/Makefile.target
index 1a994d5525e..59e9d6fb76a 100644
--- a/tests/tcg/mips/Makefile.target
+++ b/tests/tcg/mips/Makefile.target
@@ -11,9 +11,14 @@ VPATH                += $(MIPS_SRC)
 # hello-mips is 32 bit only
 ifeq ($(findstring 64,$(TARGET_NAME)),)
 MIPS_TESTS=hello-mips
-
-TESTS += $(MIPS_TESTS)
-
 hello-mips: CFLAGS+=-mno-abicalls -fno-PIC -mabi=32
 hello-mips: LDFLAGS+=-nostdlib
 endif
+
+# r5900 is only 64 bit little-endian
+ifneq ($(findstring 64el,$(TARGET_NAME)),)
+MIPS_TESTS += test-r5900-dmult
+test-r5900-dmult: CFLAGS += -mabi=n32 -march=r5900
+endif
+
+TESTS += $(MIPS_TESTS)
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]