aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-09-01 08:33:02 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-09-01 08:33:02 +0100
commitec397e90d21269037280633b6058d1f280e27667 (patch)
tree2524ceef0aec4dac7564a2287e02d6185e61963a /tests
parentd52dff5d8048d4982437db9606c27bb4127cf9d0 (diff)
parent8e034ae44dba6291beb07f7f2a932c1e5ab83e98 (diff)
downloadqemu-ec397e90d21269037280633b6058d1f280e27667.zip
qemu-ec397e90d21269037280633b6058d1f280e27667.tar.gz
qemu-ec397e90d21269037280633b6058d1f280e27667.tar.bz2
Merge remote-tracking branch 'remotes/alistair/tags/pull-riscv-to-apply-20210901-2' into staging
First RISC-V PR for QEMU 6.2 - Add a config for Shakti UART - Fixup virt flash node - Don't override users supplied ISA version - Fixup some CSR accesses - Use g_strjoinv() for virt machine PLIC string config - Fix an overflow in the SiFive CLINT - Add 64-bit register access helpers - Replace tcg_const_* with direct constant usage # gpg: Signature made Wed 01 Sep 2021 03:08:48 BST # gpg: using RSA key F6C4AC46D4934868D3B8CE8F21E10D29DF977054 # gpg: Good signature from "Alistair Francis <alistair@alistair23.me>" [full] # Primary key fingerprint: F6C4 AC46 D493 4868 D3B8 CE8F 21E1 0D29 DF97 7054 * remotes/alistair/tags/pull-riscv-to-apply-20210901-2: (33 commits) target/riscv: Use {get,dest}_gpr for RVV target/riscv: Tidy trans_rvh.c.inc target/riscv: Use {get,dest}_gpr for RVD target/riscv: Use {get,dest}_gpr for RVF target/riscv: Use gen_shift_imm_fn for slli_uw target/riscv: Use {get,dest}_gpr for RVA target/riscv: Reorg csr instructions target/riscv: Fix hgeie, hgeip target/riscv: Fix rmw_sip, rmw_vsip, rmw_hsip vs write-only operation target/riscv: Use {get, dest}_gpr for integer load/store target/riscv: Use get_gpr in branches target/riscv: Use extracts for sraiw and srliw target/riscv: Use DisasExtend in shift operations target/riscv: Add DisasExtend to gen_unary target/riscv: Move gen_* helpers for RVB target/riscv: Move gen_* helpers for RVM target/riscv: Use gen_arith for mulh and mulhu target/riscv: Remove gen_arith_div* target/riscv: Add DisasExtend to gen_arith* target/riscv: Introduce DisasExtend and new helpers ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/tcg/riscv64/Makefile.target5
-rw-r--r--tests/tcg/riscv64/test-div.c58
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target
new file mode 100644
index 0000000..d41bf6d
--- /dev/null
+++ b/tests/tcg/riscv64/Makefile.target
@@ -0,0 +1,5 @@
+# -*- Mode: makefile -*-
+# RISC-V specific tweaks
+
+VPATH += $(SRC_PATH)/tests/tcg/riscv64
+TESTS += test-div
diff --git a/tests/tcg/riscv64/test-div.c b/tests/tcg/riscv64/test-div.c
new file mode 100644
index 0000000..a90480b
--- /dev/null
+++ b/tests/tcg/riscv64/test-div.c
@@ -0,0 +1,58 @@
+#include <assert.h>
+#include <limits.h>
+
+struct TestS {
+ long x, y, q, r;
+};
+
+static struct TestS test_s[] = {
+ { 4, 2, 2, 0 }, /* normal cases */
+ { 9, 7, 1, 2 },
+ { 0, 0, -1, 0 }, /* div by zero cases */
+ { 9, 0, -1, 9 },
+ { LONG_MIN, -1, LONG_MIN, 0 }, /* overflow case */
+};
+
+struct TestU {
+ unsigned long x, y, q, r;
+};
+
+static struct TestU test_u[] = {
+ { 4, 2, 2, 0 }, /* normal cases */
+ { 9, 7, 1, 2 },
+ { 0, 0, ULONG_MAX, 0 }, /* div by zero cases */
+ { 9, 0, ULONG_MAX, 9 },
+};
+
+#define ARRAY_SIZE(X) (sizeof(X) / sizeof(*(X)))
+
+int main (void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(test_s); i++) {
+ long q, r;
+
+ asm("div %0, %2, %3\n\t"
+ "rem %1, %2, %3"
+ : "=&r" (q), "=r" (r)
+ : "r" (test_s[i].x), "r" (test_s[i].y));
+
+ assert(q == test_s[i].q);
+ assert(r == test_s[i].r);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(test_u); i++) {
+ unsigned long q, r;
+
+ asm("divu %0, %2, %3\n\t"
+ "remu %1, %2, %3"
+ : "=&r" (q), "=r" (r)
+ : "r" (test_u[i].x), "r" (test_u[i].y));
+
+ assert(q == test_u[i].q);
+ assert(r == test_u[i].r);
+ }
+
+ return 0;
+}