[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/8] tests/tcg/loongarch64: Add div and mod related instructions
From: |
Song Gao |
Subject: |
[PATCH 5/8] tests/tcg/loongarch64: Add div and mod related instructions test |
Date: |
Sat, 16 Jul 2022 16:54:23 +0800 |
This includes:
- DIV.{W[U]/D[U]}
- MOD.{W[U]/D[U]}
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
tests/tcg/loongarch64/Makefile.target | 1 +
tests/tcg/loongarch64/test_div.c | 54 +++++++++++++++++++++++++++
2 files changed, 55 insertions(+)
create mode 100644 tests/tcg/loongarch64/test_div.c
diff --git a/tests/tcg/loongarch64/Makefile.target
b/tests/tcg/loongarch64/Makefile.target
index c0bd8b9b86..24d6bb11e9 100644
--- a/tests/tcg/loongarch64/Makefile.target
+++ b/tests/tcg/loongarch64/Makefile.target
@@ -11,5 +11,6 @@ VPATH += $(LOONGARCH64_SRC)
LDFLAGS+=-lm
LOONGARCH64_TESTS = test_bit
+LOONGARCH64_TESTS += test_div
TESTS += $(LOONGARCH64_TESTS)
diff --git a/tests/tcg/loongarch64/test_div.c b/tests/tcg/loongarch64/test_div.c
new file mode 100644
index 0000000000..6c31fe97ae
--- /dev/null
+++ b/tests/tcg/loongarch64/test_div.c
@@ -0,0 +1,54 @@
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+
+#define TEST_DIV(N, M) \
+static void test_div_ ##N(uint ## M ## _t rj, \
+ uint ## M ## _t rk, \
+ uint64_t rm) \
+{ \
+ uint64_t rd = 0; \
+ \
+ asm volatile("div."#N" %0,%1,%2\n\t" \
+ : "=r"(rd) \
+ : "r"(rj), "r"(rk) \
+ : ); \
+ assert(rd == rm); \
+}
+
+#define TEST_MOD(N, M) \
+static void test_mod_ ##N(uint ## M ## _t rj, \
+ uint ## M ## _t rk, \
+ uint64_t rm) \
+{ \
+ uint64_t rd = 0; \
+ \
+ asm volatile("mod."#N" %0,%1,%2\n\t" \
+ : "=r"(rd) \
+ : "r"(rj), "r"(rk) \
+ : ); \
+ assert(rd == rm); \
+}
+
+TEST_DIV(w, 32)
+TEST_DIV(wu, 32)
+TEST_DIV(d, 64)
+TEST_DIV(du, 64)
+TEST_MOD(w, 32)
+TEST_MOD(wu, 32)
+TEST_MOD(d, 64)
+TEST_MOD(du, 64)
+
+int main(void)
+{
+ test_div_w(0xffaced97, 0xc36abcde, 0x0);
+ test_div_wu(0xffaced97, 0xc36abcde, 0x1);
+ test_div_d(0xffaced973582005f, 0xef56832a358b, 0xffffffffffffffa8);
+ test_div_du(0xffaced973582005f, 0xef56832a358b, 0x11179);
+ test_mod_w(0x7cf18c32, 0xa04da650, 0x1d3f3282);
+ test_mod_wu(0x7cf18c32, 0xc04da650, 0x7cf18c32);
+ test_mod_d(0x7cf18c3200000000, 0xa04da65000000000, 0x1d3f328200000000);
+ test_mod_du(0x7cf18c3200000000, 0xc04da65000000000, 0x7cf18c3200000000);
+
+ return 0;
+}
--
2.31.1
- [PATCH 0/8] tests/tcg/loongarch64: Add some tests., Song Gao, 2022/07/16
- [PATCH 5/8] tests/tcg/loongarch64: Add div and mod related instructions test,
Song Gao <=
- [PATCH 4/8] tests/tcg/loongarch64: Add clo related instructions test, Song Gao, 2022/07/16
- [PATCH 1/8] tests/tcg/loongarch64: Add float reference files, Song Gao, 2022/07/16
- [PATCH 6/8] tests/tcg/loongarch64: Add fclass test, Song Gao, 2022/07/16
- [PATCH 2/8] fpu/softfloat: Add LoongArch specialization for pickNaNMulAdd, Song Gao, 2022/07/16
- [PATCH 8/8] tests/tcg/loongarch64: Add pcadd related instructions test, Song Gao, 2022/07/16
- [PATCH 3/8] target/loongarch: Fix float_convd/float_convs test failing, Song Gao, 2022/07/16
- [PATCH 7/8] tests/tcg/loongarch64: Add som comparison instructions test, Song Gao, 2022/07/16