On 11/26/24 08:00, Philippe Mathieu-Daudé wrote:
Decode the destination register using the xlat() helper.

Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
  target/mips/tcg/mips16e_16.decode       |  8 ++++++++
  target/mips/tcg/mips16e_32.decode       |  9 +++++++++
  target/mips/tcg/mips16e_translate.c     | 14 ++++++++++++++
  target/mips/tcg/mips16e_translate.c.inc | 11 -----------
  4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/target/mips/tcg/mips16e_16.decode 
b/target/mips/tcg/mips16e_16.decode
index 82586493f68..bae7bfbb522 100644
--- a/target/mips/tcg/mips16e_16.decode
+++ b/target/mips/tcg/mips16e_16.decode
@@ -7,3 +7,11 @@
  # Reference: MIPS Architecture for Programmers, Volume IV-a
  #            The MIPS16e Application Specific Extension
  #            (Document Number: MD00076)
+
+&rd_imm         rd imm
+
+%xlat_rx8       8:3  !function=xlat
+
+@ri             ..... ... imm:8             &rd_imm   rd=%xlat_rx8

mips16e is decent enough to name its instruction formats -- this one is "I8". You'd do well to use those names.


+
+LI              01101 ... ........          @ri
diff --git a/target/mips/tcg/mips16e_32.decode 
b/target/mips/tcg/mips16e_32.decode
index fc429049e18..248ee95706d 100644
--- a/target/mips/tcg/mips16e_32.decode
+++ b/target/mips/tcg/mips16e_32.decode
@@ -7,3 +7,12 @@
  # Reference: MIPS Architecture for Programmers, Volume IV-a
  #            The MIPS16e Application Specific Extension
  #            (Document Number: MD00076)
+
+&rd_imm         rd imm                                          !extern
+
+%immx           0:5 21:6 16:5

The bits are in reverse order.

+%xlat_rx8       8:3  !function=xlat
+
+@ri             ..... ...... ..... ..... ... ... .....          &rd_imm 
rd=%xlat_rx8 imm=%immx

The format is "EXT-I8", though there appear to be variants where the immediate is signed (ADDIU) or unsigned (LI).

@@ -9,6 +9,20 @@
  #include "qemu/osdep.h"
  #include "translate.h"
+static inline int xlat(DisasContext *ctx, int x)
+{
+  static const int map[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
+
+  return map[x];
+}

Don't mark inline.

+
  /* Include the auto-generated decoders.  */
  #include "decode-mips16e_16.c.inc"
  #include "decode-mips16e_32.c.inc"
+
+static bool trans_LI(DisasContext *ctx, arg_rd_imm *a)
+{
+    gen_li(ctx, a->rd, a->imm);
+
+    return true;
+}

We nearly have the right set of decodetree options to allow these trans_* functions to be shared:

    --translate=trans

which will drop the 'static'. But we do not currently have an option to emit a separate header with all of the declarations. That should be trivial.


r~

Reply via email to