[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/2] tests/tcg/mips: Test user mode DMULT for the R5
From: |
Fredrik Noring |
Subject: |
[Qemu-devel] [PATCH 2/2] tests/tcg/mips: Test user mode DMULT for the R5900 |
Date: |
Thu, 8 Nov 2018 19:43:40 +0100 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
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 <address@hidden>
---
tests/tcg/mips/mipsn32r5900/Makefile | 25 +++++++++++++++++
tests/tcg/mips/mipsn32r5900/dmult.c | 40 ++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
create mode 100644 tests/tcg/mips/mipsn32r5900/Makefile
create mode 100644 tests/tcg/mips/mipsn32r5900/dmult.c
diff --git a/tests/tcg/mips/mipsn32r5900/Makefile
b/tests/tcg/mips/mipsn32r5900/Makefile
new file mode 100644
index 0000000000..7dd16723fe
--- /dev/null
+++ b/tests/tcg/mips/mipsn32r5900/Makefile
@@ -0,0 +1,25 @@
+-include ../../config-host.mak
+
+CROSS=mips64r5900el-unknown-linux-gnu-
+
+SIM=qemu-mipsn32el
+SIM_FLAGS=-cpu R5900
+
+CC = $(CROSS)gcc
+CFLAGS = -Wall -mabi=n32 -march=r5900 -static
+
+TESTCASES = dmult.tst
+
+all: $(TESTCASES)
+
+%.tst: %.c
+ $(CC) $(CFLAGS) $< -o $@
+
+check: $(TESTCASES)
+ @for case in $(TESTCASES); do \
+ echo $(SIM) $(SIM_FLAGS) ./$$case;\
+ $(SIM) $(SIM_FLAGS) ./$$case; \
+ done
+
+clean:
+ $(RM) -rf $(TESTCASES)
diff --git a/tests/tcg/mips/mipsn32r5900/dmult.c
b/tests/tcg/mips/mipsn32r5900/dmult.c
new file mode 100644
index 0000000000..2827ab5358
--- /dev/null
+++ b/tests/tcg/mips/mipsn32r5900/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;
+}
--
2.18.1