Skip to contentSkip to conversation

target/mips: Convert nanoMIPS LSA opcode to decodetree

PATCH Superseded Philippe Mathieu-Daudé 3 participants 7 messages Nov 11, 2024 – Nov 12, 2024 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover target/mips: Convert nanoMIPS LSA opcode to decodetree

Yet another 2 patches extracted from an old branch I'm rebasing. Trivial decodetree conversion of LSA, however this introduce the basis to convert nanoMIPS opcodes.

Philippe Mathieu-Daudé (2):
target/mips: Introduce decode tree bindings for nanoMIPS ISA target/mips: Convert nanoMIPS LSA opcode to decodetree

 target/mips/tcg/translate.h              |  2 ++
 target/mips/tcg/nanomips16.decode        |  8 ++++++++
 target/mips/tcg/nanomips32.decode        | 16 +++++++++++++++
 target/mips/tcg/nanomips_translate.c     | 26 ++++++++++++++++++++++++
 target/mips/tcg/nanomips_translate.c.inc | 16 +++++++--------
 target/mips/tcg/meson.build              |  3 +++
 6 files changed, 62 insertions(+), 9 deletions(-)
 create mode 100644 target/mips/tcg/nanomips16.decode
 create mode 100644 target/mips/tcg/nanomips32.decode
 create mode 100644 target/mips/tcg/nanomips_translate.c
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/2 target/mips: Introduce decode tree bindings for nanoMIPS ISA

From: Philippe Mathieu-Daudé <[email protected]>

Introduce the nanoMIPS decodetree configs for the 16-bit and 32-bit instructions.

---
 target/mips/tcg/translate.h              |  2 ++
 target/mips/tcg/nanomips16.decode        |  8 ++++++++
 target/mips/tcg/nanomips32.decode        |  8 ++++++++
 target/mips/tcg/nanomips_translate.c     | 14 ++++++++++++++
 target/mips/tcg/nanomips_translate.c.inc |  7 +++++++
 target/mips/tcg/meson.build              |  3 +++
 6 files changed, 42 insertions(+)
 create mode 100644 target/mips/tcg/nanomips16.decode
 create mode 100644 target/mips/tcg/nanomips32.decode
 create mode 100644 target/mips/tcg/nanomips_translate.c
target/mips/tcg/translate.h +2 -0
index a65ab4a747..f93bceb82a 100644
@@ -222,6 +222,8 @@ bool decode_ase_mxu(DisasContext *ctx, uint32_t insn);
 bool decode_64bit_enabled(DisasContext *ctx);
 
 /* decodetree generated */
+bool decode_isa_nanomips16(DisasContext *ctx, uint16_t insn);
+bool decode_isa_nanomips32(DisasContext *ctx, uint32_t insn);
 bool decode_isa_rel6(DisasContext *ctx, uint32_t insn);
 bool decode_ase_msa(DisasContext *ctx, uint32_t insn);
 bool decode_ext_txx9(DisasContext *ctx, uint32_t insn);
target/mips/tcg/nanomips16.decode new file +8 -0
new file mode 100644
index 0000000000..81fdc68e98
@@ -0,0 +1,8 @@
+# nanoMIPS32 16-bit instruction set extensions
+#
+# Copyright (C) 2021  Philippe Mathieu-Daudé
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# Reference: nanoMIPS32 Instruction Set Technical Reference Manual
+#            (Document Number: MD01247)
target/mips/tcg/nanomips32.decode new file +8 -0
new file mode 100644
index 0000000000..9cecf1e13d
@@ -0,0 +1,8 @@
+# nanoMIPS32 32-bit instruction set extensions
+#
+# Copyright (C) 2021  Philippe Mathieu-Daudé
+#
+# SPDX-License-Identifier: LGPL-2.1-or-later
+#
+# Reference: nanoMIPS32 Instruction Set Technical Reference Manual
+#            (Document Number: MD01247)
target/mips/tcg/nanomips_translate.c new file +14 -0
new file mode 100644
index 0000000000..c148c13ed9
@@ -0,0 +1,14 @@
+/*
+ * MIPS emulation for QEMU - nanoMIPS translation routines
+ *
+ * Copyright (c) 2021 Philippe Mathieu-Daudé <[email protected]>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "translate.h"
+
+/* Include the auto-generated decoders.  */
+#include "decode-nanomips16.c.inc"
+#include "decode-nanomips32.c.inc"
target/mips/tcg/nanomips_translate.c.inc +7 -0
index 1e274143bb..e401b92bfd 100644
@@ -4482,6 +4482,13 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx)
         return 2;
     }
 
+    if (decode_isa_nanomips16(ctx, ctx->opcode)) {
+        return 2;
+    }
+    if (decode_isa_nanomips32(ctx, ctx->opcode)) {
+        return 4;
+    }
+
     op = extract32(ctx->opcode, 10, 6);
     switch (op) {
     case NM_P16_MV:
target/mips/tcg/meson.build +3 -0
index 7b18e6c4c8..c05f3c0649 100644
@@ -1,5 +1,7 @@
 gen = [
   decodetree.process('rel6.decode', extra_args: ['--decode=decode_isa_rel6']),
+  decodetree.process('nanomips16.decode', extra_args: ['--decode=decode_isa_nanomips16', '--insnwidth=16']),
+  decodetree.process('nanomips32.decode', extra_args: ['--decode=decode_isa_nanomips32']),
   decodetree.process('msa.decode', extra_args: '--decode=decode_ase_msa'),
   decodetree.process('tx79.decode', extra_args: '--static-decode=decode_tx79'),
   decodetree.process('vr54xx.decode', extra_args: '--decode=decode_ext_vr54xx'),
@@ -18,6 +20,7 @@ mips_ss.add(files(
   'lmmi_helper.c',
   'msa_helper.c',
   'msa_translate.c',
+  'nanomips_translate.c',
   'op_helper.c',
   'rel6_translate.c',
   'translate.c',
Signature · 1 line
2.45.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] target/mips: Introduce decode tree bindings for nanoMIPS ISA

Quoted 15 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé<[email protected]>

Introduce the nanoMIPS decodetree configs for the 16-bit and 32-bit instructions.

---
  target/mips/tcg/translate.h              |  2 ++
  target/mips/tcg/nanomips16.decode        |  8 ++++++++
  target/mips/tcg/nanomips32.decode        |  8 ++++++++
  target/mips/tcg/nanomips_translate.c     | 14 ++++++++++++++
  target/mips/tcg/nanomips_translate.c.inc |  7 +++++++
  target/mips/tcg/meson.build              |  3 +++
  6 files changed, 42 insertions(+)
Quoted 3 lines

create mode 100644 target/mips/tcg/nanomips16.decode create mode 100644 target/mips/tcg/nanomips32.decode create mode 100644 target/mips/tcg/nanomips_translate.c

r~

#3 lore raw

PATCH 2/2 target/mips: Convert nanoMIPS LSA opcode to decodetree

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Simply call the generic gen_lsa() helper, taking care to substract 1 to the shift field.

---
 target/mips/tcg/nanomips32.decode        |  8 ++++++++
 target/mips/tcg/nanomips_translate.c     | 12 ++++++++++++
 target/mips/tcg/nanomips_translate.c.inc |  9 ---------
 3 files changed, 20 insertions(+), 9 deletions(-)
target/mips/tcg/nanomips32.decode +8 -0
index 9cecf1e13d..11bf5cd6c4 100644
@@ -6,3 +6,11 @@
 #
 # Reference: nanoMIPS32 Instruction Set Technical Reference Manual
 #            (Document Number: MD01247)
+
+&r                  rs rt rd sa
+
+%lsa_u2             9:2  !function=minus_1
+
+@lsa                ...... rt:5 rs:5 rd:5 .. --- ... ...    &r sa=%lsa_u2
+
+LSA                 001000 ..... ..... ..... .. ... 001 111 @lsa
target/mips/tcg/nanomips_translate.c +12 -0
index c148c13ed9..9a6db4a828 100644
@@ -9,6 +9,18 @@
 #include "qemu/osdep.h"
 #include "translate.h"
 
+static inline int minus_1(DisasContext *ctx, int x)
+{
+    return x - 1;
+}
+
 /* Include the auto-generated decoders.  */
 #include "decode-nanomips16.c.inc"
 #include "decode-nanomips32.c.inc"
+
+static bool trans_LSA(DisasContext *ctx, arg_r *a)
+{
+    gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa);
+
+    return true;
+}
target/mips/tcg/nanomips_translate.c.inc +0 -9
index e401b92bfd..0e012ab3d0 100644
@@ -399,7 +399,6 @@ enum {
 /* POOL32A7 instruction pool */
 enum {
     NM_P_LSX        = 0x00,
-    NM_LSA          = 0x01,
     NM_EXTW         = 0x03,
     NM_POOL32AXF    = 0x07,
 };
@@ -3625,14 +3624,6 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
             case NM_P_LSX:
                 gen_p_lsx(ctx, rd, rs, rt);
                 break;
-            case NM_LSA:
-                /*
-                 * In nanoMIPS, the shift field directly encodes the shift
-                 * amount, meaning that the supported shift values are in
-                 * the range 0 to 3 (instead of 1 to 4 in MIPSR6).
-                 */
-                gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2) - 1);
-                break;
             case NM_EXTW:
                 gen_ext(ctx, 32, rd, rs, rt, extract32(ctx->opcode, 6, 5));
                 break;
Signature · 1 line
2.45.2
#4 lore raw
Quoted 39 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Simply call the generic gen_lsa() helper, taking care to substract 1 to the shift field.

---
  target/mips/tcg/nanomips32.decode        |  8 ++++++++
  target/mips/tcg/nanomips_translate.c     | 12 ++++++++++++
  target/mips/tcg/nanomips_translate.c.inc |  9 ---------
  3 files changed, 20 insertions(+), 9 deletions(-)
target/mips/tcg/nanomips32.decode +8 -0
index 9cecf1e13d..11bf5cd6c4 100644
@@ -6,3 +6,11 @@
  #
  # Reference: nanoMIPS32 Instruction Set Technical Reference Manual
  #            (Document Number: MD01247)
+
+&r                  rs rt rd sa
+
+%lsa_u2             9:2  !function=minus_1
+
+@lsa                ...... rt:5 rs:5 rd:5 .. --- ... ...    &r sa=%lsa_u2
+
+LSA                 001000 ..... ..... ..... .. ... 001 111 @lsa
target/mips/tcg/nanomips_translate.c +2 -0
index c148c13ed9..9a6db4a828 100644
@@ -9,6 +9,18 @@
  #include "qemu/osdep.h"
  #include "translate.h"
 
+static inline int minus_1(DisasContext *ctx, int x)
+{

target/mips/tcg/nanomips_translate.c line 23

Quoted 10 lines
target/mips/tcg/nanomips_translate.c +7 -0
+    return x - 1;
+}
+
  /* Include the auto-generated decoders.  */
  #include "decode-nanomips16.c.inc"
  #include "decode-nanomips32.c.inc"
+
+static bool trans_LSA(DisasContext *ctx, arg_r *a)
+{
+    gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa);

I think decoding shift-amount - 1 is misleading.
Surely it would be better for other callers to pass extract(...) + 1?

r~

#5 lore raw
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Simply call the generic gen_lsa() helper, taking care to substract 1 to the shift field.

---
  target/mips/tcg/nanomips32.decode        |  8 ++++++++ target/mips/tcg/nanomips_translate.c     | 12 ++++++++++++ target/mips/tcg/nanomips_translate.c.inc |  9 ---------

  3 files changed, 20 insertions(+), 9 deletions(-)
target/mips/tcg/nanomips_translate.c +5 -0
index c148c13ed9..9a6db4a828 100644
@@ -9,6 +9,18 @@
   #include "qemu/osdep.h"
   #include "translate.h"
+static inline int minus_1(DisasContext *ctx, int x)
+{
+    return x - 1;
+}
+
   /* Include the auto-generated decoders.  */
Quoted 8 lines

target/mips/tcg/nanomips_translate.c line 23

Quoted 6 lines
target/mips/tcg/nanomips_translate.c +4 -0
   #include "decode-nanomips16.c.inc"
   #include "decode-nanomips32.c.inc"
+
+static bool trans_LSA(DisasContext *ctx, arg_r *a)
+{
+    gen_lsa(ctx, a->rd, a->rt, a->rs, a->sa);

I think decoding shift-amount - 1 is misleading.

Yeah I thought the same while rebasing ...

Quoted 1 line

Surely it would be better for other callers to pass extract(...) + 1?

... but was too lazy to do the changes :p

Quoted 4 lines

r~

Reviewed-by on the v1 series
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines

Yet another 2 patches extracted from an old branch I'm rebasing. Trivial decodetree conversion of LSA, however this introduce the basis to convert nanoMIPS opcodes.

Philippe Mathieu-Daudé (2):
target/mips: Introduce decode tree bindings for nanoMIPS ISA target/mips: Convert nanoMIPS LSA opcode to decodetree

For the entire series: