Skip to contentSkip to conversation

tests/tcg: Add MIPS32 Release 6 tests

PATCH In review Philippe Mathieu-Daudé 2 participants 16 messages Oct 30 – Nov 2 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover tests/tcg: Add MIPS32 Release 6 tests

v2:
- Use Debian toolchain instead of Bootlin (pbo)
- Convert to TAP

v1:
- Include Bootlin mips32r6el toolchain in debian-all-test container
- Wire it to meson
- Cover all the 32-bit opcodes tested in MIPS64 Rel6 (using TAP)

Based-on: <[email protected]>

Philippe Mathieu-Daudé (12):
tests/docker: Add the mips32r6el toolchain on Debian cross container
meson: Add the tcg_tests_cross_cc/cflags options for mips32r6el tests/tcg/mipsel: Add MIPS32R6 logic tests tests/tcg/mipsel: Add MIPS32R6 shift tests tests/tcg/mipsel: Add MIPS32R6 bit operation tests tests/tcg/mipsel: Add MIPS32R6 multiply tests tests/tcg/mipsel: Add MIPS32R6 PC-relative tests tests/tcg/mipsel: Test MIPS32R6 SELEQZ and SELNEZ tests/tcg/mipsel: Test MIPS32R6 DIV, MOD, DIVU and MODU tests/tcg/mipsel: Test MIPS32R6 LSA
tests/tcg/mipsel: Test MIPS32R6 BALC
tests/tcg/mipsel: Test MIPS32R6 JIALC and JIC

 tests/tcg/mips/include/wrappers_mips32r6.h    |  91 +++++++++++++
 tests/tcg/mipsel/test_mips32r6_bitops.c       |  79 +++++++++++
 tests/tcg/mipsel/test_mips32r6_branch.c       | 124 ++++++++++++++++++
 tests/tcg/mipsel/test_mips32r6_logic.c        |  65 +++++++++
 tests/tcg/mipsel/test_mips32r6_multiply.c     | 104 +++++++++++++++
 tests/tcg/mipsel/test_mips32r6_pcrel.c        |  88 +++++++++++++
 tests/tcg/mipsel/test_mips32r6_shift.c        |  81 ++++++++++++
 .../dockerfiles/debian-all-test-cross.docker  |   3 +
 meson_options.txt                             |   4 +
 scripts/meson-buildoptions.sh                 |   2 +
 tests/tcg/mipsel/meson.build                  |  34 +++++
 11 files changed, 675 insertions(+)
 create mode 100644 tests/tcg/mips/include/wrappers_mips32r6.h
 create mode 100644 tests/tcg/mipsel/test_mips32r6_bitops.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_branch.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_logic.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_multiply.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_pcrel.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_shift.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/12 tests/docker: Add the mips32r6el toolchain on Debian cross container

Use mipsisa32r6el-linux-gnu-gcc for the little-endian MIPS32R6 tests and install its compiler, binutils and libc development packages in the shared Debian cross image.

---
 tests/docker/dockerfiles/debian-all-test-cross.docker | 3 +++
 1 file changed, 3 insertions(+)
tests/docker/dockerfiles/debian-all-test-cross.docker +3 -0
index eefc03c49a4f..4bbed2cdf08c 100644
@@ -89,6 +89,9 @@ RUN apt update && \
   libc6-dev-mips64el-cross \
   gcc-mipsel-linux-gnu \
   libc6-dev-mipsel-cross \
+  gcc-mipsisa32r6el-linux-gnu \
+  binutils-mipsisa32r6el-linux-gnu \
+  libc6-dev-mipsr6el-cross \
   gcc-mipsisa64r6-linux-gnuabi64 \
   libc6-dev-mips64r6-cross \
   gcc-mipsisa64r6el-linux-gnuabi64 \
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v2 01/12] tests/docker: Add the mips32r6el toolchain on Debian cross container

Quoted 14 lines · Philippe Mathieu-Daudé

Use mipsisa32r6el-linux-gnu-gcc for the little-endian MIPS32R6 tests and install its compiler, binutils and libc development packages in the shared Debian cross image.

---
 tests/docker/dockerfiles/debian-all-test-cross.docker | 3 +++
 1 file changed, 3 insertions(+)
tests/docker/dockerfiles/debian-all-test-cross.docker +0 -0
index eefc03c49a4f..4bbed2cdf08c 100644

tests/docker/dockerfiles/debian-all-test-cross.docker RUN apt update && \ · line 93

Quoted 5 lines
tests/docker/dockerfiles/debian-all-test-cross.docker +2 -0
@@ -89,6 +89,9 @@ RUN apt update && \
   libc6-dev-mips64el-cross \
   gcc-mipsel-linux-gnu \
   libc6-dev-mipsel-cross \
+  gcc-mipsisa32r6el-linux-gnu \
+  binutils-mipsisa32r6el-linux-gnu \

Any reason you need binutils?
Seems like it's not required for other mips variant.

Quoted 4 lines
tests/docker/dockerfiles/debian-all-test-cross.docker +1 -0
+  libc6-dev-mipsr6el-cross \
   gcc-mipsisa64r6-linux-gnuabi64 \
   libc6-dev-mips64r6-cross \
   gcc-mipsisa64r6el-linux-gnuabi64 \
#3 lore raw

Re: [PATCH v2 01/12] tests/docker: Add the mips32r6el toolchain on Debian cross container

Quoted 10 lines · Pierrick Bouvier
Quoted 9 lines · Philippe Mathieu-Daudé

Use mipsisa32r6el-linux-gnu-gcc for the little-endian MIPS32R6 tests and install its compiler, binutils and libc development packages in the shared Debian cross image.

---
  tests/docker/dockerfiles/debian-all-test-cross.docker | 3 +++
  1 file changed, 3 insertions(+)
Quoted 13 lines

tests/docker/dockerfiles/debian-all-test-cross.docker RUN apt update && \ · line 93

Quoted 10 lines
tests/docker/dockerfiles/debian-all-test-cross.docker +2 -0
index eefc03c49a4f..4bbed2cdf08c 100644
@@ -89,6 +89,9 @@ RUN apt update && \
    libc6-dev-mips64el-cross \
    gcc-mipsel-linux-gnu \
    libc6-dev-mipsel-cross \
+  gcc-mipsisa32r6el-linux-gnu \
+  binutils-mipsisa32r6el-linux-gnu \

Any reason you need binutils?
Seems like it's not required for other mips variant.

Not needed indeed.

Quoted 7 lines
Quoted 5 lines
tests/docker/dockerfiles/debian-all-test-cross.docker +1 -0
+  libc6-dev-mipsr6el-cross \
    gcc-mipsisa64r6-linux-gnuabi64 \
    libc6-dev-mips64r6-cross \
    gcc-mipsisa64r6el-linux-gnuabi64 \
#4 lore raw

PATCH v2 2/12 meson: Add the tcg_tests_cross_cc/cflags options for mips32r6el

In reply to Philippe Mathieu-Daudé

Add meson tcg_tests_cross_cc/cflags options for mips32r6el, similarly of the previous mips32r5el commit c7b1a7bc9d33 ("tests/tcg/mipsel/mips32r5el: add msa tests"). This allows compiling TCG tests for the mips32r6el-linux-user targets.

---
 meson_options.txt             | 4 ++++
 scripts/meson-buildoptions.sh | 2 ++
 2 files changed, 6 insertions(+)
meson_options.txt +4 -0
index 895c6e63c28a..9ae8e44ab54e 100644
@@ -461,6 +461,10 @@ option('tcg_tests_cross_cc_mips32r5el', type: 'string',
        description: 'cc for mips32r5el tcg tests')
 option('tcg_tests_cross_cflags_mips32r5el', type: 'string',
        description: 'cflags for mips32r5el tcg tests')
+option('tcg_tests_cross_cc_mips32r6el', type: 'string',
+       description: 'cc for mips32r6el tcg tests')
+option('tcg_tests_cross_cflags_mips32r6el', type: 'string',
+       description: 'cflags for mips32r6el tcg tests')
 option('tcg_tests_cross_cc_or1k', type: 'string',
        description: 'cc for or1k tcg tests')
 option('tcg_tests_cross_cflags_or1k', type: 'string',
scripts/meson-buildoptions.sh +2 -0
index 14990966d31d..0f8b56bd7f8c 100644
@@ -539,6 +539,7 @@ _meson_option_parse() {
     --tcg-tests-cross-cc-m68k=*) quote_sh "-Dtcg_tests_cross_cc_m68k=$2" ;;
     --tcg-tests-cross-cc-mips=*) quote_sh "-Dtcg_tests_cross_cc_mips=$2" ;;
     --tcg-tests-cross-cc-mips32r5el=*) quote_sh "-Dtcg_tests_cross_cc_mips32r5el=$2" ;;
+    --tcg-tests-cross-cc-mips32r6el=*) quote_sh "-Dtcg_tests_cross_cc_mips32r6el=$2" ;;
     --tcg-tests-cross-cc-mips64=*) quote_sh "-Dtcg_tests_cross_cc_mips64=$2" ;;
     --tcg-tests-cross-cc-mips64el=*) quote_sh "-Dtcg_tests_cross_cc_mips64el=$2" ;;
     --tcg-tests-cross-cc-mips64r6=*) quote_sh "-Dtcg_tests_cross_cc_mips64r6=$2" ;;
@@ -566,6 +567,7 @@ _meson_option_parse() {
     --tcg-tests-cross-cflags-m68k=*) quote_sh "-Dtcg_tests_cross_cflags_m68k=$2" ;;
     --tcg-tests-cross-cflags-mips=*) quote_sh "-Dtcg_tests_cross_cflags_mips=$2" ;;
     --tcg-tests-cross-cflags-mips32r5el=*) quote_sh "-Dtcg_tests_cross_cflags_mips32r5el=$2" ;;
+    --tcg-tests-cross-cflags-mips32r6el=*) quote_sh "-Dtcg_tests_cross_cflags_mips32r6el=$2" ;;
     --tcg-tests-cross-cflags-mips64=*) quote_sh "-Dtcg_tests_cross_cflags_mips64=$2" ;;
     --tcg-tests-cross-cflags-mips64el=*) quote_sh "-Dtcg_tests_cross_cflags_mips64el=$2" ;;
     --tcg-tests-cross-cflags-mips64r6=*) quote_sh "-Dtcg_tests_cross_cflags_mips64r6=$2" ;;
Signature · 1 line
2.55.0
#5 lore raw

PATCH v2 3/12 tests/tcg/mipsel: Add MIPS32R6 logic tests

In reply to Philippe Mathieu-Daudé

Add a mips32r6el-linux-user target running, on mips32r6-generic, 32-bit versions of the Release 6 tests that don't need 64-bit registers, starting with and, nor, or and xor. Output is TAP.

---
 tests/tcg/mips/include/wrappers_mips32r6.h | 61 ++++++++++++++++++++++
 tests/tcg/mipsel/test_mips32r6_logic.c     | 60 +++++++++++++++++++++
 tests/tcg/mipsel/meson.build               | 29 ++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 tests/tcg/mips/include/wrappers_mips32r6.h
 create mode 100644 tests/tcg/mipsel/test_mips32r6_logic.c
tests/tcg/mips/include/wrappers_mips32r6.h new file +61 -0
new file mode 100644
index 000000000000..316aa69ef582
@@ -0,0 +1,61 @@
+/*
+ * Wrappers for MIPS32R6 instructions operating on 32-bit values
+ * (32-bit counterpart of wrappers_mips64r6.h).
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef WRAPPERS_MIPS32R6_H
+#define WRAPPERS_MIPS32R6_H
+
+#include <stdint.h>
+
+#define DO_MIPS32R6__RD__RS(suffix, mnemonic)                          \
+static inline void do_mips32r6_##suffix(const uint32_t *input,         \
+                                        uint32_t *output)              \
+{                                                                      \
+   __asm__ volatile (                                                  \
+      "lw $t1, 0(%0)\n\t"                                              \
+      #mnemonic " $t0, $t1\n\t"                                        \
+      "sw $t0, 0(%1)\n\t"                                              \
+      :                                                                \
+      : "r" (input), "r" (output)                                      \
+      : "t0", "t1", "memory"                                           \
+   );                                                                  \
+}
+
+#define DO_MIPS32R6__RD__RS_RT(suffix, mnemonic)                       \
+static inline void do_mips32r6_##suffix(const uint32_t *input1,        \
+                                        const uint32_t *input2,        \
+                                        uint32_t *output)              \
+{                                                                      \
+   __asm__ volatile (                                                  \
+      "lw $t1, 0(%0)\n\t"                                              \
+      "lw $t2, 0(%1)\n\t"                                              \
+      #mnemonic " $t0, $t1, $t2\n\t"                                   \
+      "sw $t0, 0(%2)\n\t"                                              \
+      :                                                                \
+      : "r" (input1), "r" (input2), "r" (output)                       \
+      : "t0", "t1", "t2", "memory"                                     \
+   );                                                                  \
+}
+
+DO_MIPS32R6__RD__RS(CLO, clo)
+DO_MIPS32R6__RD__RS(CLZ, clz)
+DO_MIPS32R6__RD__RS(BITSWAP, bitswap)
+
+DO_MIPS32R6__RD__RS_RT(SLLV, sllv)
+DO_MIPS32R6__RD__RS_RT(SRLV, srlv)
+DO_MIPS32R6__RD__RS_RT(SRAV, srav)
+
+DO_MIPS32R6__RD__RS_RT(MUL, mul)
+DO_MIPS32R6__RD__RS_RT(MUH, muh)
+DO_MIPS32R6__RD__RS_RT(MULU, mulu)
+DO_MIPS32R6__RD__RS_RT(MUHU, muhu)
+
+DO_MIPS32R6__RD__RS_RT(AND, and)
+DO_MIPS32R6__RD__RS_RT(NOR, nor)
+DO_MIPS32R6__RD__RS_RT(OR, or)
+DO_MIPS32R6__RD__RS_RT(XOR, xor)
+
+#endif
tests/tcg/mipsel/test_mips32r6_logic.c new file +60 -0

60 lines not on this page · raw message

tests/tcg/mipsel/meson.build +29 -0
index 1951c3c437fb..d64cf50f5a05 100644
@@ -63,3 +63,32 @@ if 'qemu-mipsel' in emulators
     }
   }
 endif
+
+tests = []
+
+tests_mips32r6 = [
+  'test_mips32r6_logic.c',
+]
+
+foreach src: tests_mips32r6
+  tests += {
+    src: {
+      'cflags': ['-mabi=32', '-march=mips32r6'],
+      'qemu_args': ['-cpu', 'mips32r6-generic'],
+      'protocol': 'tap',
+    }
+  }
+endforeach
+
+if 'qemu-mipsel' in emulators
+  tcg_tests += {
+    'mips32r6el-linux-user': {
+      'cc': 'mipsisa32r6el-linux-gnu-gcc',
+      'cc_dockerfile': 'debian-all-test-cross',
+      'folder': 'mipsel',
+      'gdb_arch': 'mipsel',
+      'qemu': emulators['qemu-mipsel'],
+      'tests': tests,
+    }
+  }
+endif
Signature · 1 line
2.55.0
#6 lore raw

PATCH v2 4/12 tests/tcg/mipsel: Add MIPS32R6 shift tests

In reply to Philippe Mathieu-Daudé

Test SLLV, SRLV and SRAV.

---
 tests/tcg/mipsel/test_mips32r6_shift.c | 73 ++++++++++++++++++++++++++
 tests/tcg/mipsel/meson.build           |  1 +
 2 files changed, 74 insertions(+)
 create mode 100644 tests/tcg/mipsel/test_mips32r6_shift.c
tests/tcg/mipsel/test_mips32r6_shift.c new file +73 -0
new file mode 100644
index 000000000000..0594796709f3
@@ -0,0 +1,73 @@
+/*
+ * MIPS32R6 tests: shift instructions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+
+#include "../include/tap.h"
+#include "../mips/include/wrappers_mips32r6.h"
+#include "../mips/include/test_inputs_32.h"
+
+typedef void (*binary_op_32)(const uint32_t *, const uint32_t *, uint32_t *);
+typedef uint32_t (*ref_op_32)(uint32_t, uint32_t);
+
+/* Only the low 5 bits of the shift amount (rs) are used. */
+static uint32_t ref_sllv(uint32_t a, uint32_t b) { return a << (b & 31); }
+static uint32_t ref_srlv(uint32_t a, uint32_t b) { return a >> (b & 31); }
+static uint32_t ref_srav(uint32_t a, uint32_t b)
+{
+    return (uint32_t)((int32_t)a >> (b & 31));
+}
+
+static int check_one(const char *name, binary_op_32 op, ref_op_32 ref,
+                     uint32_t a, uint32_t b)
+{
+    uint32_t res = 0;
+
+    op(&a, &b, &res);
+    if (res != ref(a, b)) {
+        TAP_INFO("%s: %08x, %08x: got %08x expected %08x",
+                 name, a, b, res, ref(a, b));
+        return 1;
+    }
+    return 0;
+}
+
+static int run(const char *name, binary_op_32 op, ref_op_32 ref)
+{
+    int ret = 0;
+
+    /* Value/amount pairs from the input tables. */
+    for (size_t i = 0; i < PATTERN_INPUTS_32_SHORT_COUNT; i++) {
+        for (size_t j = 0; j < PATTERN_INPUTS_32_SHORT_COUNT; j++) {
+            ret |= check_one(name, op, ref, b32_pattern[i], b32_pattern[j]);
+        }
+    }
+    for (size_t i = 0; i < RANDOM_INPUTS_32_SHORT_COUNT; i++) {
+        for (size_t j = 0; j < RANDOM_INPUTS_32_SHORT_COUNT; j++) {
+            ret |= check_one(name, op, ref, b32_random[i], b32_random[j]);
+        }
+    }
+    /* Every shift amount (including ones with ignored high bits). */
+    for (size_t i = 0; i < PATTERN_INPUTS_32_SHORT_COUNT; i++) {
+        for (uint32_t sa = 0; sa < 64; sa++) {
+            ret |= check_one(name, op, ref, b32_pattern[i], sa);
+        }
+    }
+    tap_report(!ret, "MIPS32R6 shift %s", name);
+    return ret;
+}
+
+int main(void)
+{
+    int ret = 0;
+
+    TAP_START();
+    ret |= run("SLLV", do_mips32r6_SLLV, ref_sllv);
+    ret |= run("SRLV", do_mips32r6_SRLV, ref_srlv);
+    ret |= run("SRAV", do_mips32r6_SRAV, ref_srav);
+
+    return tap_done();
+}
tests/tcg/mipsel/meson.build +1 -0
index d64cf50f5a05..3c40a556ad46 100644
@@ -68,6 +68,7 @@ tests = []
 
 tests_mips32r6 = [
   'test_mips32r6_logic.c',
+  'test_mips32r6_shift.c',
 ]
 
 foreach src: tests_mips32r6
Signature · 1 line
2.55.0
#7 lore raw

PATCH v2 5/12 tests/tcg/mipsel: Add MIPS32R6 bit operation tests

In reply to Philippe Mathieu-Daudé

Test CLO, CLZ and bitswap.

---
 tests/tcg/mipsel/test_mips32r6_bitops.c | 79 +++++++++++++++++++++++++
 tests/tcg/mipsel/test_mips32r6_shift.c  |  8 +--
 tests/tcg/mipsel/meson.build            |  1 +
 3 files changed, 83 insertions(+), 5 deletions(-)
 create mode 100644 tests/tcg/mipsel/test_mips32r6_bitops.c
tests/tcg/mipsel/test_mips32r6_bitops.c new file +79 -0
new file mode 100644
index 000000000000..8546209b50dd
@@ -0,0 +1,79 @@
+/*
+ * MIPS32R6 tests: bit operations instructions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+
+#include "../include/tap.h"
+#include "../mips/include/wrappers_mips32r6.h"
+#include "../mips/include/test_inputs_32.h"
+
+typedef void (*unary_op_32)(const uint32_t *, uint32_t *);
+typedef uint32_t (*ref_op_32)(uint32_t);
+
+static uint32_t ref_clz(uint32_t a) { return a ? __builtin_clz(a) : 32; }
+static uint32_t ref_clo(uint32_t a) { return ref_clz(~a); }
+
+/* BITSWAP reverses the bit order inside each byte. */
+static uint32_t ref_bitswap(uint32_t a)
+{
+    uint32_t res = 0;
+
+    for (int byte = 0; byte < 4; byte++) {
+        for (int bit = 0; bit < 8; bit++) {
+            if (a & (1u << (byte * 8 + bit))) {
+                res |= 1u << (byte * 8 + 7 - bit);
+            }
+        }
+    }
+    return res;
+}
+
+static int check_all(const char *name, unary_op_32 op, ref_op_32 ref,
+                     const uint32_t *input, size_t count)
+{
+    int fail = 0;
+
+    for (size_t i = 0; i < count; i++) {
+        uint32_t a = input[i], res = 0;
+
+        op(&a, &res);
+        if (res != ref(a)) {
+            TAP_INFO("%s: %08x: got %08x expected %08x",
+                     name, a, res, ref(a));
+            fail = 1;
+        }
+    }
+    return fail;
+}
+
+static int run(const char *name, unary_op_32 op, ref_op_32 ref)
+{
+    int ret = 0;
+
+    ret |= check_all(name, op, ref, b32_pattern, PATTERN_INPUTS_32_COUNT);
+    ret |= check_all(name, op, ref, b32_random, RANDOM_INPUTS_32_COUNT);
+    /* Every leading-run length, for both polarities. */
+    for (int n = 0; n < 32; n++) {
+        uint32_t v[2] = { 0xffffffffu >> n, ~(0xffffffffu >> n) };
+
+        ret |= check_all(name, op, ref, v, 2);
+        v[0] = 1u << n;
+        v[1] = ~(1u << n);
+        ret |= check_all(name, op, ref, v, 2);
+    }
+    tap_report(!ret, "MIPS32R6 bitops %s", name);
+    return ret;
+}
+
+int main(void)
+{
+    TAP_START();
+    run("CLO", do_mips32r6_CLO, ref_clo);
+    run("CLZ", do_mips32r6_CLZ, ref_clz);
+    run("BITSWAP", do_mips32r6_BITSWAP, ref_bitswap);
+
+    return tap_done();
+}
tests/tcg/mipsel/test_mips32r6_shift.c +3 -5
index 0594796709f3..6828e90dd8af 100644
@@ -62,12 +62,10 @@ static int run(const char *name, binary_op_32 op, ref_op_32 ref)
 
 int main(void)
 {
-    int ret = 0;
-
     TAP_START();
-    ret |= run("SLLV", do_mips32r6_SLLV, ref_sllv);
-    ret |= run("SRLV", do_mips32r6_SRLV, ref_srlv);
-    ret |= run("SRAV", do_mips32r6_SRAV, ref_srav);
+    run("SLLV", do_mips32r6_SLLV, ref_sllv);
+    run("SRLV", do_mips32r6_SRLV, ref_srlv);
+    run("SRAV", do_mips32r6_SRAV, ref_srav);
 
     return tap_done();
 }
tests/tcg/mipsel/meson.build +1 -0
index 3c40a556ad46..0c43c31e7355 100644
@@ -67,6 +67,7 @@ endif
 tests = []
 
 tests_mips32r6 = [
+  'test_mips32r6_bitops.c',
   'test_mips32r6_logic.c',
   'test_mips32r6_shift.c',
 ]
Signature · 1 line
2.55.0
#8 lore raw

PATCH v2 6/12 tests/tcg/mipsel: Add MIPS32R6 multiply tests

In reply to Philippe Mathieu-Daudé

Test MUL[U] and MUH[U].

---
 tests/tcg/mipsel/test_mips32r6_multiply.c | 75 +++++++++++++++++++++++
 tests/tcg/mipsel/meson.build              |  1 +
 2 files changed, 76 insertions(+)
 create mode 100644 tests/tcg/mipsel/test_mips32r6_multiply.c
tests/tcg/mipsel/test_mips32r6_multiply.c new file +75 -0
new file mode 100644
index 000000000000..17106391107a
@@ -0,0 +1,75 @@
+/*
+ * MIPS32R6 tests: multiply instructions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+
+#include "../include/tap.h"
+#include "../mips/include/wrappers_mips32r6.h"
+#include "../mips/include/test_inputs_32.h"
+
+typedef void (*binary_op_32)(const uint32_t *, const uint32_t *, uint32_t *);
+typedef uint32_t (*ref_op_32)(uint32_t, uint32_t);
+
+static uint32_t ref_mul(uint32_t a, uint32_t b)
+{
+    return (uint32_t)((int64_t)(int32_t)a * (int32_t)b);
+}
+
+static uint32_t ref_muh(uint32_t a, uint32_t b)
+{
+    return (uint32_t)(((int64_t)(int32_t)a * (int32_t)b) >> 32);
+}
+
+static uint32_t ref_mulu(uint32_t a, uint32_t b)
+{
+    return (uint32_t)((uint64_t)a * b);
+}
+
+static uint32_t ref_muhu(uint32_t a, uint32_t b)
+{
+    return (uint32_t)(((uint64_t)a * b) >> 32);
+}
+
+static int check_op(const char *name, binary_op_32 op, ref_op_32 ref,
+                    const uint32_t *input, size_t count)
+{
+    int fail = 0;
+
+    for (size_t i = 0; i < count; i++) {
+        for (size_t j = 0; j < count; j++) {
+            uint32_t a = input[i], b = input[j], res = 0;
+
+            op(&a, &b, &res);
+            if (res != ref(a, b)) {
+                TAP_INFO("%s: %08x, %08x: got %08x expected %08x",
+                         name, a, b, res, ref(a, b));
+                fail = 1;
+            }
+        }
+    }
+    return fail;
+}
+
+static int run(const char *name, binary_op_32 op, ref_op_32 ref)
+{
+    int ret = 0;
+
+    ret |= check_op(name, op, ref, b32_pattern, PATTERN_INPUTS_32_COUNT);
+    ret |= check_op(name, op, ref, b32_random, RANDOM_INPUTS_32_COUNT);
+    tap_report(!ret, "MIPS32R6 multiply %s", name);
+    return ret;
+}
+
+int main(void)
+{
+    TAP_START();
+    run("MUL", do_mips32r6_MUL, ref_mul);
+    run("MUH", do_mips32r6_MUH, ref_muh);
+    run("MULU", do_mips32r6_MULU, ref_mulu);
+    run("MUHU", do_mips32r6_MUHU, ref_muhu);
+
+    return tap_done();
+}
tests/tcg/mipsel/meson.build +1 -0
index 0c43c31e7355..f540d18b3bd2 100644
@@ -69,6 +69,7 @@ tests = []
 tests_mips32r6 = [
   'test_mips32r6_bitops.c',
   'test_mips32r6_logic.c',
+  'test_mips32r6_multiply.c',
   'test_mips32r6_shift.c',
 ]
 
Signature · 1 line
2.55.0
#9 lore raw

PATCH v2 7/12 tests/tcg/mipsel: Add MIPS32R6 PC-relative tests

In reply to Philippe Mathieu-Daudé

Test A[L]UIPC opcodes.

---
 tests/tcg/mipsel/test_mips32r6_pcrel.c | 88 ++++++++++++++++++++++++++
 tests/tcg/mipsel/meson.build           |  1 +
 2 files changed, 89 insertions(+)
 create mode 100644 tests/tcg/mipsel/test_mips32r6_pcrel.c
tests/tcg/mipsel/test_mips32r6_pcrel.c new file +88 -0
new file mode 100644
index 000000000000..c93bca0ac06e
@@ -0,0 +1,88 @@
+/*
+ * MIPS32R6 tests: PC-relative AUIPC and ALUIPC instructions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+
+#include "../include/tap.h"
+
+/*
+ * Run INSN with the immediate IMM, and probe the address of INSN with a
+ * second AUIPC (which yields its own address, +4 being INSN's size).
+ */
+#define PCREL(insn, imm, res, addr)                                     \
+    __asm__ volatile (                                                  \
+        ".set push\n\t"                                                 \
+        ".set noreorder\n\t"                                            \
+        insn " %0, " #imm "\n\t"                                        \
+        "auipc %1, 0\n\t"                                               \
+        ".set pop\n\t"                                                  \
+        : "=r" (res), "=r" (addr))
+
+static int check(const char *name, uint32_t imm, uint32_t res, uint32_t probe,
+                 int aligned)
+{
+    /* The probe AUIPC is the instruction after the tested one. */
+    uint32_t addr = probe - 4;
+    uint32_t expected = addr + (imm << 16);
+    int ok;
+
+    if (aligned) {
+        expected &= ~0xffffu;
+    }
+    ok = res == expected;
+    if (!ok) {
+        TAP_INFO("%s imm=0x%04x at 0x%08x: got 0x%08x expected 0x%08x",
+                 name, imm, addr, res, expected);
+    }
+    return !ok;
+}
+
+#define CHECK_AUIPC(imm)                                                \
+    do {                                                                \
+        uint32_t res, probe;                                            \
+        PCREL("auipc", imm, res, probe);                                \
+        ret |= check("AUIPC", imm, res, probe, 0);                      \
+    } while (0)
+
+#define CHECK_ALUIPC(imm)                                               \
+    do {                                                                \
+        uint32_t res, probe;                                            \
+        PCREL("aluipc", imm, res, probe);                               \
+        ret |= check("ALUIPC", imm, res, probe, 1);                     \
+    } while (0)
+
+static int test_auipc(void)
+{
+    int ret = 0;
+
+    CHECK_AUIPC(0);
+    CHECK_AUIPC(1);
+    CHECK_AUIPC(0x7fff);
+    CHECK_AUIPC(0x8000);
+    CHECK_AUIPC(0xffff);
+    return ret;
+}
+
+static int test_aluipc(void)
+{
+    int ret = 0;
+
+    CHECK_ALUIPC(0);
+    CHECK_ALUIPC(1);
+    CHECK_ALUIPC(0x7fff);
+    CHECK_ALUIPC(0x8000);
+    CHECK_ALUIPC(0xffff);
+    return ret;
+}
+
+int main(void)
+{
+    TAP_START();
+    tap_report(!test_auipc(), "MIPS32R6 AUIPC");
+    tap_report(!test_aluipc(), "MIPS32R6 ALUIPC");
+
+    return tap_done();
+}
tests/tcg/mipsel/meson.build +1 -0
index f540d18b3bd2..a7af2f16192f 100644
@@ -70,6 +70,7 @@ tests_mips32r6 = [
   'test_mips32r6_bitops.c',
   'test_mips32r6_logic.c',
   'test_mips32r6_multiply.c',
+  'test_mips32r6_pcrel.c',
   'test_mips32r6_shift.c',
 ]
 
Signature · 1 line
2.55.0
#10 lore raw

PATCH v2 8/12 tests/tcg/mipsel: Test MIPS32R6 SELEQZ and SELNEZ

In reply to Philippe Mathieu-Daudé

Test SEL[EQ/NE]Z.

---
 tests/tcg/mips/include/wrappers_mips32r6.h | 3 +++
 tests/tcg/mipsel/test_mips32r6_logic.c     | 5 +++++
 2 files changed, 8 insertions(+)
tests/tcg/mips/include/wrappers_mips32r6.h +3 -0
index 316aa69ef582..aaa8afcae95b 100644
@@ -58,4 +58,7 @@ DO_MIPS32R6__RD__RS_RT(NOR, nor)
 DO_MIPS32R6__RD__RS_RT(OR, or)
 DO_MIPS32R6__RD__RS_RT(XOR, xor)
 
+DO_MIPS32R6__RD__RS_RT(SELEQZ, seleqz)
+DO_MIPS32R6__RD__RS_RT(SELNEZ, selnez)
+
 #endif
tests/tcg/mipsel/test_mips32r6_logic.c +5 -0
index b640aa0975b5..45fc8e3a9ef7 100644
@@ -17,6 +17,9 @@ static uint32_t ref_and(uint32_t a, uint32_t b) { return a & b; }
 static uint32_t ref_nor(uint32_t a, uint32_t b) { return ~(a | b); }
 static uint32_t ref_or(uint32_t a, uint32_t b) { return a | b; }
 static uint32_t ref_xor(uint32_t a, uint32_t b) { return a ^ b; }
+/* SELEQZ/SELNEZ select rs, or zero, depending on rt. */
+static uint32_t ref_seleqz(uint32_t a, uint32_t b) { return b == 0 ? a : 0; }
+static uint32_t ref_selnez(uint32_t a, uint32_t b) { return b != 0 ? a : 0; }
 
 static int check_op(const char *name, binary_op_32 op, ref_op_32 ref,
                     const uint32_t *input, size_t count)
@@ -55,6 +58,8 @@ int main(void)
     run("NOR", do_mips32r6_NOR, ref_nor);
     run("OR", do_mips32r6_OR, ref_or);
     run("XOR", do_mips32r6_XOR, ref_xor);
+    run("SELEQZ", do_mips32r6_SELEQZ, ref_seleqz);
+    run("SELNEZ", do_mips32r6_SELNEZ, ref_selnez);
 
     return tap_done();
 }
Signature · 1 line
2.55.0
#11 lore raw

PATCH v2 9/12 tests/tcg/mipsel: Test MIPS32R6 DIV, MOD, DIVU and MODU

In reply to Philippe Mathieu-Daudé

Test DIV[U] and MOD[U]. A zero divisor and INT_MIN / -1 are skipped: their result is UNPREDICTABLE.

---
 tests/tcg/mips/include/wrappers_mips32r6.h |  5 +++
 tests/tcg/mipsel/test_mips32r6_multiply.c  | 45 ++++++++++++++++++----
 2 files changed, 42 insertions(+), 8 deletions(-)
tests/tcg/mips/include/wrappers_mips32r6.h +5 -0
index aaa8afcae95b..cbff8450b656 100644
@@ -53,6 +53,11 @@ DO_MIPS32R6__RD__RS_RT(MUH, muh)
 DO_MIPS32R6__RD__RS_RT(MULU, mulu)
 DO_MIPS32R6__RD__RS_RT(MUHU, muhu)
 
+DO_MIPS32R6__RD__RS_RT(DIV, div)
+DO_MIPS32R6__RD__RS_RT(MOD, mod)
+DO_MIPS32R6__RD__RS_RT(DIVU, divu)
+DO_MIPS32R6__RD__RS_RT(MODU, modu)
+
 DO_MIPS32R6__RD__RS_RT(AND, and)
 DO_MIPS32R6__RD__RS_RT(NOR, nor)
 DO_MIPS32R6__RD__RS_RT(OR, or)
tests/tcg/mipsel/test_mips32r6_multiply.c +37 -8

79 lines not on this page · raw message

Signature · 1 line
2.55.0
#12 lore raw

PATCH v2 10/12 tests/tcg/mipsel: Test MIPS32R6 LSA

In reply to Philippe Mathieu-Daudé

Test LSA opcode.

---
 tests/tcg/mips/include/wrappers_mips32r6.h | 22 ++++++++++++++++++++++
 tests/tcg/mipsel/test_mips32r6_shift.c     | 10 ++++++++++
 2 files changed, 32 insertions(+)
tests/tcg/mips/include/wrappers_mips32r6.h +22 -0
index cbff8450b656..63b4496b3188 100644
@@ -48,6 +48,28 @@ DO_MIPS32R6__RD__RS_RT(SLLV, sllv)
 DO_MIPS32R6__RD__RS_RT(SRLV, srlv)
 DO_MIPS32R6__RD__RS_RT(SRAV, srav)
 
+/* LSA rd, rs, rt, sa: rd = (rs << sa) + rt, with sa in 1..4. */
+#define DO_MIPS32R6__LSA(suffix, sa)                                   \
+static inline void do_mips32r6_##suffix(const uint32_t *input1,        \
+                                        const uint32_t *input2,        \
+                                        uint32_t *output)              \
+{                                                                      \
+   __asm__ volatile (                                                  \
+      "lw $t1, 0(%0)\n\t"                                              \
+      "lw $t2, 0(%1)\n\t"                                              \
+      "lsa $t0, $t1, $t2, " #sa "\n\t"                                 \
+      "sw $t0, 0(%2)\n\t"                                              \
+      :                                                                \
+      : "r" (input1), "r" (input2), "r" (output)                       \
+      : "t0", "t1", "t2", "memory"                                     \
+   );                                                                  \
+}
+
+DO_MIPS32R6__LSA(LSA1, 1)
+DO_MIPS32R6__LSA(LSA2, 2)
+DO_MIPS32R6__LSA(LSA3, 3)
+DO_MIPS32R6__LSA(LSA4, 4)
+
 DO_MIPS32R6__RD__RS_RT(MUL, mul)
 DO_MIPS32R6__RD__RS_RT(MUH, muh)
 DO_MIPS32R6__RD__RS_RT(MULU, mulu)
tests/tcg/mipsel/test_mips32r6_shift.c +10 -0
index 6828e90dd8af..c2d0e61137d0 100644
@@ -21,6 +21,12 @@ static uint32_t ref_srav(uint32_t a, uint32_t b)
     return (uint32_t)((int32_t)a >> (b & 31));
 }
 
+/* LSA: shift rs left by 1..4, then add rt. */
+static uint32_t ref_lsa1(uint32_t a, uint32_t b) { return (a << 1) + b; }
+static uint32_t ref_lsa2(uint32_t a, uint32_t b) { return (a << 2) + b; }
+static uint32_t ref_lsa3(uint32_t a, uint32_t b) { return (a << 3) + b; }
+static uint32_t ref_lsa4(uint32_t a, uint32_t b) { return (a << 4) + b; }
+
 static int check_one(const char *name, binary_op_32 op, ref_op_32 ref,
                      uint32_t a, uint32_t b)
 {
@@ -66,6 +72,10 @@ int main(void)
     run("SLLV", do_mips32r6_SLLV, ref_sllv);
     run("SRLV", do_mips32r6_SRLV, ref_srlv);
     run("SRAV", do_mips32r6_SRAV, ref_srav);
+    run("LSA1", do_mips32r6_LSA1, ref_lsa1);
+    run("LSA2", do_mips32r6_LSA2, ref_lsa2);
+    run("LSA3", do_mips32r6_LSA3, ref_lsa3);
+    run("LSA4", do_mips32r6_LSA4, ref_lsa4);
 
     return tap_done();
 }
Signature · 1 line
2.55.0
#13 lore raw

PATCH v2 11/12 tests/tcg/mipsel: Test MIPS32R6 BALC

In reply to Philippe Mathieu-Daudé

Add a branch group, starting with BALC.

---
 tests/tcg/mipsel/test_mips32r6_branch.c | 53 +++++++++++++++++++++++++
 tests/tcg/mipsel/meson.build            |  1 +
 2 files changed, 54 insertions(+)
 create mode 100644 tests/tcg/mipsel/test_mips32r6_branch.c
tests/tcg/mipsel/test_mips32r6_branch.c new file +53 -0
new file mode 100644
index 000000000000..83580fcbedac
@@ -0,0 +1,53 @@
+/*
+ * MIPS32R6 tests: compact branches and jumps instructions
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <stdint.h>
+
+#include "../include/tap.h"
+
+/*
+ * BALC: branch and link, no delay slot. The callee records $ra and returns;
+ * $ra must be the address of the instruction following BALC (label 2).
+ */
+static int test_balc(void)
+{
+    uint32_t seen, expected;
+
+    __asm__ volatile (
+        ".set push\n\t"
+        ".set noreorder\n\t"
+        "move %0, $zero\n\t"
+        "balc 1f\n\t"
+        "2: bc 3f\n\t"
+        "1: move %0, $ra\n\t"
+        "jrc $ra\n\t"
+        "3: lapc %1, 2b\n\t"
+        ".set pop\n\t"
+        : "=&r" (seen), "=&r" (expected)
+        :
+        : "ra");
+
+    if (seen != expected) {
+        TAP_INFO("BALC: ra 0x%08x expected 0x%08x", seen, expected);
+    }
+    return seen != expected;
+}
+
+static int run(const char *name, int (*test)(void))
+{
+    int ret = test();
+
+    tap_report(!ret, "MIPS32R6 branch %s", name);
+    return ret;
+}
+
+int main(void)
+{
+    TAP_START();
+    run("BALC", test_balc);
+
+    return tap_done();
+}
tests/tcg/mipsel/meson.build +1 -0
index a7af2f16192f..fc27a4f6eb96 100644
@@ -68,6 +68,7 @@ tests = []
 
 tests_mips32r6 = [
   'test_mips32r6_bitops.c',
+  'test_mips32r6_branch.c',
   'test_mips32r6_logic.c',
   'test_mips32r6_multiply.c',
   'test_mips32r6_pcrel.c',
Signature · 1 line
2.55.0
#14 lore raw

PATCH v2 12/12 tests/tcg/mipsel: Test MIPS32R6 JIALC and JIC

In reply to Philippe Mathieu-Daudé

Now test JI[AL]C.

---
 tests/tcg/mipsel/test_mips32r6_branch.c | 71 +++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
tests/tcg/mipsel/test_mips32r6_branch.c +71 -0
index 83580fcbedac..3c0746c0e028 100644
@@ -36,6 +36,75 @@ static int test_balc(void)
     return seen != expected;
 }
 
+/* JIALC rt, offset: call to GPR[rt] + offset, link in $ra. */
+#define JIALC(bias, off, seen, expected, tmp)                           \
+    __asm__ volatile (                                                  \
+        ".set push\n\t"                                                 \
+        ".set noreorder\n\t"                                            \
+        "move %0, $zero\n\t"                                            \
+        "lapc %2, 1f\n\t"                                               \
+        "addiu %2, %2, " #bias "\n\t"                                   \
+        "jialc %2, " #off "\n\t"                                        \
+        "2: bc 3f\n\t"                                                  \
+        "1: move %0, $ra\n\t"                                           \
+        "jrc $ra\n\t"                                                   \
+        "3: lapc %1, 2b\n\t"                                            \
+        ".set pop\n\t"                                                  \
+        : "=&r" (seen), "=&r" (expected), "=&r" (tmp)                   \
+        :                                                               \
+        : "ra")
+
+static int test_jialc(void)
+{
+    uint32_t seen, expected, tmp;
+    int ret = 0;
+
+    JIALC(0, 0, seen, expected, tmp);
+    ret |= seen != expected;
+    JIALC(-8, 8, seen, expected, tmp);
+    ret |= seen != expected;
+    JIALC(8, -8, seen, expected, tmp);
+    ret |= seen != expected;
+    if (ret) {
+        TAP_INFO("JIALC: last ra 0x%08x expected 0x%08x", seen, expected);
+    }
+    return ret;
+}
+
+/* JIC rt, offset: jump to GPR[rt] + offset, no link ($ra unchanged). */
+#define JIC(bias, off, res, ra_before, ra_after, tmp)                   \
+    __asm__ volatile (                                                  \
+        ".set push\n\t"                                                 \
+        ".set noreorder\n\t"                                            \
+        "move %0, $zero\n\t"                                            \
+        "move %1, $ra\n\t"                                              \
+        "lapc %3, 1f\n\t"                                               \
+        "addiu %3, %3, " #bias "\n\t"                                   \
+        "jic %3, " #off "\n\t"                                          \
+        "addiu %0, %0, 2\n\t"                                           \
+        "1: addiu %0, %0, 1\n\t"                                        \
+        "move %2, $ra\n\t"                                              \
+        ".set pop\n\t"                                                  \
+        : "=&r" (res), "=&r" (ra_before), "=&r" (ra_after), "=&r" (tmp))
+
+static int test_jic(void)
+{
+    uint32_t res, ra_before, ra_after, tmp;
+    int ret = 0;
+
+    JIC(0, 0, res, ra_before, ra_after, tmp);
+    ret |= res != 1 || ra_before != ra_after;
+    JIC(-4, 4, res, ra_before, ra_after, tmp);
+    ret |= res != 1 || ra_before != ra_after;
+    JIC(4, -4, res, ra_before, ra_after, tmp);
+    ret |= res != 1 || ra_before != ra_after;
+    if (ret) {
+        TAP_INFO("JIC: last res %u (expected 1) ra 0x%08x -> 0x%08x",
+                 res, ra_before, ra_after);
+    }
+    return ret;
+}
+
 static int run(const char *name, int (*test)(void))
 {
     int ret = test();
@@ -48,6 +117,8 @@ int main(void)
 {
     TAP_START();
     run("BALC", test_balc);
+    run("JIALC", test_jialc);
+    run("JIC", test_jic);
 
     return tap_done();
 }
Signature · 1 line
2.55.0
Reviewed-by on the v2 series
#15 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 36 lines · Philippe Mathieu-Daudé

v2:
- Use Debian toolchain instead of Bootlin (pbo)
- Convert to TAP

v1:
- Include Bootlin mips32r6el toolchain in debian-all-test container
- Wire it to meson
- Cover all the 32-bit opcodes tested in MIPS64 Rel6 (using TAP)

Based-on: <[email protected]>

Philippe Mathieu-Daudé (12):
tests/docker: Add the mips32r6el toolchain on Debian cross container
meson: Add the tcg_tests_cross_cc/cflags options for mips32r6el tests/tcg/mipsel: Add MIPS32R6 logic tests tests/tcg/mipsel: Add MIPS32R6 shift tests tests/tcg/mipsel: Add MIPS32R6 bit operation tests tests/tcg/mipsel: Add MIPS32R6 multiply tests tests/tcg/mipsel: Add MIPS32R6 PC-relative tests tests/tcg/mipsel: Test MIPS32R6 SELEQZ and SELNEZ tests/tcg/mipsel: Test MIPS32R6 DIV, MOD, DIVU and MODU tests/tcg/mipsel: Test MIPS32R6 LSA
tests/tcg/mipsel: Test MIPS32R6 BALC
tests/tcg/mipsel: Test MIPS32R6 JIALC and JIC

 tests/tcg/mips/include/wrappers_mips32r6.h    |  91 +++++++++++++
 tests/tcg/mipsel/test_mips32r6_bitops.c       |  79 +++++++++++
 tests/tcg/mipsel/test_mips32r6_branch.c       | 124 ++++++++++++++++++
 tests/tcg/mipsel/test_mips32r6_logic.c        |  65 +++++++++
 tests/tcg/mipsel/test_mips32r6_multiply.c     | 104 +++++++++++++++
 tests/tcg/mipsel/test_mips32r6_pcrel.c        |  88 +++++++++++++
 tests/tcg/mipsel/test_mips32r6_shift.c        |  81 ++++++++++++
 .../dockerfiles/debian-all-test-cross.docker  |   3 +
 meson_options.txt                             |   4 +
 scripts/meson-buildoptions.sh                 |   2 +
 tests/tcg/mipsel/meson.build                  |  34 +++++
Quoted 9 lines
 11 files changed, 675 insertions(+)
 create mode 100644 tests/tcg/mips/include/wrappers_mips32r6.h
 create mode 100644 tests/tcg/mipsel/test_mips32r6_bitops.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_branch.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_logic.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_multiply.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_pcrel.c
 create mode 100644 tests/tcg/mipsel/test_mips32r6_shift.c

For series:

Just remove the binutils dep in dockerfile, as I think it's not mandatory to compile the tests.

Regards,
Pierrick