Skip to contentSkip to conversation

riscv decodetree followup

PATCH Superseded Richard Henderson 3 participants 28 messages Oct 23, 2018 – Oct 24, 2018 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover riscv decodetree followup

The first patch is the promised change to argument sets to allow them to be shared between two decoders.

Then I set about trying to use this... and ran into some other interesting problems. The first of which is that

  bool trans_add(DecodeContext *ctx, struct arg_r *a, uint32_t insn);
  bool trans_add(DecodeContext *ctx, struct arg_r *a, uint16_t insn);

conflicts.

I think the best solution is to remove the insn argument to the trans_* functions. When this goes in for real, this will be a big patch that touches lots of lines in target/arm and target/openrisc. For now, I'm ignoring that and only building riscv{32,64}-linux-user.

Second, it occured to me that if we smoosh several files together at build time, we don't have to play silly games with trying to decode for riscv32 and riscv64 at the same time. The last patch is, I think, a big improvement in that.

Full tree at https://github.com/rth7680/qemu.git riscv-dt-rth.

r~

Richard Henderson (7):
decodetree: Add !extern flag to argument sets
decodetree: Remove "insn" argument from trans_* expanders target/riscv: Update for decodetree insn argument change target/riscv: Rename some argument sets in insn32.decode target/riscv: Convert @cs_2 insns to share translation functions target/riscv: Convert @cl_d, @cl_w, @cs_d, @cs_w insns target/riscv: Splice decodetree inputs for riscv32 vs riscv64

 .../riscv/insn_trans/trans_privileged.inc.c   |  19 +-
 target/riscv/insn_trans/trans_rva.inc.c       |  90 ++------
 target/riscv/insn_trans/trans_rvc.inc.c       | 215 ++++--------------
 target/riscv/insn_trans/trans_rvd.inc.c       |  90 +++-----
 target/riscv/insn_trans/trans_rvf.inc.c       |  78 +++----
 target/riscv/insn_trans/trans_rvi.inc.c       | 165 ++++++--------
 target/riscv/insn_trans/trans_rvm.inc.c       |  48 ++--
 target/riscv/translate.c                      |  30 ++-
 scripts/decodetree.py                         |  39 ++--
 target/riscv/Makefile.objs                    |  23 +-
 target/riscv/insn16-32.decode                 |  31 +++
 target/riscv/insn16-64.decode                 |  33 +++
 target/riscv/insn16.decode                    |  55 ++---
 target/riscv/insn32.decode                    |  68 +-----
 target/riscv/insn64.decode                    |  71 ++++++
 15 files changed, 450 insertions(+), 605 deletions(-)
 create mode 100644 target/riscv/insn16-32.decode
 create mode 100644 target/riscv/insn16-64.decode
 create mode 100644 target/riscv/insn64.decode
Signature · 1 line
2.17.2
#1 lore raw

PATCH 1/7 decodetree: Add !extern flag to argument sets

Allow argument sets to be shared between two decoders by avoiding a re-declaration error. Make sure that anonymous argument sets have unique names.

---
 scripts/decodetree.py | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
scripts/decodetree.py +23 -11
index 277f9a9bba..a9b10452ef 100755
@@ -63,13 +63,16 @@
 #
 # *** Argument set syntax:
 #
-# args_def    := '&' identifier ( args_elt )+
+# args_def    := '&' identifier ( args_elt )+ ( !extern )?
 # args_elt    := identifier
 #
 # Each args_elt defines an argument within the argument set.
 # Each argument set will be rendered as a C structure "arg_$name"
 # with each of the fields being one of the member arguments.
 #
+# If !extern is specified, the backing structure is assumed to
+# have been already declared, typically via a second decoder.
+#
 # Argument set examples:
 #
 #   &reg3       ra rb rc
@@ -169,6 +172,7 @@ input_file = ''
 output_file = None
 output_fd = None
 insntype = 'uint32_t'
+decode_function = 'decode'
 
 re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
 
@@ -394,8 +398,9 @@ class FunctionField:
 
 class Arguments:
     """Class representing the extracted fields of a format"""
-    def __init__(self, nm, flds):
+    def __init__(self, nm, flds, extern):
         self.name = nm
+        self.extern = extern
         self.fields = sorted(flds)
 
     def __str__(self):
@@ -405,10 +410,11 @@ class Arguments:
         return 'arg_' + self.name
 
     def output_def(self):
-        output('typedef struct {\n')
-        for n in self.fields:
-            output('    int ', n, ';\n')
-        output('} ', self.struct_name(), ';\n\n')
+        if not self.extern:
+            output('typedef struct {\n')
+            for n in self.fields:
+                output('    int ', n, ';\n')
+            output('} ', self.struct_name(), ';\n\n')
 # end Arguments
 
 
@@ -542,7 +548,11 @@ def parse_arguments(lineno, name, toks):
     global re_ident
 
     flds = []
+    extern = False
     for t in toks:
+        if re_fullmatch('!extern', t):
+            extern = True
+            continue
         if not re_fullmatch(re_ident, t):
             error(lineno, 'invalid argument set token "{0}"'.format(t))
         if t in flds:
@@ -551,7 +561,7 @@ def parse_arguments(lineno, name, toks):
 
     if name in arguments:
         error(lineno, 'duplicate argument set', name)
-    arguments[name] = Arguments(name, flds)
+    arguments[name] = Arguments(name, flds, extern)
 # end parse_arguments
 
 
@@ -575,13 +585,14 @@ def add_field_byname(lineno, flds, new_name, old_name):
 
 def infer_argument_set(flds):
     global arguments
+    global decode_function
 
     for arg in arguments.values():
         if eq_fields_for_args(flds, arg.fields):
             return arg
 
-    name = str(len(arguments))
-    arg = Arguments(name, flds.keys())
+    name = decode_function + str(len(arguments))
+    arg = Arguments(name, flds.keys(), False)
     arguments[name] = arg
     return arg
 
@@ -589,6 +600,7 @@ def infer_argument_set(flds):
 def infer_format(arg, fieldmask, flds):
     global arguments
     global formats
+    global decode_function
 
     const_flds = {}
     var_flds = {}
@@ -608,7 +620,7 @@ def infer_format(arg, fieldmask, flds):
             continue
         return (fmt, const_flds)
 
-    name = 'Fmt_' + str(len(formats))
+    name = decode_function + '_Fmt_' + str(len(formats))
     if not arg:
         arg = infer_argument_set(flds)
 
@@ -973,8 +985,8 @@ def main():
     global insnwidth
     global insntype
     global insnmask
+    global decode_function
 
-    decode_function = 'decode'
     decode_scope = 'static '
 
     long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']
Signature · 1 line
2.17.2
Reviewed-by on v1 1/7
#2 lore raw

Re: [Qemu-devel] [PATCH 1/7] decodetree: Add !extern flag to argument sets

Quoted 9 lines · Richard Henderson

Allow argument sets to be shared between two decoders by avoiding a re-declaration error. Make sure that anonymous argument sets have unique names.

---
  scripts/decodetree.py | 34 +++++++++++++++++++++++-----------
  1 file changed, 23 insertions(+), 11 deletions(-)

Cheers,

Bastian

Reviewed-by on v1 1/7
#3 lore raw

Re: [Qemu-devel] [PATCH 1/7] decodetree: Add !extern flag to argument sets

In reply to Richard Henderson
Quoted 67 lines · Richard Henderson

Allow argument sets to be shared between two decoders by avoiding a re-declaration error. Make sure that anonymous argument sets have unique names.

---
  scripts/decodetree.py | 34 +++++++++++++++++++++++-----------
  1 file changed, 23 insertions(+), 11 deletions(-)
scripts/decodetree.py +12 -6
index 277f9a9bba..a9b10452ef 100755
@@ -63,13 +63,16 @@
  #
  # *** Argument set syntax:
  #
-# args_def    := '&' identifier ( args_elt )+
+# args_def    := '&' identifier ( args_elt )+ ( !extern )?
  # args_elt    := identifier
  #
  # Each args_elt defines an argument within the argument set.
  # Each argument set will be rendered as a C structure "arg_$name"
  # with each of the fields being one of the member arguments.
  #
+# If !extern is specified, the backing structure is assumed to
+# have been already declared, typically via a second decoder.
+#
  # Argument set examples:
  #
  #   &reg3       ra rb rc
@@ -169,6 +172,7 @@ input_file = ''
  output_file = None
  output_fd = None
  insntype = 'uint32_t'
+decode_function = 'decode'
 
  re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
 
@@ -394,8 +398,9 @@ class FunctionField:
 
  class Arguments:
      """Class representing the extracted fields of a format"""
-    def __init__(self, nm, flds):
+    def __init__(self, nm, flds, extern):
          self.name = nm
+        self.extern = extern
          self.fields = sorted(flds)
 
      def __str__(self):
@@ -405,10 +410,11 @@ class Arguments:
          return 'arg_' + self.name
 
      def output_def(self):
-        output('typedef struct {\n')
-        for n in self.fields:
-            output('    int ', n, ';\n')
-        output('} ', self.struct_name(), ';\n\n')
+        if not self.extern:
+            output('typedef struct {\n')
+            for n in self.fields:
+                output('    int ', n, ';\n')
+            output('} ', self.struct_name(), ';\n\n')
  # end Arguments
 
 

scripts/decodetree.py def parse_arguments(lineno, name, toks): · line 554

Quoted 7 lines
scripts/decodetree.py +3 -0
@@ -542,7 +548,11 @@ def parse_arguments(lineno, name, toks):
      global re_ident
 
      flds = []
+    extern = False
      for t in toks:
+        if re_fullmatch('!extern', t):
+            extern = True

It looks odd to match a negative form then use a positive one.

Why not simply use 'extern'?

Regardless,

Quoted 58 lines
scripts/decodetree.py +8 -5
+            continue
          if not re_fullmatch(re_ident, t):
              error(lineno, 'invalid argument set token "{0}"'.format(t))
          if t in flds:
@@ -551,7 +561,7 @@ def parse_arguments(lineno, name, toks):
 
      if name in arguments:
          error(lineno, 'duplicate argument set', name)
-    arguments[name] = Arguments(name, flds)
+    arguments[name] = Arguments(name, flds, extern)
  # end parse_arguments
 
 
@@ -575,13 +585,14 @@ def add_field_byname(lineno, flds, new_name, old_name):
 
  def infer_argument_set(flds):
      global arguments
+    global decode_function
 
      for arg in arguments.values():
          if eq_fields_for_args(flds, arg.fields):
              return arg
 
-    name = str(len(arguments))
-    arg = Arguments(name, flds.keys())
+    name = decode_function + str(len(arguments))
+    arg = Arguments(name, flds.keys(), False)
      arguments[name] = arg
      return arg
 
@@ -589,6 +600,7 @@ def infer_argument_set(flds):
  def infer_format(arg, fieldmask, flds):
      global arguments
      global formats
+    global decode_function
 
      const_flds = {}
      var_flds = {}
@@ -608,7 +620,7 @@ def infer_format(arg, fieldmask, flds):
              continue
          return (fmt, const_flds)
 
-    name = 'Fmt_' + str(len(formats))
+    name = decode_function + '_Fmt_' + str(len(formats))
      if not arg:
          arg = infer_argument_set(flds)
 
@@ -973,8 +985,8 @@ def main():
      global insnwidth
      global insntype
      global insnmask
+    global decode_function
 
-    decode_function = 'decode'
      decode_scope = 'static '
 
      long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=']
#4 lore raw

Re: [Qemu-devel] [PATCH 1/7] decodetree: Add !extern flag to argument sets

Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 2 lines

+        if re_fullmatch('!extern', t):
+            extern = True

It looks odd to match a negative form then use a positive one.

Why not simply use 'extern'?

"!" is an escape character here.
Just "escape" would be a field named "escape".

It follows existing similar syntax for !function=foo

r~

#5 lore raw

Re: [Qemu-devel] [PATCH 1/7] decodetree: Add !extern flag to argument sets

Quoted 4 lines · Richard Henderson
Quoted 3 lines · Philippe Mathieu-Daudé
Quoted 2 lines

+        if re_fullmatch('!extern', t):
+            extern = True

Quoted 8 lines
Quoted 3 lines

It looks odd to match a negative form then use a positive one.

Why not simply use 'extern'?

"!" is an escape character here.
Just "escape" would be a field named "escape".

It follows existing similar syntax for !function=foo

Oh OK!

Thanks,

Phil.

#6 lore raw

PATCH 2/7 decodetree: Remove "insn" argument from trans_* expanders

In reply to Richard Henderson

??? Needs simultaneous corresponding changes to all translators using decodetree.

---
 scripts/decodetree.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
scripts/decodetree.py +2 -3
index a9b10452ef..c0bb447095 100755
@@ -468,8 +468,7 @@ class Pattern(General):
         output('typedef ', self.base.base.struct_name(),
                ' arg_', self.name, ';\n')
         output(translate_scope, 'bool ', translate_prefix, '_', self.name,
-               '(DisasContext *ctx, arg_', self.name,
-               ' *a, ', insntype, ' insn);\n')
+               '(DisasContext *ctx, arg_', self.name, ' *a);\n')
 
     def output_code(self, i, extracted, outerbits, outermask):
         global translate_prefix
@@ -481,7 +480,7 @@ class Pattern(General):
         for n, f in self.fields.items():
             output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n')
         output(ind, 'return ', translate_prefix, '_', self.name,
-               '(ctx, &u.f_', arg, ', insn);\n')
+               '(ctx, &u.f_', arg, ');\n')
 # end Pattern
 
 
Signature · 1 line
2.17.2
#7 lore raw

Re: [Qemu-devel] [PATCH 2/7] decodetree: Remove "insn" argument from trans_* expanders

Quoted 6 lines · Richard Henderson

??? Needs simultaneous corresponding changes to all translators using decodetree.

---
  scripts/decodetree.py | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)

Was the only intend of the insn argument to be used for manual decoding in a trans_ function?

Cheers,

Bastian

#8 lore raw

Re: [Qemu-devel] [PATCH 2/7] decodetree: Remove "insn" argument from trans_* expanders

Quoted 10 lines · Bastian Koppelmann
Quoted 6 lines · Richard Henderson

??? Needs simultaneous corresponding changes to all translators using decodetree.
---
  scripts/decodetree.py | 5 ++---

  1 file changed, 2 insertions(+), 3 deletions(-)

Was the only intend of the insn argument to be used for manual decoding in a trans_ function?

I didn't quite know what it might be used for, and thought I was planning ahead. Now I see that it's probably counter-productive.

In particular, think of how you were calling the trans_foo functions yourself, passing along the uint16_t input to the uint32_t output. Which would have worked not at all had you actually been using it for decode within the insn32 code base.

r~

#9 lore raw

Re: [Qemu-devel] [PATCH 2/7] decodetree: Remove "insn" argument from trans_* expanders

Quoted 8 lines · Richard Henderson
Quoted 7 lines · Bastian Koppelmann
Quoted 6 lines · Richard Henderson

??? Needs simultaneous corresponding changes to all translators using decodetree.

---
   scripts/decodetree.py | 5 ++---
   1 file changed, 2 insertions(+), 3 deletions(-)
Quoted 4 lines
Quoted 2 lines

Was the only intend of the insn argument to be used for manual decoding in a trans_ function?

I didn't quite know what it might be used for, and thought I was planning ahead. Now I see that it's probably counter-productive.

Richard, can you pick up the first two patches together with the insn arg removal for openrisc and ARM, such that we don't break bisecting? I then squash the rest of the patches into my patch-set.

Cheers,

Bastian

#10 lore raw

Re: [Qemu-devel] [PATCH 2/7] decodetree: Remove "insn" argument from trans_* expanders

Quoted 3 lines · Bastian Koppelmann

Richard, can you pick up the first two patches together with the insn arg removal for openrisc and ARM, such that we don't break bisecting? I then squash the rest of the patches into my patch-set.

I've now pushed these two to a new branch off master:

https://github.com/rth7680/qemu.git decodetree

r~

#11 lore raw

Re: [Qemu-devel] [PATCH 2/7] decodetree: Remove "insn" argument from trans_* expanders

In reply to Richard Henderson
Quoted 9 lines · Richard Henderson
Quoted 8 lines · Bastian Koppelmann
Quoted 6 lines · Richard Henderson

??? Needs simultaneous corresponding changes to all translators using decodetree.

---
   scripts/decodetree.py | 5 ++---
   1 file changed, 2 insertions(+), 3 deletions(-)
Quoted 5 lines
Quoted 2 lines

Was the only intend of the insn argument to be used for manual decoding in a trans_ function?

I didn't quite know what it might be used for, and thought I was planning ahead. Now I see that it's probably counter-productive.

I agree.

Quoted 9 lines

In particular, think of how you were calling the trans_foo functions yourself, passing along the uint16_t input to the uint32_t output. Which would have worked not at all had you actually been using it for decode within the insn32 code base.

r~

#12 lore raw

PATCH 3/7 target/riscv: Update for decodetree insn argument change

In reply to Richard Henderson

??? Should be merged back into previous patches.
??? Additional changes required for compact mode.

---
 .../riscv/insn_trans/trans_privileged.inc.c   |  19 ++-
 target/riscv/insn_trans/trans_rva.inc.c       |  44 +++---
 target/riscv/insn_trans/trans_rvc.inc.c       | 148 +++++++++---------
 target/riscv/insn_trans/trans_rvd.inc.c       |  64 ++++----
 target/riscv/insn_trans/trans_rvf.inc.c       |  60 +++----
 target/riscv/insn_trans/trans_rvi.inc.c       | 114 +++++++-------
 target/riscv/insn_trans/trans_rvm.inc.c       |  26 +--
 7 files changed, 234 insertions(+), 241 deletions(-)
target/riscv/insn_trans/trans_privileged.inc.c +9 -10
index 9534adb025..999e7f0f9e 100644
@@ -18,7 +18,7 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-static bool trans_ecall(DisasContext *ctx, arg_ecall *a, uint32_t insn)
+static bool trans_ecall(DisasContext *ctx, arg_ecall *a)
 {
     /* always generates U-level ECALL, fixed in do_interrupt handler */
     generate_exception(ctx, RISCV_EXCP_U_ECALL);
@@ -27,7 +27,7 @@ static bool trans_ecall(DisasContext *ctx, arg_ecall *a, uint32_t insn)
     return true;
 }
 
-static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a, uint32_t insn)
+static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
 {
     generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
     tcg_gen_exit_tb(NULL, 0); /* no chaining */
@@ -35,13 +35,13 @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a, uint32_t insn)
     return true;
 }
 
-static bool trans_uret(DisasContext *ctx, arg_uret *a, uint32_t insn)
+static bool trans_uret(DisasContext *ctx, arg_uret *a)
 {
     gen_exception_illegal(ctx);
     return true;
 }
 
-static bool trans_sret(DisasContext *ctx, arg_sret *a, uint32_t insn)
+static bool trans_sret(DisasContext *ctx, arg_sret *a)
 {
 #ifndef CONFIG_USER_ONLY
     tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
@@ -59,13 +59,13 @@ static bool trans_sret(DisasContext *ctx, arg_sret *a, uint32_t insn)
 #endif
 }
 
-static bool trans_hret(DisasContext *ctx, arg_hret *a, uint32_t insn)
+static bool trans_hret(DisasContext *ctx, arg_hret *a)
 {
     gen_exception_illegal(ctx);
     return true;
 }
 
-static bool trans_mret(DisasContext *ctx, arg_mret *a, uint32_t insn)
+static bool trans_mret(DisasContext *ctx, arg_mret *a)
 {
 #ifndef CONFIG_USER_ONLY
     tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
@@ -78,7 +78,7 @@ static bool trans_mret(DisasContext *ctx, arg_mret *a, uint32_t insn)
 #endif
 }
 
-static bool trans_wfi(DisasContext *ctx, arg_wfi *a, uint32_t insn)
+static bool trans_wfi(DisasContext *ctx, arg_wfi *a)
 {
 #ifndef CONFIG_USER_ONLY
     tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn);
@@ -89,8 +89,7 @@ static bool trans_wfi(DisasContext *ctx, arg_wfi *a, uint32_t insn)
 #endif
 }
 
-static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a,
-                             uint32_t insn)
+static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a)
 {
 #ifndef CONFIG_USER_ONLY
     gen_helper_tlb_flush(cpu_env);
@@ -100,7 +99,7 @@ static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a,
 #endif
 }
 
-static bool trans_sfence_vm(DisasContext *ctx, arg_sfence_vm *a, uint32_t insn)
+static bool trans_sfence_vm(DisasContext *ctx, arg_sfence_vm *a)
 {
 #ifndef CONFIG_USER_ONLY
     gen_helper_tlb_flush(cpu_env);
target/riscv/insn_trans/trans_rva.inc.c +22 -22

154 lines not on this page · raw message

target/riscv/insn_trans/trans_rvc.inc.c +71 -77

359 lines not on this page · raw message

target/riscv/insn_trans/trans_rvd.inc.c +32 -32

256 lines not on this page · raw message

target/riscv/insn_trans/trans_rvf.inc.c +30 -30

240 lines not on this page · raw message

target/riscv/insn_trans/trans_rvi.inc.c +57 -57

407 lines not on this page · raw message

target/riscv/insn_trans/trans_rvm.inc.c +13 -13
index 0bc9b4347a..7809bcb187 100644
@@ -19,12 +19,12 @@
  */
 
 
-static bool trans_mul(DisasContext *ctx, arg_mul *a, uint32_t insn)
+static bool trans_mul(DisasContext *ctx, arg_mul *a)
 {
     return gen_arith(ctx, a, &tcg_gen_mul_tl);
 }
 
-static bool trans_mulh(DisasContext *ctx, arg_mulh *a, uint32_t insn)
+static bool trans_mulh(DisasContext *ctx, arg_mulh *a)
 {
     TCGv source1 = tcg_temp_new();
     TCGv source2 = tcg_temp_new();
@@ -39,12 +39,12 @@ static bool trans_mulh(DisasContext *ctx, arg_mulh *a, uint32_t insn)
     return true;
 }
 
-static bool trans_mulhsu(DisasContext *ctx, arg_mulhsu *a, uint32_t insn)
+static bool trans_mulhsu(DisasContext *ctx, arg_mulhsu *a)
 {
     return gen_arith(ctx, a, &gen_mulhsu);
 }
 
-static bool trans_mulhu(DisasContext *ctx, arg_mulhu *a, uint32_t insn)
+static bool trans_mulhu(DisasContext *ctx, arg_mulhu *a)
 {
     TCGv source1 = tcg_temp_new();
     TCGv source2 = tcg_temp_new();
@@ -59,27 +59,27 @@ static bool trans_mulhu(DisasContext *ctx, arg_mulhu *a, uint32_t insn)
     return true;
 }
 
-static bool trans_div(DisasContext *ctx, arg_div *a, uint32_t insn)
+static bool trans_div(DisasContext *ctx, arg_div *a)
 {
     return gen_arith(ctx, a, &gen_div);
 }
 
-static bool trans_divu(DisasContext *ctx, arg_divu *a, uint32_t insn)
+static bool trans_divu(DisasContext *ctx, arg_divu *a)
 {
     return gen_arith(ctx, a, &gen_divu);
 }
 
-static bool trans_rem(DisasContext *ctx, arg_rem *a, uint32_t insn)
+static bool trans_rem(DisasContext *ctx, arg_rem *a)
 {
     return gen_arith(ctx, a, &gen_rem);
 }
 
-static bool trans_remu(DisasContext *ctx, arg_remu *a, uint32_t insn)
+static bool trans_remu(DisasContext *ctx, arg_remu *a)
 {
     return gen_arith(ctx, a, &gen_remu);
 }
 
-static bool trans_mulw(DisasContext *ctx, arg_mulw *a, uint32_t insn)
+static bool trans_mulw(DisasContext *ctx, arg_mulw *a)
 {
 #ifdef TARGET_RISCV64
     return gen_arith(ctx, a, &tcg_gen_mul_tl);
@@ -88,7 +88,7 @@ static bool trans_mulw(DisasContext *ctx, arg_mulw *a, uint32_t insn)
 #endif
 }
 
-static bool trans_divw(DisasContext *ctx, arg_divw *a, uint32_t insn)
+static bool trans_divw(DisasContext *ctx, arg_divw *a)
 {
 #ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_div);
@@ -97,7 +97,7 @@ static bool trans_divw(DisasContext *ctx, arg_divw *a, uint32_t insn)
 #endif
 }
 
-static bool trans_divuw(DisasContext *ctx, arg_divuw *a, uint32_t insn)
+static bool trans_divuw(DisasContext *ctx, arg_divuw *a)
 {
 #ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_divu);
@@ -106,7 +106,7 @@ static bool trans_divuw(DisasContext *ctx, arg_divuw *a, uint32_t insn)
 #endif
 }
 
-static bool trans_remw(DisasContext *ctx, arg_remw *a, uint32_t insn)
+static bool trans_remw(DisasContext *ctx, arg_remw *a)
 {
 #ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_rem);
@@ -115,7 +115,7 @@ static bool trans_remw(DisasContext *ctx, arg_remw *a, uint32_t insn)
 #endif
 }
 
-static bool trans_remuw(DisasContext *ctx, arg_remuw *a, uint32_t insn)
+static bool trans_remuw(DisasContext *ctx, arg_remuw *a)
 {
 #ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_remu);
Signature · 1 line
2.17.2
Reviewed-by on v1 3/7
#13 lore raw

Re: [Qemu-devel] [PATCH 3/7] target/riscv: Update for decodetree insn argument change

Quoted 11 lines · Richard Henderson

??? Should be merged back into previous patches.
??? Additional changes required for compact mode.

---
  .../riscv/insn_trans/trans_privileged.inc.c   |  19 ++-
  target/riscv/insn_trans/trans_rva.inc.c       |  44 +++---
  target/riscv/insn_trans/trans_rvc.inc.c       | 148 +++++++++---------
  target/riscv/insn_trans/trans_rvd.inc.c       |  64 ++++----
  target/riscv/insn_trans/trans_rvf.inc.c       |  60 +++----
  target/riscv/insn_trans/trans_rvi.inc.c       | 114 +++++++-------
  target/riscv/insn_trans/trans_rvm.inc.c       |  26 +--
  7 files changed, 234 insertions(+), 241 deletions(-)

Cheers,
Bastian

#14 lore raw

PATCH 4/7 target/riscv: Rename some argument sets in insn32.decode

In reply to Richard Henderson

For format x, use &x for the argument set and @x for the extract. This is less confusing than e.g. "arith" for format R.

---
 target/riscv/insn_trans/trans_rvi.inc.c |  2 +-
 target/riscv/translate.c                | 10 +++++-----
 target/riscv/insn32.decode              | 12 ++++++------
 3 files changed, 12 insertions(+), 12 deletions(-)
target/riscv/insn_trans/trans_rvi.inc.c +1 -1
index 2ef355019d..7e676fe2e4 100644
@@ -72,7 +72,7 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
     return true;
 }
 
-static bool gen_branch(DisasContext *ctx, arg_branch *a, TCGCond cond)
+static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond)
 {
     TCGLabel *l = gen_new_label();
     TCGv source1, source2;
target/riscv/translate.c +5 -5
index ece163e69f..e7fe8720ac 100644
@@ -326,7 +326,7 @@ bool decode_insn32(DisasContext *ctx, uint32_t insn);
 /* Include the auto-generated decoder for 32 bit insn */
 #include "decode_insn32.inc.c"
 
-static bool gen_arith_imm(DisasContext *ctx, arg_arith_imm *a,
+static bool gen_arith_imm(DisasContext *ctx, arg_i *a,
                           void(*func)(TCGv, TCGv, TCGv))
 {
     TCGv source1, source2;
@@ -344,7 +344,7 @@ static bool gen_arith_imm(DisasContext *ctx, arg_arith_imm *a,
     return true;
 }
 
-static bool gen_arith(DisasContext *ctx, arg_arith *a,
+static bool gen_arith(DisasContext *ctx, arg_r *a,
                       void(*func)(TCGv, TCGv, TCGv))
 {
     TCGv source1, source2;
@@ -363,7 +363,7 @@ static bool gen_arith(DisasContext *ctx, arg_arith *a,
 }
 
 #ifdef TARGET_RISCV64
-static bool gen_arith_w(DisasContext *ctx, arg_arith *a,
+static bool gen_arith_w(DisasContext *ctx, arg_r *a,
                         void(*func)(TCGv, TCGv, TCGv))
 {
     TCGv source1, source2;
@@ -384,8 +384,8 @@ static bool gen_arith_w(DisasContext *ctx, arg_arith *a,
 }
 #endif
 
-static bool gen_shift(DisasContext *ctx, arg_arith *a,
-                        void(*func)(TCGv, TCGv, TCGv))
+static bool gen_shift(DisasContext *ctx, arg_r *a,
+                      void(*func)(TCGv, TCGv, TCGv))
 {
     TCGv source1 = tcg_temp_new();
     TCGv source2 = tcg_temp_new();
target/riscv/insn32.decode +6 -6
index 1541c254df..77e093a060 100644
@@ -38,17 +38,17 @@
 %imm_u    12:s20                 !function=ex_shift_12
 
 # Argument sets:
-&branch    imm rs2 rs1
-&arith_imm imm rs1 rd
-&arith     rd rs1 rs2
+&b         imm rs2 rs1
+&i         imm rs1 rd
+&r         rd rs1 rs2
 &shift     shamt rs1 rd
 &atomic    aq rl rs2 rs1 rd
 
 # Formats 32:
 
-@r       .......   ..... ..... ... ..... ....... &arith            %rs2 %rs1 %rd
-@i       ............    ..... ... ..... ....... &arith_imm imm=%imm_i  %rs1 %rd
-@b       .......   ..... ..... ... ..... ....... &branch imm=%imm_b %rs2 %rs1
+@r       .......   ..... ..... ... ..... ....... &r    %rs2 %rs1 %rd
+@i       ............    ..... ... ..... ....... &i    imm=%imm_i %rs1 %rd
+@b       .......   ..... ..... ... ..... ....... &b    imm=%imm_b %rs2 %rs1
 @s       .......   ..... ..... ... ..... .......         imm=%imm_s %rs2 %rs1
 @u       ....................      ..... .......         imm=%imm_u          %rd
 @j       ....................      ..... .......         imm=%imm_j          %rd
Signature · 1 line
2.17.2
Reviewed-by on v1 4/7
#15 lore raw

Re: [Qemu-devel] [PATCH 4/7] target/riscv: Rename some argument sets in insn32.decode

Quoted 2 lines · Richard Henderson

For format x, use &x for the argument set and @x for the extract. This is less confusing than e.g. "arith" for format R.

With your S-o-b:

Quoted 90 lines
---
  target/riscv/insn_trans/trans_rvi.inc.c |  2 +-
  target/riscv/translate.c                | 10 +++++-----
  target/riscv/insn32.decode              | 12 ++++++------
  3 files changed, 12 insertions(+), 12 deletions(-)
target/riscv/insn_trans/trans_rvi.inc.c +1 -1
index 2ef355019d..7e676fe2e4 100644
@@ -72,7 +72,7 @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
      return true;
  }
 
-static bool gen_branch(DisasContext *ctx, arg_branch *a, TCGCond cond)
+static bool gen_branch(DisasContext *ctx, arg_b *a, TCGCond cond)
  {
      TCGLabel *l = gen_new_label();
      TCGv source1, source2;
target/riscv/translate.c +5 -5
index ece163e69f..e7fe8720ac 100644
@@ -326,7 +326,7 @@ bool decode_insn32(DisasContext *ctx, uint32_t insn);
  /* Include the auto-generated decoder for 32 bit insn */
  #include "decode_insn32.inc.c"
 
-static bool gen_arith_imm(DisasContext *ctx, arg_arith_imm *a,
+static bool gen_arith_imm(DisasContext *ctx, arg_i *a,
                            void(*func)(TCGv, TCGv, TCGv))
  {
      TCGv source1, source2;
@@ -344,7 +344,7 @@ static bool gen_arith_imm(DisasContext *ctx, arg_arith_imm *a,
      return true;
  }
 
-static bool gen_arith(DisasContext *ctx, arg_arith *a,
+static bool gen_arith(DisasContext *ctx, arg_r *a,
                        void(*func)(TCGv, TCGv, TCGv))
  {
      TCGv source1, source2;
@@ -363,7 +363,7 @@ static bool gen_arith(DisasContext *ctx, arg_arith *a,
  }
 
  #ifdef TARGET_RISCV64
-static bool gen_arith_w(DisasContext *ctx, arg_arith *a,
+static bool gen_arith_w(DisasContext *ctx, arg_r *a,
                          void(*func)(TCGv, TCGv, TCGv))
  {
      TCGv source1, source2;
@@ -384,8 +384,8 @@ static bool gen_arith_w(DisasContext *ctx, arg_arith *a,
  }
  #endif
 
-static bool gen_shift(DisasContext *ctx, arg_arith *a,
-                        void(*func)(TCGv, TCGv, TCGv))
+static bool gen_shift(DisasContext *ctx, arg_r *a,
+                      void(*func)(TCGv, TCGv, TCGv))
  {
      TCGv source1 = tcg_temp_new();
      TCGv source2 = tcg_temp_new();
target/riscv/insn32.decode +6 -6
index 1541c254df..77e093a060 100644
@@ -38,17 +38,17 @@
  %imm_u    12:s20                 !function=ex_shift_12
 
  # Argument sets:
-&branch    imm rs2 rs1
-&arith_imm imm rs1 rd
-&arith     rd rs1 rs2
+&b         imm rs2 rs1
+&i         imm rs1 rd
+&r         rd rs1 rs2
  &shift     shamt rs1 rd
  &atomic    aq rl rs2 rs1 rd
 
  # Formats 32:
 
-@r       .......   ..... ..... ... ..... ....... &arith            %rs2 %rs1 %rd
-@i       ............    ..... ... ..... ....... &arith_imm imm=%imm_i  %rs1 %rd
-@b       .......   ..... ..... ... ..... ....... &branch imm=%imm_b %rs2 %rs1
+@r       .......   ..... ..... ... ..... ....... &r    %rs2 %rs1 %rd
+@i       ............    ..... ... ..... ....... &i    imm=%imm_i %rs1 %rd
+@b       .......   ..... ..... ... ..... ....... &b    imm=%imm_b %rs2 %rs1
  @s       .......   ..... ..... ... ..... .......         imm=%imm_s %rs2 %rs1
  @u       ....................      ..... .......         imm=%imm_u          %rd
  @j       ....................      ..... .......         imm=%imm_j          %rd
#16 lore raw

Re: [Qemu-devel] [PATCH 4/7] target/riscv: Rename some argument sets in insn32.decode

Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Richard Henderson

For format x, use &x for the argument set and @x for the extract. This is less confusing than e.g. "arith" for format R.

With your S-o-b:

Oh no. I fully expect these to be merged back into the original patch set:
http://lists.nongnu.org/archive/html/qemu-devel/2018-10/msg04648.html

r~

Reviewed-by on v1 4/7
#17 lore raw

Re: [Qemu-devel] [PATCH 4/7] target/riscv: Rename some argument sets in insn32.decode

In reply to Richard Henderson
Quoted 8 lines · Richard Henderson

For format x, use &x for the argument set and @x for the extract. This is less confusing than e.g. "arith" for format R.

---
  target/riscv/insn_trans/trans_rvi.inc.c |  2 +-
  target/riscv/translate.c                | 10 +++++-----
  target/riscv/insn32.decode              | 12 ++++++------
  3 files changed, 12 insertions(+), 12 deletions(-)

Cheers,
Bastian

#18 lore raw

PATCH 5/7 target/riscv: Convert @cs_2 insns to share translation functions

In reply to Richard Henderson

These all expand simply to R format instructions.

---
 target/riscv/insn_trans/trans_rvc.inc.c | 36 -------------------------
 target/riscv/translate.c                | 20 +++++++++++---
 target/riscv/insn16.decode              | 17 +++++++-----
 3 files changed, 26 insertions(+), 47 deletions(-)
target/riscv/insn_trans/trans_rvc.inc.c +0 -36
index 7e2668c03d..152c1c9bca 100644
@@ -176,42 +176,6 @@ static bool trans_c_andi(DisasContext *ctx, arg_c_andi *a)
     return trans_andi(ctx, &arg);
 }
 
-static bool trans_c_sub(DisasContext *ctx, arg_c_sub *a)
-{
-    arg_sub arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_sub(ctx, &arg);
-}
-
-static bool trans_c_xor(DisasContext *ctx, arg_c_xor *a)
-{
-    arg_xor arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_xor(ctx, &arg);
-}
-
-static bool trans_c_or(DisasContext *ctx, arg_c_or *a)
-{
-    arg_or arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_or(ctx, &arg);
-}
-
-static bool trans_c_and(DisasContext *ctx, arg_c_and *a)
-{
-    arg_and arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_and(ctx, &arg);
-}
-
-static bool trans_c_subw(DisasContext *ctx, arg_c_subw *a)
-{
-    arg_subw arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_subw(ctx, &arg);
-}
-
-static bool trans_c_addw(DisasContext *ctx, arg_c_addw *a)
-{
-    arg_addw arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_addw(ctx, &arg);
-}
-
 static bool trans_c_j(DisasContext *ctx, arg_c_j *a)
 {
     arg_jal arg = { .rd = 0, .imm = a->imm };
target/riscv/translate.c +16 -4
index e7fe8720ac..f4d2a56f9a 100644
@@ -322,10 +322,25 @@ static int ex_rvc_register(int reg)
     return 8 + reg;
 }
 
+/*
+ * Include the auto-generated decoders.
+ * Note that the 16-bit decoder reuses some of the trans_* functions
+ * from the 32-bit decoder, which results in duplicate declarations
+ * of the relevant helpers.  Suppress the warning.
+ */
 bool decode_insn32(DisasContext *ctx, uint32_t insn);
-/* Include the auto-generated decoder for 32 bit insn */
+bool decode_insn16(DisasContext *ctx, uint16_t insn);
+
 #include "decode_insn32.inc.c"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wredundant-decls"
+
+#include "decode_insn16.inc.c"
+
+#pragma GCC diagnostic pop
+
+
 static bool gen_arith_imm(DisasContext *ctx, arg_i *a,
                           void(*func)(TCGv, TCGv, TCGv))
 {
@@ -410,9 +425,6 @@ static bool gen_shift(DisasContext *ctx, arg_r *a,
 #include "insn_trans/trans_rvd.inc.c"
 #include "insn_trans/trans_privileged.inc.c"
 
-bool decode_insn16(DisasContext *ctx, uint16_t insn);
-/* auto-generated decoder*/
-#include "decode_insn16.inc.c"
 #include "insn_trans/trans_rvc.inc.c"
 
 static void decode_opc(DisasContext *ctx)
target/riscv/insn16.decode +10 -7
index 138290c450..16525486ae 100644
@@ -39,6 +39,9 @@
 %imm_addi16sp  12:s1 3:2 5:1 2:1 6:1 !function=ex_shift_4
 %imm_lui       12:s1 2:5             !function=ex_shift_12
 
+# Argument sets imported from insn32.decode:
+&r         rd rs1 rs2   !extern
+
 # Argument sets:
 &cl               rs1 rd
 &cl_dw     uimm   rs1 rd
@@ -65,7 +68,7 @@
 @cl_w      ... ... ... .. ... .. &cl_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
 @cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
 @cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
-@cs_2      ... ... ... .. ... .. &cr                      rd=%rs1_3   rs2=%rs2_3
+@cs_2      ... ... ... .. ... .. &r      rd=%rs1_3 rs1=%rs1_3 rs2=%rs2_3
 @cs_d      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
 @cs_w      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
 @cb        ... ... ... .. ... .. &cb     imm=%imm_cb      rs1=%rs1_3
@@ -104,12 +107,12 @@ c_addi16sp_lui    011 .  .....  ..... 01 @c_addi16sp_lui # shares opc with C.LUI
 c_srli            100 . 00 ...  ..... 01 @c_shift
 c_srai            100 . 01 ...  ..... 01 @c_shift
 c_andi            100 . 10 ...  ..... 01 @c_andi
-c_sub             100 0 11 ... 00 ... 01 @cs_2
-c_xor             100 0 11 ... 01 ... 01 @cs_2
-c_or              100 0 11 ... 10 ... 01 @cs_2
-c_and             100 0 11 ... 11 ... 01 @cs_2
-c_subw            100 1 11 ... 00 ... 01 @cs_2
-c_addw            100 1 11 ... 01 ... 01 @cs_2
+sub               100 0 11 ... 00 ... 01 @cs_2
+xor               100 0 11 ... 01 ... 01 @cs_2
+or                100 0 11 ... 10 ... 01 @cs_2
+and               100 0 11 ... 11 ... 01 @cs_2
+subw              100 1 11 ... 00 ... 01 @cs_2
+addw              100 1 11 ... 01 ... 01 @cs_2
 c_j               101     ........... 01 @cj
 c_beqz            110  ... ...  ..... 01 @cb
 c_bnez            111  ... ...  ..... 01 @cb
Signature · 1 line
2.17.2
Reviewed-by on v1 5/7
#19 lore raw

Re: [Qemu-devel] [PATCH 5/7] target/riscv: Convert @cs_2 insns to share translation functions

Quoted 66 lines · Richard Henderson

These all expand simply to R format instructions.

---
  target/riscv/insn_trans/trans_rvc.inc.c | 36 -------------------------
  target/riscv/translate.c                | 20 +++++++++++---
  target/riscv/insn16.decode              | 17 +++++++-----
  3 files changed, 26 insertions(+), 47 deletions(-)
target/riscv/insn_trans/trans_rvc.inc.c +0 -36
index 7e2668c03d..152c1c9bca 100644
@@ -176,42 +176,6 @@ static bool trans_c_andi(DisasContext *ctx, arg_c_andi *a)
      return trans_andi(ctx, &arg);
  }
 
-static bool trans_c_sub(DisasContext *ctx, arg_c_sub *a)
-{
-    arg_sub arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_sub(ctx, &arg);
-}
-
-static bool trans_c_xor(DisasContext *ctx, arg_c_xor *a)
-{
-    arg_xor arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_xor(ctx, &arg);
-}
-
-static bool trans_c_or(DisasContext *ctx, arg_c_or *a)
-{
-    arg_or arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_or(ctx, &arg);
-}
-
-static bool trans_c_and(DisasContext *ctx, arg_c_and *a)
-{
-    arg_and arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_and(ctx, &arg);
-}
-
-static bool trans_c_subw(DisasContext *ctx, arg_c_subw *a)
-{
-    arg_subw arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_subw(ctx, &arg);
-}
-
-static bool trans_c_addw(DisasContext *ctx, arg_c_addw *a)
-{
-    arg_addw arg = { .rd = a->rd, .rs1 = a->rd, .rs2 = a->rs2 };
-    return trans_addw(ctx, &arg);
-}
-
  static bool trans_c_j(DisasContext *ctx, arg_c_j *a)
  {
      arg_jal arg = { .rd = 0, .imm = a->imm };
target/riscv/translate.c +4 -0
index e7fe8720ac..f4d2a56f9a 100644
@@ -322,10 +322,25 @@ static int ex_rvc_register(int reg)
      return 8 + reg;
  }
 
+/*
+ * Include the auto-generated decoders.
+ * Note that the 16-bit decoder reuses some of the trans_* functions
+ * from the 32-bit decoder, which results in duplicate declarations

target/riscv/translate.c static int ex_rvc_register(int reg) · line 337

Quoted 10 lines
target/riscv/translate.c +6 -1
+ * of the relevant helpers.  Suppress the warning.
+ */
  bool decode_insn32(DisasContext *ctx, uint32_t insn);
-/* Include the auto-generated decoder for 32 bit insn */
+bool decode_insn16(DisasContext *ctx, uint16_t insn);
+
  #include "decode_insn32.inc.c"
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wredundant-decls"

We might move that to a generic Makefile rule, this will be useful for other archs.

Something like:

translate*.o: CPPFLAGS += -Wno-redundant-decls

Quoted 52 lines
target/riscv/translate.c +6 -3
+
+#include "decode_insn16.inc.c"
+
+#pragma GCC diagnostic pop
+
+
  static bool gen_arith_imm(DisasContext *ctx, arg_i *a,
                            void(*func)(TCGv, TCGv, TCGv))
  {
@@ -410,9 +425,6 @@ static bool gen_shift(DisasContext *ctx, arg_r *a,
  #include "insn_trans/trans_rvd.inc.c"
  #include "insn_trans/trans_privileged.inc.c"
 
-bool decode_insn16(DisasContext *ctx, uint16_t insn);
-/* auto-generated decoder*/
-#include "decode_insn16.inc.c"
  #include "insn_trans/trans_rvc.inc.c"
 
  static void decode_opc(DisasContext *ctx)
target/riscv/insn16.decode +4 -6
index 138290c450..16525486ae 100644
@@ -39,6 +39,9 @@
  %imm_addi16sp  12:s1 3:2 5:1 2:1 6:1 !function=ex_shift_4
  %imm_lui       12:s1 2:5             !function=ex_shift_12
 
+# Argument sets imported from insn32.decode:
+&r         rd rs1 rs2   !extern
+
  # Argument sets:
  &cl               rs1 rd
  &cl_dw     uimm   rs1 rd
@@ -65,7 +68,7 @@
  @cl_w      ... ... ... .. ... .. &cl_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
  @cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
  @cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
-@cs_2      ... ... ... .. ... .. &cr                      rd=%rs1_3   rs2=%rs2_3
+@cs_2      ... ... ... .. ... .. &r      rd=%rs1_3 rs1=%rs1_3 rs2=%rs2_3
  @cs_d      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
  @cs_w      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
  @cb        ... ... ... .. ... .. &cb     imm=%imm_cb      rs1=%rs1_3
@@ -104,12 +107,12 @@ c_addi16sp_lui    011 .  .....  ..... 01 @c_addi16sp_lui # shares opc with C.LUI
  c_srli            100 . 00 ...  ..... 01 @c_shift
  c_srai            100 . 01 ...  ..... 01 @c_shift
  c_andi            100 . 10 ...  ..... 01 @c_andi
-c_sub             100 0 11 ... 00 ... 01 @cs_2
-c_xor             100 0 11 ... 01 ... 01 @cs_2
-c_or              100 0 11 ... 10 ... 01 @cs_2
-c_and             100 0 11 ... 11 ... 01 @cs_2
-c_subw            100 1 11 ... 00 ... 01 @cs_2

target/riscv/insn16.decode c_addi16sp_lui 011 . ..... ..... 01 @c_addi16sp_lui # shares opc with C.LUI · line 118

Quoted 10 lines
target/riscv/insn16.decode +6 -1
-c_addw            100 1 11 ... 01 ... 01 @cs_2
+sub               100 0 11 ... 00 ... 01 @cs_2
+xor               100 0 11 ... 01 ... 01 @cs_2
+or                100 0 11 ... 10 ... 01 @cs_2
+and               100 0 11 ... 11 ... 01 @cs_2
+subw              100 1 11 ... 00 ... 01 @cs_2
+addw              100 1 11 ... 01 ... 01 @cs_2
  c_j               101     ........... 01 @cj
  c_beqz            110  ... ...  ..... 01 @cb
  c_bnez            111  ... ...  ..... 01 @cb
#20 lore raw

Re: [Qemu-devel] [PATCH 5/7] target/riscv: Convert @cs_2 insns to share translation functions

Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 2 lines

  +#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wredundant-decls"

We might move that to a generic Makefile rule, this will be useful for other archs.

Something like:

translate*.o: CPPFLAGS += -Wno-redundant-decls

I did want to restrict that to the one region though.

r~

Reviewed-by on v1 5/7
#21 lore raw

Re: [Qemu-devel] [PATCH 5/7] target/riscv: Convert @cs_2 insns to share translation functions

In reply to Richard Henderson
Quoted 7 lines · Richard Henderson

These all expand simply to R format instructions.

---
  target/riscv/insn_trans/trans_rvc.inc.c | 36 -------------------------
  target/riscv/translate.c                | 20 +++++++++++---
  target/riscv/insn16.decode              | 17 +++++++-----
  3 files changed, 26 insertions(+), 47 deletions(-)

Pretty cool :)

Cheers,
Bastian

#22 lore raw

PATCH 6/7 target/riscv: Convert @cl_d, @cl_w, @cs_d, @cs_w insns

In reply to Richard Henderson
---
 target/riscv/insn_trans/trans_rvc.inc.c | 34 +++----------------------
 target/riscv/insn16.decode              | 18 +++++++------
 target/riscv/insn32.decode              |  3 ++-
 3 files changed, 16 insertions(+), 39 deletions(-)
target/riscv/insn_trans/trans_rvc.inc.c +4 -30
index 152c1c9bca..c5ffb3bf7c 100644
@@ -28,18 +28,6 @@ static bool trans_c_addi4spn(DisasContext *ctx, arg_c_addi4spn *a)
     return trans_addi(ctx, &arg);
 }
 
-static bool trans_c_fld(DisasContext *ctx, arg_c_fld *a)
-{
-    arg_fld arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm };
-    return trans_fld(ctx, &arg);
-}
-
-static bool trans_c_lw(DisasContext *ctx, arg_c_lw *a)
-{
-    arg_lw arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm };
-    return trans_lw(ctx, &arg);
-}
-
 static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
 {
 #ifdef TARGET_RISCV32
@@ -50,25 +38,12 @@ static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
     return trans_flw(ctx, &arg, insn);
 #else
     /* C.LD ( RV64C/RV128C-only ) */
-    arg_c_fld tmp;
+    arg_i tmp;
     extract_cl_d(&tmp, 0); // FIXME
-    arg_ld arg = { .rd = tmp.rd, .rs1 = tmp.rs1, .imm = tmp.uimm };
-    return trans_ld(ctx, &arg);
+    return trans_ld(ctx, &tmp);
 #endif
 }
 
-static bool trans_c_fsd(DisasContext *ctx, arg_c_fsd *a)
-{
-    arg_fsd arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm };
-    return trans_fsd(ctx, &arg);
-}
-
-static bool trans_c_sw(DisasContext *ctx, arg_c_sw *a)
-{
-    arg_sw arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm };
-    return trans_sw(ctx, &arg);
-}
-
 static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
 {
 #ifdef TARGET_RISCV32
@@ -79,10 +54,9 @@ static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
     return trans_fsw(ctx, &arg, insn);
 #else
     /* C.SD ( RV64C/RV128C-only ) */
-    arg_c_fsd tmp;
+    arg_s tmp;
     extract_cs_d(&tmp, 0); // FIXME
-    arg_sd arg = { .rs1 = tmp.rs1, .rs2 = tmp.rs2, .imm = tmp.uimm };
-    return trans_sd(ctx, &arg);
+    return trans_sd(ctx, &tmp);
 #endif
 }
 
target/riscv/insn16.decode +10 -8
index 16525486ae..73b385ad19 100644
@@ -41,6 +41,8 @@
 
 # Argument sets imported from insn32.decode:
 &r         rd rs1 rs2   !extern
+&i         imm rs1 rd   !extern
+&s         imm rs1 rs2  !extern
 
 # Argument sets:
 &cl               rs1 rd
@@ -64,13 +66,13 @@
 @cr        ....  ..... .....  .. &cr                      rs2=%rs2_5  %rd
 @ci        ... . ..... .....  .. &ci     imm=%imm_ci                  %rd
 @ciw       ...   ........ ... .. &ciw    nzuimm=%nzuimm_ciw           rd=%rs2_3
-@cl_d      ... ... ... .. ... .. &cl_dw  uimm=%uimm_cl_d  rs1=%rs1_3  rd=%rs2_3
-@cl_w      ... ... ... .. ... .. &cl_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
+@cl_d      ... ... ... .. ... .. &i  imm=%uimm_cl_d  rs1=%rs1_3  rd=%rs2_3
+@cl_w      ... ... ... .. ... .. &i  imm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
 @cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
 @cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
 @cs_2      ... ... ... .. ... .. &r      rd=%rs1_3 rs1=%rs1_3 rs2=%rs2_3
-@cs_d      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
-@cs_w      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
+@cs_d      ... ... ... .. ... .. &s  imm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
+@cs_w      ... ... ... .. ... .. &s  imm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
 @cb        ... ... ... .. ... .. &cb     imm=%imm_cb      rs1=%rs1_3
 @cj        ...    ........... .. &c_j    imm=%imm_cj
 
@@ -92,11 +94,11 @@
 
 # *** RV64C Standard Extension (Quadrant 0) ***
 c_addi4spn        000    ........ ... 00 @ciw
-c_fld             001  ... ... .. ... 00 @cl_d
-c_lw              010  ... ... .. ... 00 @cl_w
+fld               001  ... ... .. ... 00 @cl_d
+lw                010  ... ... .. ... 00 @cl_w
 c_flw_ld          011  --- ... -- ... 00 @cl    #Note: Must parse uimm manually
-c_fsd             101  ... ... .. ... 00 @cs_d
-c_sw              110  ... ... .. ... 00 @cs_w
+fsd               101  ... ... .. ... 00 @cs_d
+sw                110  ... ... .. ... 00 @cs_w
 c_fsw_sd          111  --- ... -- ... 00 @cs    #Note: Must parse uimm manually
 
 # *** RV64C Standard Extension (Quadrant 1) ***
target/riscv/insn32.decode +2 -1
index 77e093a060..e1fccc57c6 100644
@@ -40,6 +40,7 @@
 # Argument sets:
 &b         imm rs2 rs1
 &i         imm rs1 rd
+&s         imm rs2 rs1
 &r         rd rs1 rs2
 &shift     shamt rs1 rd
 &atomic    aq rl rs2 rs1 rd
@@ -49,7 +50,7 @@
 @r       .......   ..... ..... ... ..... ....... &r    %rs2 %rs1 %rd
 @i       ............    ..... ... ..... ....... &i    imm=%imm_i %rs1 %rd
 @b       .......   ..... ..... ... ..... ....... &b    imm=%imm_b %rs2 %rs1
-@s       .......   ..... ..... ... ..... .......         imm=%imm_s %rs2 %rs1
+@s       .......   ..... ..... ... ..... ....... &s    imm=%imm_s %rs2 %rs1
 @u       ....................      ..... .......         imm=%imm_u          %rd
 @j       ....................      ..... .......         imm=%imm_j          %rd
 
Signature · 1 line
2.17.2
Reviewed-by on v1 6/7
#23 lore raw

Re: [Qemu-devel] [PATCH 6/7] target/riscv: Convert @cl_d, @cl_w, @cs_d, @cs_w insns

With S-o-b:

Quoted 139 lines · Richard Henderson
---
  target/riscv/insn_trans/trans_rvc.inc.c | 34 +++----------------------
  target/riscv/insn16.decode              | 18 +++++++------
  target/riscv/insn32.decode              |  3 ++-
  3 files changed, 16 insertions(+), 39 deletions(-)
target/riscv/insn_trans/trans_rvc.inc.c +4 -30
index 152c1c9bca..c5ffb3bf7c 100644
@@ -28,18 +28,6 @@ static bool trans_c_addi4spn(DisasContext *ctx, arg_c_addi4spn *a)
      return trans_addi(ctx, &arg);
  }
 
-static bool trans_c_fld(DisasContext *ctx, arg_c_fld *a)
-{
-    arg_fld arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm };
-    return trans_fld(ctx, &arg);
-}
-
-static bool trans_c_lw(DisasContext *ctx, arg_c_lw *a)
-{
-    arg_lw arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm };
-    return trans_lw(ctx, &arg);
-}
-
  static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
  {
  #ifdef TARGET_RISCV32
@@ -50,25 +38,12 @@ static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
      return trans_flw(ctx, &arg, insn);
  #else
      /* C.LD ( RV64C/RV128C-only ) */
-    arg_c_fld tmp;
+    arg_i tmp;
      extract_cl_d(&tmp, 0); // FIXME
-    arg_ld arg = { .rd = tmp.rd, .rs1 = tmp.rs1, .imm = tmp.uimm };
-    return trans_ld(ctx, &arg);
+    return trans_ld(ctx, &tmp);
  #endif
  }
 
-static bool trans_c_fsd(DisasContext *ctx, arg_c_fsd *a)
-{
-    arg_fsd arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm };
-    return trans_fsd(ctx, &arg);
-}
-
-static bool trans_c_sw(DisasContext *ctx, arg_c_sw *a)
-{
-    arg_sw arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm };
-    return trans_sw(ctx, &arg);
-}
-
  static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
  {
  #ifdef TARGET_RISCV32
@@ -79,10 +54,9 @@ static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
      return trans_fsw(ctx, &arg, insn);
  #else
      /* C.SD ( RV64C/RV128C-only ) */
-    arg_c_fsd tmp;
+    arg_s tmp;
      extract_cs_d(&tmp, 0); // FIXME
-    arg_sd arg = { .rs1 = tmp.rs1, .rs2 = tmp.rs2, .imm = tmp.uimm };
-    return trans_sd(ctx, &arg);
+    return trans_sd(ctx, &tmp);
  #endif
  }
 
target/riscv/insn16.decode +10 -8
index 16525486ae..73b385ad19 100644
@@ -41,6 +41,8 @@
 
  # Argument sets imported from insn32.decode:
  &r         rd rs1 rs2   !extern
+&i         imm rs1 rd   !extern
+&s         imm rs1 rs2  !extern
 
  # Argument sets:
  &cl               rs1 rd
@@ -64,13 +66,13 @@
  @cr        ....  ..... .....  .. &cr                      rs2=%rs2_5  %rd
  @ci        ... . ..... .....  .. &ci     imm=%imm_ci                  %rd
  @ciw       ...   ........ ... .. &ciw    nzuimm=%nzuimm_ciw           rd=%rs2_3
-@cl_d      ... ... ... .. ... .. &cl_dw  uimm=%uimm_cl_d  rs1=%rs1_3  rd=%rs2_3
-@cl_w      ... ... ... .. ... .. &cl_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
+@cl_d      ... ... ... .. ... .. &i  imm=%uimm_cl_d  rs1=%rs1_3  rd=%rs2_3
+@cl_w      ... ... ... .. ... .. &i  imm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
  @cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
  @cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
  @cs_2      ... ... ... .. ... .. &r      rd=%rs1_3 rs1=%rs1_3 rs2=%rs2_3
-@cs_d      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
-@cs_w      ... ... ... .. ... .. &cs_dw  uimm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
+@cs_d      ... ... ... .. ... .. &s  imm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
+@cs_w      ... ... ... .. ... .. &s  imm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
  @cb        ... ... ... .. ... .. &cb     imm=%imm_cb      rs1=%rs1_3
  @cj        ...    ........... .. &c_j    imm=%imm_cj
 
@@ -92,11 +94,11 @@
 
  # *** RV64C Standard Extension (Quadrant 0) ***
  c_addi4spn        000    ........ ... 00 @ciw
-c_fld             001  ... ... .. ... 00 @cl_d
-c_lw              010  ... ... .. ... 00 @cl_w
+fld               001  ... ... .. ... 00 @cl_d
+lw                010  ... ... .. ... 00 @cl_w
  c_flw_ld          011  --- ... -- ... 00 @cl    #Note: Must parse uimm manually
-c_fsd             101  ... ... .. ... 00 @cs_d
-c_sw              110  ... ... .. ... 00 @cs_w
+fsd               101  ... ... .. ... 00 @cs_d
+sw                110  ... ... .. ... 00 @cs_w
  c_fsw_sd          111  --- ... -- ... 00 @cs    #Note: Must parse uimm manually
 
  # *** RV64C Standard Extension (Quadrant 1) ***
target/riscv/insn32.decode +2 -1
index 77e093a060..e1fccc57c6 100644
@@ -40,6 +40,7 @@
  # Argument sets:
  &b         imm rs2 rs1
  &i         imm rs1 rd
+&s         imm rs2 rs1
  &r         rd rs1 rs2
  &shift     shamt rs1 rd
  &atomic    aq rl rs2 rs1 rd
@@ -49,7 +50,7 @@
  @r       .......   ..... ..... ... ..... ....... &r    %rs2 %rs1 %rd
  @i       ............    ..... ... ..... ....... &i    imm=%imm_i %rs1 %rd
  @b       .......   ..... ..... ... ..... ....... &b    imm=%imm_b %rs2 %rs1
-@s       .......   ..... ..... ... ..... .......         imm=%imm_s %rs2 %rs1
+@s       .......   ..... ..... ... ..... ....... &s    imm=%imm_s %rs2 %rs1
  @u       ....................      ..... .......         imm=%imm_u          %rd
  @j       ....................      ..... .......         imm=%imm_j          %rd
 
#24 lore raw

PATCH 7/7 target/riscv: Splice decodetree inputs for riscv32 vs riscv64

In reply to Richard Henderson

This primarily solves the case for RVC that several insns are completely different, decode and all, between the two. But it also means that we need less ifdefing for RV{I,M,A,F,D}.

---
 target/riscv/insn_trans/trans_rva.inc.c | 46 +---------------
 target/riscv/insn_trans/trans_rvc.inc.c | 71 -------------------------
 target/riscv/insn_trans/trans_rvd.inc.c | 26 +--------
 target/riscv/insn_trans/trans_rvf.inc.c | 18 +------
 target/riscv/insn_trans/trans_rvi.inc.c | 49 +++--------------
 target/riscv/insn_trans/trans_rvm.inc.c | 22 +-------
 target/riscv/Makefile.objs              | 23 ++++++--
 target/riscv/insn16-32.decode           | 31 +++++++++++
 target/riscv/insn16-64.decode           | 33 ++++++++++++
 target/riscv/insn16.decode              | 24 +++------
 target/riscv/insn32.decode              | 53 +-----------------
 target/riscv/insn64.decode              | 71 +++++++++++++++++++++++++
 12 files changed, 176 insertions(+), 291 deletions(-)
 create mode 100644 target/riscv/insn16-32.decode
 create mode 100644 target/riscv/insn16-64.decode
 create mode 100644 target/riscv/insn64.decode
target/riscv/insn_trans/trans_rva.inc.c +2 -44
index e658bf32c4..e63d8a5127 100644
@@ -144,101 +144,59 @@ static bool trans_amomaxu_w(DisasContext *ctx, arg_amomaxu_w *a)
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TESL));
 }
 
+#ifdef TARGET_RISCV64
 static bool trans_lr_d(DisasContext *ctx, arg_lr_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_lr(ctx, a, MO_ALIGN | MO_TEQ);
-#else
-    return false;
-#endif
 }
 
 static bool trans_sc_d(DisasContext *ctx, arg_sc_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_sc(ctx, a, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amoswap_d(DisasContext *ctx, arg_amoswap_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amoxor_d(DisasContext *ctx, arg_amoxor_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amoand_d(DisasContext *ctx, arg_amoand_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amoor_d(DisasContext *ctx, arg_amoor_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amomin_d(DisasContext *ctx, arg_amomin_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amomax_d(DisasContext *ctx, arg_amomax_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amominu_d(DisasContext *ctx, arg_amominu_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
 
 static bool trans_amomaxu_d(DisasContext *ctx, arg_amomaxu_d *a)
 {
-#ifdef TARGET_RISCV64
     return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
 }
+#endif /* TARGET_RISCV64 */
target/riscv/insn_trans/trans_rvc.inc.c +0 -71

92 lines not on this page · raw message

target/riscv/insn_trans/trans_rvd.inc.c +2 -24
index 4b2face7c5..fab6621d08 100644
@@ -318,9 +318,9 @@ static bool trans_fcvt_d_wu(DisasContext *ctx, arg_fcvt_d_wu *a)
     return true;
 }
 
+#ifdef TARGET_RISCV64
 static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -328,15 +328,11 @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
     gen_helper_fcvt_l_d(t0, cpu_env, cpu_fpr[a->rs1]);
     gen_set_gpr(a->rd, t0);
     tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
     return true;
 }
 
 static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -344,27 +340,19 @@ static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a)
     gen_helper_fcvt_lu_d(t0, cpu_env, cpu_fpr[a->rs1]);
     gen_set_gpr(a->rd, t0);
     tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
     return true;
 }
 
 static bool trans_fmv_x_d(DisasContext *ctx, arg_fmv_x_d *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     gen_set_gpr(a->rd, cpu_fpr[a->rs1]);
-#else
-    gen_exception_illegal(ctx);
-#endif
     return true;
 }
 
 static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -373,15 +361,11 @@ static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a)
     gen_set_rm(ctx, a->rm);
     gen_helper_fcvt_d_l(cpu_fpr[a->rd], cpu_env, t0);
     tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
     return true;
 }
 
 static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -390,15 +374,11 @@ static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a)
     gen_set_rm(ctx, a->rm);
     gen_helper_fcvt_d_lu(cpu_fpr[a->rd], cpu_env, t0);
     tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
     return true;
 }
 
 static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -406,8 +386,6 @@ static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a)
 
     tcg_gen_mov_tl(cpu_fpr[a->rd], t0);
     tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
     return true;
 }
+#endif /* TARGET_RISCV64 */
target/riscv/insn_trans/trans_rvf.inc.c +2 -16
index 6f055e77bf..0007cf0980 100644
@@ -333,9 +333,9 @@ static bool trans_fmv_w_x(DisasContext *ctx, arg_fmv_w_x *a)
     return true;
 }
 
+#ifdef TARGET_RISCV64
 static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -344,14 +344,10 @@ static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a)
     gen_set_gpr(a->rd, t0);
     tcg_temp_free(t0);
     return true;
-#else
-    return false;
-#endif
 }
 
 static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -360,14 +356,10 @@ static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a)
     gen_set_gpr(a->rd, t0);
     tcg_temp_free(t0);
     return true;
-#else
-    return false;
-#endif
 }
 
 static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -378,14 +370,10 @@ static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a)
 
     tcg_temp_free(t0);
     return true;
-#else
-    return false;
-#endif
 }
 
 static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a)
 {
-#if defined(TARGET_RISCV64)
     REQUIRE_FPU;
 
     TCGv t0 = tcg_temp_new();
@@ -396,7 +384,5 @@ static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a)
 
     tcg_temp_free(t0);
     return true;
-#else
-    return false;
-#endif
 }
+#endif /* TARGET_RISCV64 */
target/riscv/insn_trans/trans_rvi.inc.c +6 -43

147 lines not on this page · raw message

target/riscv/insn_trans/trans_rvm.inc.c +2 -20
index 7809bcb187..ee0ff4deb9 100644
@@ -79,47 +79,29 @@ static bool trans_remu(DisasContext *ctx, arg_remu *a)
     return gen_arith(ctx, a, &gen_remu);
 }
 
+#ifdef TARGET_RISCV64
 static bool trans_mulw(DisasContext *ctx, arg_mulw *a)
 {
-#ifdef TARGET_RISCV64
     return gen_arith(ctx, a, &tcg_gen_mul_tl);
-#else
-    return false;
-#endif
 }
 
 static bool trans_divw(DisasContext *ctx, arg_divw *a)
 {
-#ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_div);
-#else
-    return false;
-#endif
 }
 
 static bool trans_divuw(DisasContext *ctx, arg_divuw *a)
 {
-#ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_divu);
-#else
-    return false;
-#endif
 }
 
 static bool trans_remw(DisasContext *ctx, arg_remw *a)
 {
-#ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_rem);
-#else
-    return false;
-#endif
 }
 
 static bool trans_remuw(DisasContext *ctx, arg_remuw *a)
 {
-#ifdef TARGET_RISCV64
     return gen_arith_w(ctx, a, &gen_remu);
-#else
-    return false;
-#endif
 }
+#endif /* TARGET_RISCV64 */
target/riscv/Makefile.objs +19 -4
index ec7326f1c7..45cc2e8c8a 100644
@@ -2,14 +2,29 @@ obj-y += translate.o op_helper.o helper.o cpu.o fpu_helper.o gdbstub.o pmp.o
 
 DECODETREE = $(SRC_PATH)/scripts/decodetree.py
 
-target/riscv/decode_insn32.inc.c: \
-  $(SRC_PATH)/target/riscv/insn32.decode $(DECODETREE)
+decode32-y = $(SRC_PATH)/target/riscv/insn32.decode
+decode32-$(TARGET_RISCV64) += $(SRC_PATH)/target/riscv/insn64.decode
+
+decode16-y = $(SRC_PATH)/target/riscv/insn16.decode
+decode16-$(TARGET_RISCV32) += $(SRC_PATH)/target/riscv/insn16-32.decode
+decode16-$(TARGET_RISCV64) += $(SRC_PATH)/target/riscv/insn16-64.decode
+
+target/riscv/insn32.decode: $(decode32-y)
+	$(call quiet-command, \
+	  cat $(decode32-y) > target/riscv/insn32.decode, \
+          "CAT", $(TARGET_DIR)$@)
+
+target/riscv/insn16.decode: $(decode16-y)
+	$(call quiet-command, \
+	  cat $(decode16-y) > target/riscv/insn16.decode, \
+          "CAT", $(TARGET_DIR)$@)
+
+target/riscv/decode_insn32.inc.c: target/riscv/insn32.decode $(DECODETREE)
 	$(call quiet-command, \
 	  $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn32 $<, \
 	  "GEN", $(TARGET_DIR)$@)
 
-target/riscv/decode_insn16.inc.c: \
-  $(SRC_PATH)/target/riscv/insn16.decode $(DECODETREE)
+target/riscv/decode_insn16.inc.c: target/riscv/insn16.decode $(DECODETREE)
 	$(call quiet-command, \
 	  $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn16 --insnwidth 16 $<, \
 	  "GEN", $(TARGET_DIR)$@)
target/riscv/insn16-32.decode new file +31 -0
new file mode 100644
index 0000000000..efb7f5bdc8
@@ -0,0 +1,31 @@
+#
+# RISC-V translation routines for the RVC Instruction Set.
+#
+# Copyright (c) 2018 Peer Adelt, [email protected]
+#                    Bastian Koppelmann, [email protected]
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2 or later, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This is concatenated with insn16.decode for risc32 targets.
+# All of the fields and formats are there.
+
+# *** RV32C Standard Extension (Quadrant 0) ***
+flw     011 ... ... .. ... 00   @cl_w
+fsw     111 ... ... .. ... 00   @cs_w
+
+# *** RV32C Standard Extension (Quadrant 1) ***
+jal     001 ......   ..... 01   &j imm=%imm_cj rd=1
+
+# *** RV32C Standard Extension (Quadrant 2) ***
+flw     011 . .....  ..... 10   &i imm=%uimm_6bit_lw %rd rs1=2
+fsw     111 ......   ..... 10   &s imm=%uimm_6bit_sw rs2=%rs2_5 rs1=2
target/riscv/insn16-64.decode new file +33 -0
new file mode 100644
index 0000000000..163fd5014a
@@ -0,0 +1,33 @@
+#
+# RISC-V translation routines for the RVC Instruction Set.
+#
+# Copyright (c) 2018 Peer Adelt, [email protected]
+#                    Bastian Koppelmann, [email protected]
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2 or later, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This is concatenated with insn16.decode for risc64 targets.
+# All of the fields and formats are there.
+
+# *** RV64C Standard Extension (Quadrant 0) ***
+ld      011  ... ... .. ... 00 @cl_d
+sd      111  ... ... .. ... 00 @cs_d
+
+# *** RV64C Standard Extension (Quadrant 1) ***
+addiw   001 .  .....  ..... 01 @ci
+subw              100 1 11 ... 00 ... 01 @cs_2
+addw              100 1 11 ... 01 ... 01 @cs_2
+
+# *** RV64C Standard Extension (Quadrant 2) ***
+ld      011 .  .....  ..... 10 &i imm=%uimm_6bit_ld %rd rs1=2
+sd      111 .  .....  ..... 10 &s imm=%uimm_6bit_sw rs2=%rs2_5 rs1=2
target/riscv/insn16.decode +6 -18
index 73b385ad19..345629b649 100644
@@ -42,6 +42,7 @@
 # Argument sets imported from insn32.decode:
 &r         rd rs1 rs2   !extern
 &i         imm rs1 rd   !extern
+&j         imm rd       !extern
 &s         imm rs1 rs2  !extern
 
 # Argument sets:
@@ -64,12 +65,10 @@
 
 # Formats 16:
 @cr        ....  ..... .....  .. &cr                      rs2=%rs2_5  %rd
-@ci        ... . ..... .....  .. &ci     imm=%imm_ci                  %rd
+@ci        ... . ..... .....  .. &i  imm=%imm_ci %rd rs1=%rd
 @ciw       ...   ........ ... .. &ciw    nzuimm=%nzuimm_ciw           rd=%rs2_3
 @cl_d      ... ... ... .. ... .. &i  imm=%uimm_cl_d  rs1=%rs1_3  rd=%rs2_3
 @cl_w      ... ... ... .. ... .. &i  imm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
-@cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
-@cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
 @cs_2      ... ... ... .. ... .. &r      rd=%rs1_3 rs1=%rs1_3 rs2=%rs2_3
 @cs_d      ... ... ... .. ... .. &s  imm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
 @cs_w      ... ... ... .. ... .. &s  imm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
@@ -82,28 +81,21 @@
 @c_sw      ... . .....  ..... .. &c_sd     uimm=%uimm_6bit_sw  rs2=%rs2_5
 
 @c_addi16sp_lui ... .  ..... ..... .. &c_addi16sp_lui %imm_lui %imm_addi16sp %rd
-@c_flwsp_ldsp   ... .  ..... ..... .. &c_flwsp_ldsp uimm_flwsp=%uimm_6bit_lw \
-    uimm_ldsp=%uimm_6bit_ld %rd
-@c_fswsp_sdsp   ... .  ..... ..... .. &c_fswsp_sdsp uimm_fswsp=%uimm_6bit_sw \
-    uimm_sdsp=%uimm_6bit_sd rs2=%rs2_5
 
 @c_shift        ... . .. ... ..... .. &c_shift rd=%rs1_3 shamt=%nzuimm_6bit
 @c_shift2       ... . .. ... ..... .. &c_shift rd=%rd    shamt=%nzuimm_6bit
 
-@c_andi         ... . .. ... ..... .. &ci imm=%imm_ci rd=%rs1_3
+@c_andi         ... . .. ... ..... .. &i imm=%imm_ci rd=%rs1_3 rs1=%rs1_3
 
-# *** RV64C Standard Extension (Quadrant 0) ***
+# *** RVC Standard Extension (Quadrant 0) ***
 c_addi4spn        000    ........ ... 00 @ciw
 fld               001  ... ... .. ... 00 @cl_d
 lw                010  ... ... .. ... 00 @cl_w
-c_flw_ld          011  --- ... -- ... 00 @cl    #Note: Must parse uimm manually
 fsd               101  ... ... .. ... 00 @cs_d
 sw                110  ... ... .. ... 00 @cs_w
-c_fsw_sd          111  --- ... -- ... 00 @cs    #Note: Must parse uimm manually
 
-# *** RV64C Standard Extension (Quadrant 1) ***
+# *** RVC Standard Extension (Quadrant 1) ***
 c_addi            000 .  .....  ..... 01 @ci
-c_jal_addiw       001 .  .....  ..... 01 @ci #Note: parse rd and/or imm manually
 c_li              010 .  .....  ..... 01 @ci
 c_addi16sp_lui    011 .  .....  ..... 01 @c_addi16sp_lui # shares opc with C.LUI
 c_srli            100 . 00 ...  ..... 01 @c_shift
@@ -113,19 +105,15 @@ sub               100 0 11 ... 00 ... 01 @cs_2
 xor               100 0 11 ... 01 ... 01 @cs_2
 or                100 0 11 ... 10 ... 01 @cs_2
 and               100 0 11 ... 11 ... 01 @cs_2
-subw              100 1 11 ... 00 ... 01 @cs_2
-addw              100 1 11 ... 01 ... 01 @cs_2
 c_j               101     ........... 01 @cj
 c_beqz            110  ... ...  ..... 01 @cb
 c_bnez            111  ... ...  ..... 01 @cb
 
-# *** RV64C Standard Extension (Quadrant 2) ***
+# *** RVC Standard Extension (Quadrant 2) ***
 c_slli            000 .  .....  ..... 10 @c_shift2
 c_fldsp           001 .  .....  ..... 10 @c_ld
 c_lwsp            010 .  .....  ..... 10 @c_lw
-c_flwsp_ldsp      011 .  .....  ..... 10 @c_flwsp_ldsp #C.LDSP:RV64;C.FLWSP:RV32
 c_jr_mv           100 0  .....  ..... 10 @cr
 c_ebreak_jalr_add 100 1  .....  ..... 10 @cr
 c_fsdsp           101   ......  ..... 10 @c_sd
 c_swsp            110 .  .....  ..... 10 @c_sw
-c_fswsp_sdsp      111 .  .....  ..... 10 @c_fswsp_sdsp #C.SDSP:RV64;C.FSWSP:RV32
target/riscv/insn32.decode +2 -51

100 lines not on this page · raw message

target/riscv/insn64.decode new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.17.2
Reviewed-by on v1 7/7
#25 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/riscv: Splice decodetree inputs for riscv32 vs riscv64

Quoted 3 lines · Richard Henderson

This primarily solves the case for RVC that several insns are completely different, decode and all, between the two. But it also means that we need less ifdefing for RV{I,M,A,F,D}.

Lovely!

Probably due to the jet lag you forgot your S-o-b :p With it:

Quoted 993 lines
---
  target/riscv/insn_trans/trans_rva.inc.c | 46 +---------------
  target/riscv/insn_trans/trans_rvc.inc.c | 71 -------------------------
  target/riscv/insn_trans/trans_rvd.inc.c | 26 +--------
  target/riscv/insn_trans/trans_rvf.inc.c | 18 +------
  target/riscv/insn_trans/trans_rvi.inc.c | 49 +++--------------
  target/riscv/insn_trans/trans_rvm.inc.c | 22 +-------
  target/riscv/Makefile.objs              | 23 ++++++--
  target/riscv/insn16-32.decode           | 31 +++++++++++
  target/riscv/insn16-64.decode           | 33 ++++++++++++
  target/riscv/insn16.decode              | 24 +++------
  target/riscv/insn32.decode              | 53 +-----------------
  target/riscv/insn64.decode              | 71 +++++++++++++++++++++++++
  12 files changed, 176 insertions(+), 291 deletions(-)

create mode 100644 target/riscv/insn16-32.decode create mode 100644 target/riscv/insn16-64.decode create mode 100644 target/riscv/insn64.decode

target/riscv/insn_trans/trans_rva.inc.c +2 -44
index e658bf32c4..e63d8a5127 100644
@@ -144,101 +144,59 @@ static bool trans_amomaxu_w(DisasContext *ctx, arg_amomaxu_w *a)
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TESL));
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_lr_d(DisasContext *ctx, arg_lr_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_lr(ctx, a, MO_ALIGN | MO_TEQ);
-#else
-    return false;
-#endif
  }
 
  static bool trans_sc_d(DisasContext *ctx, arg_sc_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_sc(ctx, a, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amoswap_d(DisasContext *ctx, arg_amoswap_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amoadd_d(DisasContext *ctx, arg_amoadd_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amoxor_d(DisasContext *ctx, arg_amoxor_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amoand_d(DisasContext *ctx, arg_amoand_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amoor_d(DisasContext *ctx, arg_amoor_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amomin_d(DisasContext *ctx, arg_amomin_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amomax_d(DisasContext *ctx, arg_amomax_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amominu_d(DisasContext *ctx, arg_amominu_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
 
  static bool trans_amomaxu_d(DisasContext *ctx, arg_amomaxu_d *a)
  {
-#ifdef TARGET_RISCV64
      return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, (MO_ALIGN | MO_TEQ));
-#else
-    return false;
-#endif
  }
+#endif /* TARGET_RISCV64 */
target/riscv/insn_trans/trans_rvc.inc.c +0 -71
index c5ffb3bf7c..e77bcdb2c6 100644
@@ -28,38 +28,6 @@ static bool trans_c_addi4spn(DisasContext *ctx, arg_c_addi4spn *a)
      return trans_addi(ctx, &arg);
  }
 
-static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
-{
-#ifdef TARGET_RISCV32
-    /* C.FLW ( RV32FC-only ) */
-    arg_c_lw tmp;
-    extract_cl_w(&tmp, insn);
-    arg_flw arg = { .rd = tmp.rd, .rs1 = tmp.rs1, .imm = tmp.uimm };
-    return trans_flw(ctx, &arg, insn);
-#else
-    /* C.LD ( RV64C/RV128C-only ) */
-    arg_i tmp;
-    extract_cl_d(&tmp, 0); // FIXME
-    return trans_ld(ctx, &tmp);
-#endif
-}
-
-static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
-{
-#ifdef TARGET_RISCV32
-    /* C.FSW ( RV32FC-only ) */
-    arg_c_sw tmp;
-    extract_cs_w(&tmp, insn);
-    arg_fsw arg = { .rs1 = tmp.rs1, .rs2 = tmp.rs2, .imm = tmp.uimm };
-    return trans_fsw(ctx, &arg, insn);
-#else
-    /* C.SD ( RV64C/RV128C-only ) */
-    arg_s tmp;
-    extract_cs_d(&tmp, 0); // FIXME
-    return trans_sd(ctx, &tmp);
-#endif
-}
-
  static bool trans_c_addi(DisasContext *ctx, arg_c_addi *a)
  {
      if (a->imm == 0) {
@@ -70,19 +38,6 @@ static bool trans_c_addi(DisasContext *ctx, arg_c_addi *a)
      return trans_addi(ctx, &arg);
  }
 
-static bool trans_c_jal_addiw(DisasContext *ctx, arg_c_jal_addiw *a)
-{
-#ifdef TARGET_RISCV32
-    /* C.JAL */
-    arg_jal arg = { .rd = 1, .imm = a->imm };
-    return trans_jal(ctx, &arg, insn);
-#else
-    /* C.ADDIW */
-    arg_addiw arg = { .rd = a->rd, .rs1 = a->rd, .imm = a->imm };
-    return trans_addiw(ctx, &arg);
-#endif
-}
-
  static bool trans_c_li(DisasContext *ctx, arg_c_li *a)
  {
      if (a->rd == 0) {
@@ -196,20 +151,6 @@ static bool trans_c_lwsp(DisasContext *ctx, arg_c_lwsp *a)
      return trans_lw(ctx, &arg);
  }
 
-static bool trans_c_flwsp_ldsp(DisasContext *ctx, arg_c_flwsp_ldsp *a)
-{
-#ifdef TARGET_RISCV32
-    /* C.FLWSP */
-    arg_flw arg_flw = { .rd = a->rd, .rs1 = 2, .imm = a->uimm_flwsp };
-    return trans_flw(ctx, &arg_flw);
-#else
-    /* C.LDSP */
-    arg_ld arg_ld = { .rd = a->rd, .rs1 = 2, .imm = a->uimm_ldsp };
-    return trans_ld(ctx, &arg_ld);
-#endif
-    return false;
-}
-
  static bool trans_c_jr_mv(DisasContext *ctx, arg_c_jr_mv *a)
  {
      if (a->rd != 0 && a->rs2 == 0) {
@@ -255,15 +196,3 @@ static bool trans_c_swsp(DisasContext *ctx, arg_c_swsp *a)
      arg_sw arg = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm };
      return trans_sw(ctx, &arg);
  }
-
-static bool trans_c_fswsp_sdsp(DisasContext *ctx, arg_c_fswsp_sdsp *a)
-{
-#ifdef TARGET_RISCV32
-    /* C.FSWSP */
-    arg_fsw a_fsw = { .rs1 = a->rs2, .rs2 = 2, .imm = a->uimm_fswsp };
-    return trans_fsw(ctx, &a_fsw, insn);
-#endif
-    /* C.SDSP */
-    arg_sd a_sd = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm_sdsp };
-    return trans_sd(ctx, &a_sd);
-}
target/riscv/insn_trans/trans_rvd.inc.c +2 -24
index 4b2face7c5..fab6621d08 100644
@@ -318,9 +318,9 @@ static bool trans_fcvt_d_wu(DisasContext *ctx, arg_fcvt_d_wu *a)
      return true;
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -328,15 +328,11 @@ static bool trans_fcvt_l_d(DisasContext *ctx, arg_fcvt_l_d *a)
      gen_helper_fcvt_l_d(t0, cpu_env, cpu_fpr[a->rs1]);
      gen_set_gpr(a->rd, t0);
      tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
      return true;
  }
 
  static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -344,27 +340,19 @@ static bool trans_fcvt_lu_d(DisasContext *ctx, arg_fcvt_lu_d *a)
      gen_helper_fcvt_lu_d(t0, cpu_env, cpu_fpr[a->rs1]);
      gen_set_gpr(a->rd, t0);
      tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
      return true;
  }
 
  static bool trans_fmv_x_d(DisasContext *ctx, arg_fmv_x_d *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      gen_set_gpr(a->rd, cpu_fpr[a->rs1]);
-#else
-    gen_exception_illegal(ctx);
-#endif
      return true;
  }
 
  static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -373,15 +361,11 @@ static bool trans_fcvt_d_l(DisasContext *ctx, arg_fcvt_d_l *a)
      gen_set_rm(ctx, a->rm);
      gen_helper_fcvt_d_l(cpu_fpr[a->rd], cpu_env, t0);
      tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
      return true;
  }
 
  static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -390,15 +374,11 @@ static bool trans_fcvt_d_lu(DisasContext *ctx, arg_fcvt_d_lu *a)
      gen_set_rm(ctx, a->rm);
      gen_helper_fcvt_d_lu(cpu_fpr[a->rd], cpu_env, t0);
      tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
      return true;
  }
 
  static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -406,8 +386,6 @@ static bool trans_fmv_d_x(DisasContext *ctx, arg_fmv_d_x *a)
 
      tcg_gen_mov_tl(cpu_fpr[a->rd], t0);
      tcg_temp_free(t0);
-#else
-    gen_exception_illegal(ctx);
-#endif
      return true;
  }
+#endif /* TARGET_RISCV64 */
target/riscv/insn_trans/trans_rvf.inc.c +2 -16
index 6f055e77bf..0007cf0980 100644
@@ -333,9 +333,9 @@ static bool trans_fmv_w_x(DisasContext *ctx, arg_fmv_w_x *a)
      return true;
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -344,14 +344,10 @@ static bool trans_fcvt_l_s(DisasContext *ctx, arg_fcvt_l_s *a)
      gen_set_gpr(a->rd, t0);
      tcg_temp_free(t0);
      return true;
-#else
-    return false;
-#endif
  }
 
  static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -360,14 +356,10 @@ static bool trans_fcvt_lu_s(DisasContext *ctx, arg_fcvt_lu_s *a)
      gen_set_gpr(a->rd, t0);
      tcg_temp_free(t0);
      return true;
-#else
-    return false;
-#endif
  }
 
  static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -378,14 +370,10 @@ static bool trans_fcvt_s_l(DisasContext *ctx, arg_fcvt_s_l *a)
 
      tcg_temp_free(t0);
      return true;
-#else
-    return false;
-#endif
  }
 
  static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a)
  {
-#if defined(TARGET_RISCV64)
      REQUIRE_FPU;
 
      TCGv t0 = tcg_temp_new();
@@ -396,7 +384,5 @@ static bool trans_fcvt_s_lu(DisasContext *ctx, arg_fcvt_s_lu *a)
 
      tcg_temp_free(t0);
      return true;
-#else
-    return false;
-#endif
  }
+#endif /* TARGET_RISCV64 */
target/riscv/insn_trans/trans_rvi.inc.c +6 -43
index 7e676fe2e4..16bfd23739 100644
@@ -168,23 +168,17 @@ static bool trans_lhu(DisasContext *ctx, arg_lhu *a)
      return gen_load(ctx, a, MO_TEUW);
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_lwu(DisasContext *ctx, arg_lwu *a)
  {
-#ifdef TARGET_RISCV64
      return gen_load(ctx, a, MO_TEUL);
-#else
-    return false;
-#endif
  }
 
  static bool trans_ld(DisasContext *ctx, arg_ld *a)
  {
-#ifdef TARGET_RISCV64
      return gen_load(ctx, a, MO_TEQ);
-#else
-    return false;
-#endif
  }
+#endif /* TARGET_RISCV64 */
 
  static bool gen_store(DisasContext *ctx, arg_sb *a, int memop)
  {
@@ -216,14 +210,12 @@ static bool trans_sw(DisasContext *ctx, arg_sw *a)
      return gen_store(ctx, a, MO_TESL);
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_sd(DisasContext *ctx, arg_sd *a)
  {
-#ifdef TARGET_RISCV64
      return gen_store(ctx, a, MO_TEQ);
-#else
-    return false;
-#endif
  }
+#endif
 
  static bool trans_addi(DisasContext *ctx, arg_addi *a)
  {
@@ -387,20 +379,16 @@ static bool trans_and(DisasContext *ctx, arg_and *a)
      return gen_arith(ctx, a, &tcg_gen_and_tl);
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_addiw(DisasContext *ctx, arg_addiw *a)
  {
-#ifdef TARGET_RISCV64
      bool res = gen_arith_imm(ctx, a, &tcg_gen_add_tl);
      tcg_gen_ext32s_tl(cpu_gpr[a->rd], cpu_gpr[a->rd]);
      return res;
-#else
-    return false;
-#endif
  }
 
  static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
  {
-#ifdef TARGET_RISCV64
      TCGv source1;
      source1 = tcg_temp_new();
      gen_get_gpr(source1, a->rs1);
@@ -411,14 +399,10 @@ static bool trans_slliw(DisasContext *ctx, arg_slliw *a)
 
      tcg_temp_free(source1);
      return true;
-#else
-    return false;
-#endif
  }
 
  static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
  {
-#ifdef TARGET_RISCV64
      TCGv t = tcg_temp_new();
      gen_get_gpr(t, a->rs1);
      tcg_gen_extract_tl(t, t, a->shamt, 32 - a->shamt);
@@ -427,14 +411,10 @@ static bool trans_srliw(DisasContext *ctx, arg_srliw *a)
      gen_set_gpr(a->rd, t);
      tcg_temp_free(t);
      return true;
-#else
-    return false;
-#endif
  }
 
  static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
  {
-#ifdef TARGET_RISCV64
      TCGv t = tcg_temp_new();
      gen_get_gpr(t, a->rs1);
      tcg_gen_sextract_tl(t, t, a->shamt, 32 - a->shamt);
@@ -443,32 +423,20 @@ static bool trans_sraiw(DisasContext *ctx, arg_sraiw *a)
      gen_set_gpr(a->rd, t);
      tcg_temp_free(t);
      return true;
-#else
-    return false;
-#endif
  }
 
  static bool trans_addw(DisasContext *ctx, arg_addw *a)
  {
-#if !defined(TARGET_RISCV64)
-    return false;
-#endif
      return gen_arith(ctx, a, &tcg_gen_add_tl);
  }
 
  static bool trans_subw(DisasContext *ctx, arg_subw *a)
  {
-#if !defined(TARGET_RISCV64)
-    return false;
-#endif
      return gen_arith(ctx, a, &tcg_gen_sub_tl);
  }
 
  static bool trans_sllw(DisasContext *ctx, arg_sllw *a)
  {
-#if !defined(TARGET_RISCV64)
-    return false;
-#endif
      TCGv source1 = tcg_temp_new();
      TCGv source2 = tcg_temp_new();
 
@@ -486,9 +454,6 @@ static bool trans_sllw(DisasContext *ctx, arg_sllw *a)
 
  static bool trans_srlw(DisasContext *ctx, arg_srlw *a)
  {
-#if !defined(TARGET_RISCV64)
-    return false;
-#endif
      TCGv source1 = tcg_temp_new();
      TCGv source2 = tcg_temp_new();
 
@@ -508,9 +473,6 @@ static bool trans_srlw(DisasContext *ctx, arg_srlw *a)
 
  static bool trans_sraw(DisasContext *ctx, arg_sraw *a)
  {
-#if !defined(TARGET_RISCV64)
-    return false;
-#endif
      TCGv source1 = tcg_temp_new();
      TCGv source2 = tcg_temp_new();
 
@@ -528,6 +490,7 @@ static bool trans_sraw(DisasContext *ctx, arg_sraw *a)
      tcg_temp_free(source2);
      return true;
  }
+#endif /* TARGET_RISCV64 */
 
  static bool trans_fence(DisasContext *ctx, arg_fence *a)
  {
target/riscv/insn_trans/trans_rvm.inc.c +2 -20
index 7809bcb187..ee0ff4deb9 100644
@@ -79,47 +79,29 @@ static bool trans_remu(DisasContext *ctx, arg_remu *a)
      return gen_arith(ctx, a, &gen_remu);
  }
 
+#ifdef TARGET_RISCV64
  static bool trans_mulw(DisasContext *ctx, arg_mulw *a)
  {
-#ifdef TARGET_RISCV64
      return gen_arith(ctx, a, &tcg_gen_mul_tl);
-#else
-    return false;
-#endif
  }
 
  static bool trans_divw(DisasContext *ctx, arg_divw *a)
  {
-#ifdef TARGET_RISCV64
      return gen_arith_w(ctx, a, &gen_div);
-#else
-    return false;
-#endif
  }
 
  static bool trans_divuw(DisasContext *ctx, arg_divuw *a)
  {
-#ifdef TARGET_RISCV64
      return gen_arith_w(ctx, a, &gen_divu);
-#else
-    return false;
-#endif
  }
 
  static bool trans_remw(DisasContext *ctx, arg_remw *a)
  {
-#ifdef TARGET_RISCV64
      return gen_arith_w(ctx, a, &gen_rem);
-#else
-    return false;
-#endif
  }
 
  static bool trans_remuw(DisasContext *ctx, arg_remuw *a)
  {
-#ifdef TARGET_RISCV64
      return gen_arith_w(ctx, a, &gen_remu);
-#else
-    return false;
-#endif
  }
+#endif /* TARGET_RISCV64 */
target/riscv/Makefile.objs +19 -4
index ec7326f1c7..45cc2e8c8a 100644
@@ -2,14 +2,29 @@ obj-y += translate.o op_helper.o helper.o cpu.o fpu_helper.o gdbstub.o pmp.o
 
  DECODETREE = $(SRC_PATH)/scripts/decodetree.py
 
-target/riscv/decode_insn32.inc.c: \
-  $(SRC_PATH)/target/riscv/insn32.decode $(DECODETREE)
+decode32-y = $(SRC_PATH)/target/riscv/insn32.decode
+decode32-$(TARGET_RISCV64) += $(SRC_PATH)/target/riscv/insn64.decode
+
+decode16-y = $(SRC_PATH)/target/riscv/insn16.decode
+decode16-$(TARGET_RISCV32) += $(SRC_PATH)/target/riscv/insn16-32.decode
+decode16-$(TARGET_RISCV64) += $(SRC_PATH)/target/riscv/insn16-64.decode
+
+target/riscv/insn32.decode: $(decode32-y)
+	$(call quiet-command, \
+	  cat $(decode32-y) > target/riscv/insn32.decode, \
+          "CAT", $(TARGET_DIR)$@)
+
+target/riscv/insn16.decode: $(decode16-y)
+	$(call quiet-command, \
+	  cat $(decode16-y) > target/riscv/insn16.decode, \
+          "CAT", $(TARGET_DIR)$@)
+
+target/riscv/decode_insn32.inc.c: target/riscv/insn32.decode $(DECODETREE)
  	$(call quiet-command, \
  	  $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn32 $<, \
  	  "GEN", $(TARGET_DIR)$@)
 
-target/riscv/decode_insn16.inc.c: \
-  $(SRC_PATH)/target/riscv/insn16.decode $(DECODETREE)
+target/riscv/decode_insn16.inc.c: target/riscv/insn16.decode $(DECODETREE)
  	$(call quiet-command, \
  	  $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn16 --insnwidth 16 $<, \
  	  "GEN", $(TARGET_DIR)$@)
target/riscv/insn16-32.decode new file +31 -0
new file mode 100644
index 0000000000..efb7f5bdc8
@@ -0,0 +1,31 @@
+#
+# RISC-V translation routines for the RVC Instruction Set.
+#
+# Copyright (c) 2018 Peer Adelt, [email protected]
+#                    Bastian Koppelmann, [email protected]
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2 or later, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This is concatenated with insn16.decode for risc32 targets.
+# All of the fields and formats are there.
+
+# *** RV32C Standard Extension (Quadrant 0) ***
+flw     011 ... ... .. ... 00   @cl_w
+fsw     111 ... ... .. ... 00   @cs_w
+
+# *** RV32C Standard Extension (Quadrant 1) ***
+jal     001 ......   ..... 01   &j imm=%imm_cj rd=1
+
+# *** RV32C Standard Extension (Quadrant 2) ***
+flw     011 . .....  ..... 10   &i imm=%uimm_6bit_lw %rd rs1=2
+fsw     111 ......   ..... 10   &s imm=%uimm_6bit_sw rs2=%rs2_5 rs1=2
target/riscv/insn16-64.decode new file +33 -0
new file mode 100644
index 0000000000..163fd5014a
@@ -0,0 +1,33 @@
+#
+# RISC-V translation routines for the RVC Instruction Set.
+#
+# Copyright (c) 2018 Peer Adelt, [email protected]
+#                    Bastian Koppelmann, [email protected]
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2 or later, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This is concatenated with insn16.decode for risc64 targets.
+# All of the fields and formats are there.
+
+# *** RV64C Standard Extension (Quadrant 0) ***
+ld      011  ... ... .. ... 00 @cl_d
+sd      111  ... ... .. ... 00 @cs_d
+
+# *** RV64C Standard Extension (Quadrant 1) ***
+addiw   001 .  .....  ..... 01 @ci
+subw              100 1 11 ... 00 ... 01 @cs_2
+addw              100 1 11 ... 01 ... 01 @cs_2
+
+# *** RV64C Standard Extension (Quadrant 2) ***
+ld      011 .  .....  ..... 10 &i imm=%uimm_6bit_ld %rd rs1=2
+sd      111 .  .....  ..... 10 &s imm=%uimm_6bit_sw rs2=%rs2_5 rs1=2
target/riscv/insn16.decode +6 -18
index 73b385ad19..345629b649 100644
@@ -42,6 +42,7 @@
  # Argument sets imported from insn32.decode:
  &r         rd rs1 rs2   !extern
  &i         imm rs1 rd   !extern
+&j         imm rd       !extern
  &s         imm rs1 rs2  !extern
 
  # Argument sets:
@@ -64,12 +65,10 @@
 
  # Formats 16:
  @cr        ....  ..... .....  .. &cr                      rs2=%rs2_5  %rd
-@ci        ... . ..... .....  .. &ci     imm=%imm_ci                  %rd
+@ci        ... . ..... .....  .. &i  imm=%imm_ci %rd rs1=%rd
  @ciw       ...   ........ ... .. &ciw    nzuimm=%nzuimm_ciw           rd=%rs2_3
  @cl_d      ... ... ... .. ... .. &i  imm=%uimm_cl_d  rs1=%rs1_3  rd=%rs2_3
  @cl_w      ... ... ... .. ... .. &i  imm=%uimm_cl_w  rs1=%rs1_3  rd=%rs2_3
-@cl        ... ... ... .. ... .. &cl                      rs1=%rs1_3  rd=%rs2_3
-@cs        ... ... ... .. ... .. &cs                      rs1=%rs1_3  rs2=%rs2_3
  @cs_2      ... ... ... .. ... .. &r      rd=%rs1_3 rs1=%rs1_3 rs2=%rs2_3
  @cs_d      ... ... ... .. ... .. &s  imm=%uimm_cl_d  rs1=%rs1_3  rs2=%rs2_3
  @cs_w      ... ... ... .. ... .. &s  imm=%uimm_cl_w  rs1=%rs1_3  rs2=%rs2_3
@@ -82,28 +81,21 @@
  @c_sw      ... . .....  ..... .. &c_sd     uimm=%uimm_6bit_sw  rs2=%rs2_5
 
  @c_addi16sp_lui ... .  ..... ..... .. &c_addi16sp_lui %imm_lui %imm_addi16sp %rd
-@c_flwsp_ldsp   ... .  ..... ..... .. &c_flwsp_ldsp uimm_flwsp=%uimm_6bit_lw \
-    uimm_ldsp=%uimm_6bit_ld %rd
-@c_fswsp_sdsp   ... .  ..... ..... .. &c_fswsp_sdsp uimm_fswsp=%uimm_6bit_sw \
-    uimm_sdsp=%uimm_6bit_sd rs2=%rs2_5
 
  @c_shift        ... . .. ... ..... .. &c_shift rd=%rs1_3 shamt=%nzuimm_6bit
  @c_shift2       ... . .. ... ..... .. &c_shift rd=%rd    shamt=%nzuimm_6bit
 
-@c_andi         ... . .. ... ..... .. &ci imm=%imm_ci rd=%rs1_3
+@c_andi         ... . .. ... ..... .. &i imm=%imm_ci rd=%rs1_3 rs1=%rs1_3
 
-# *** RV64C Standard Extension (Quadrant 0) ***
+# *** RVC Standard Extension (Quadrant 0) ***
  c_addi4spn        000    ........ ... 00 @ciw
  fld               001  ... ... .. ... 00 @cl_d
  lw                010  ... ... .. ... 00 @cl_w
-c_flw_ld          011  --- ... -- ... 00 @cl    #Note: Must parse uimm manually
  fsd               101  ... ... .. ... 00 @cs_d
  sw                110  ... ... .. ... 00 @cs_w
-c_fsw_sd          111  --- ... -- ... 00 @cs    #Note: Must parse uimm manually
 
-# *** RV64C Standard Extension (Quadrant 1) ***
+# *** RVC Standard Extension (Quadrant 1) ***
  c_addi            000 .  .....  ..... 01 @ci
-c_jal_addiw       001 .  .....  ..... 01 @ci #Note: parse rd and/or imm manually
  c_li              010 .  .....  ..... 01 @ci
  c_addi16sp_lui    011 .  .....  ..... 01 @c_addi16sp_lui # shares opc with C.LUI
  c_srli            100 . 00 ...  ..... 01 @c_shift
@@ -113,19 +105,15 @@ sub               100 0 11 ... 00 ... 01 @cs_2
  xor               100 0 11 ... 01 ... 01 @cs_2
  or                100 0 11 ... 10 ... 01 @cs_2
  and               100 0 11 ... 11 ... 01 @cs_2
-subw              100 1 11 ... 00 ... 01 @cs_2
-addw              100 1 11 ... 01 ... 01 @cs_2
  c_j               101     ........... 01 @cj
  c_beqz            110  ... ...  ..... 01 @cb
  c_bnez            111  ... ...  ..... 01 @cb
 
-# *** RV64C Standard Extension (Quadrant 2) ***
+# *** RVC Standard Extension (Quadrant 2) ***
  c_slli            000 .  .....  ..... 10 @c_shift2
  c_fldsp           001 .  .....  ..... 10 @c_ld
  c_lwsp            010 .  .....  ..... 10 @c_lw
-c_flwsp_ldsp      011 .  .....  ..... 10 @c_flwsp_ldsp #C.LDSP:RV64;C.FLWSP:RV32
  c_jr_mv           100 0  .....  ..... 10 @cr
  c_ebreak_jalr_add 100 1  .....  ..... 10 @cr
  c_fsdsp           101   ......  ..... 10 @c_sd
  c_swsp            110 .  .....  ..... 10 @c_sw
-c_fswsp_sdsp      111 .  .....  ..... 10 @c_fswsp_sdsp #C.SDSP:RV64;C.FSWSP:RV32
target/riscv/insn32.decode +2 -51
index e1fccc57c6..7fcc9a3074 100644
@@ -23,7 +23,6 @@
  %rd        7:5
 
  %sh6    20:6
-%sh5    20:5
  %csr    20:12
  %rm     12:3
 
@@ -40,6 +39,7 @@
  # Argument sets:
  &b         imm rs2 rs1
  &i         imm rs1 rd
+&j         imm rd
  &s         imm rs2 rs1
  &r         rd rs1 rs2
  &shift     shamt rs1 rd
@@ -52,10 +52,9 @@
  @b       .......   ..... ..... ... ..... ....... &b    imm=%imm_b %rs2 %rs1
  @s       .......   ..... ..... ... ..... ....... &s    imm=%imm_s %rs2 %rs1
  @u       ....................      ..... .......         imm=%imm_u          %rd
-@j       ....................      ..... .......         imm=%imm_j          %rd
+@j       ....................      ..... ....... &j      imm=%imm_j          %rd
 
  @sh6     ......  ...... .....  ... ..... ....... &shift  shamt=%sh6      %rs1 %rd
-@sh5     .......  ..... .....  ... ..... ....... &shift  shamt=%sh5      %rs1 %rd
  @csr     ............   .....  ... ..... .......               %csr     %rs1 %rd
 
  @atom_ld ..... aq:1 rl:1 ..... ........ ..... ....... &atomic rs2=0     %rs1 %rd
@@ -129,20 +128,6 @@ csrrsi   ............     ..... 110 ..... 1110011 @csr
  csrrci   ............     ..... 111 ..... 1110011 @csr
 
 
-# *** RV64I Base Instruction Set (in addition to RV32I) ***
-lwu      ............   ..... 110 ..... 0000011 @i
-ld       ............   ..... 011 ..... 0000011 @i
-sd       ....... .....  ..... 011 ..... 0100011 @s
-addiw    ............   ..... 000 ..... 0011011 @i
-slliw    0000000 .....  ..... 001 ..... 0011011 @sh5
-srliw    0000000 .....  ..... 101 ..... 0011011 @sh5
-sraiw    0100000 .....  ..... 101 ..... 0011011 @sh5
-addw     0000000 .....  ..... 000 ..... 0111011 @r
-subw     0100000 .....  ..... 000 ..... 0111011 @r
-sllw     0000000 .....  ..... 001 ..... 0111011 @r
-srlw     0000000 .....  ..... 101 ..... 0111011 @r
-sraw     0100000 .....  ..... 101 ..... 0111011 @r
-
  # *** RV32M Standard Extension ***
  mul      0000001 .....  ..... 000 ..... 0110011 @r
  mulh     0000001 .....  ..... 001 ..... 0110011 @r
@@ -153,13 +138,6 @@ divu     0000001 .....  ..... 101 ..... 0110011 @r
  rem      0000001 .....  ..... 110 ..... 0110011 @r
  remu     0000001 .....  ..... 111 ..... 0110011 @r
 
-# *** RV64M Standard Extension (in addition to RV32M) ***
-mulw     0000001 .....  ..... 000 ..... 0111011 @r
-divw     0000001 .....  ..... 100 ..... 0111011 @r
-divuw    0000001 .....  ..... 101 ..... 0111011 @r
-remw     0000001 .....  ..... 110 ..... 0111011 @r
-remuw    0000001 .....  ..... 111 ..... 0111011 @r
-
  # *** RV32A Standard Extension ***
  lr_w       00010 . . 00000 ..... 010 ..... 0101111 @atom_ld
  sc_w       00011 . . ..... ..... 010 ..... 0101111 @atom_st
@@ -173,19 +151,6 @@ amomax_w   10100 . . ..... ..... 010 ..... 0101111 @atom_st
  amominu_w  11000 . . ..... ..... 010 ..... 0101111 @atom_st
  amomaxu_w  11100 . . ..... ..... 010 ..... 0101111 @atom_st
 
-# *** RV64A Standard Extension (in addition to RV32A) ***
-lr_d       00010 . . 00000 ..... 011 ..... 0101111 @atom_ld
-sc_d       00011 . . ..... ..... 011 ..... 0101111 @atom_st
-amoswap_d  00001 . . ..... ..... 011 ..... 0101111 @atom_st
-amoadd_d   00000 . . ..... ..... 011 ..... 0101111 @atom_st
-amoxor_d   00100 . . ..... ..... 011 ..... 0101111 @atom_st
-amoand_d   01100 . . ..... ..... 011 ..... 0101111 @atom_st
-amoor_d    01000 . . ..... ..... 011 ..... 0101111 @atom_st
-amomin_d   10000 . . ..... ..... 011 ..... 0101111 @atom_st
-amomax_d   10100 . . ..... ..... 011 ..... 0101111 @atom_st
-amominu_d  11000 . . ..... ..... 011 ..... 0101111 @atom_st
-amomaxu_d  11100 . . ..... ..... 011 ..... 0101111 @atom_st
-
  # *** RV32F Standard Extension ***
  flw        ............   ..... 010 ..... 0000111 @i
  fsw        .......  ..... ..... 010 ..... 0100111 @s
@@ -214,12 +179,6 @@ fcvt_s_w   1101000  00000 ..... ... ..... 1010011 @r2_rm
  fcvt_s_wu  1101000  00001 ..... ... ..... 1010011 @r2_rm
  fmv_w_x    1111000  00000 ..... 000 ..... 1010011 @r2
 
-# *** RV64F Standard Extension (in addition to RV32F) ***
-fcvt_l_s   1100000  00010 ..... ... ..... 1010011 @r2_rm
-fcvt_lu_s  1100000  00011 ..... ... ..... 1010011 @r2_rm
-fcvt_s_l   1101000  00010 ..... ... ..... 1010011 @r2_rm
-fcvt_s_lu  1101000  00011 ..... ... ..... 1010011 @r2_rm
-
  # *** RV32D Standard Extension ***
  fld        ............   ..... 011 ..... 0000111 @i
  fsd        ....... .....  ..... 011 ..... 0100111 @s
@@ -247,11 +206,3 @@ fcvt_w_d   1100001  00000 ..... ... ..... 1010011 @r2_rm
  fcvt_wu_d  1100001  00001 ..... ... ..... 1010011 @r2_rm
  fcvt_d_w   1101001  00000 ..... ... ..... 1010011 @r2_rm
  fcvt_d_wu  1101001  00001 ..... ... ..... 1010011 @r2_rm
-
-# *** RV64D Standard Extension (in addition to RV32D) ***
-fcvt_l_d   1100001  00010 ..... ... ..... 1010011 @r2_rm
-fcvt_lu_d  1100001  00011 ..... ... ..... 1010011 @r2_rm
-fmv_x_d    1110001  00000 ..... 000 ..... 1010011 @r2
-fcvt_d_l   1101001  00010 ..... ... ..... 1010011 @r2_rm
-fcvt_d_lu  1101001  00011 ..... ... ..... 1010011 @r2_rm
-fmv_d_x    1111001  00000 ..... 000 ..... 1010011 @r2
target/riscv/insn64.decode new file +71 -0
new file mode 100644
index 0000000000..92ac363a11
@@ -0,0 +1,71 @@
+#
+# RISC-V translation routines for the RV Instruction Set.
+#
+# Copyright (c) 2018 Peer Adelt, [email protected]
+#                    Bastian Koppelmann, [email protected]
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2 or later, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# This is concatenated with insn32.decode for risc64 targets.
+# Most of the fields and formats are there.
+
+%sh5    20:5
+@sh5     .......  ..... .....  ... ..... ....... &shift shamt=%sh5 %rs1 %rd
+
+# *** RV64I Base Instruction Set (in addition to RV32I) ***
+lwu      ............   ..... 110 ..... 0000011 @i
+ld       ............   ..... 011 ..... 0000011 @i
+sd       ....... .....  ..... 011 ..... 0100011 @s
+addiw    ............   ..... 000 ..... 0011011 @i
+slliw    0000000 .....  ..... 001 ..... 0011011 @sh5
+srliw    0000000 .....  ..... 101 ..... 0011011 @sh5
+sraiw    0100000 .....  ..... 101 ..... 0011011 @sh5
+addw     0000000 .....  ..... 000 ..... 0111011 @r
+subw     0100000 .....  ..... 000 ..... 0111011 @r
+sllw     0000000 .....  ..... 001 ..... 0111011 @r
+srlw     0000000 .....  ..... 101 ..... 0111011 @r
+sraw     0100000 .....  ..... 101 ..... 0111011 @r
+
+# *** RV64M Standard Extension (in addition to RV32M) ***
+mulw     0000001 .....  ..... 000 ..... 0111011 @r
+divw     0000001 .....  ..... 100 ..... 0111011 @r
+divuw    0000001 .....  ..... 101 ..... 0111011 @r
+remw     0000001 .....  ..... 110 ..... 0111011 @r
+remuw    0000001 .....  ..... 111 ..... 0111011 @r
+
+# *** RV64A Standard Extension (in addition to RV32A) ***
+lr_d       00010 . . 00000 ..... 011 ..... 0101111 @atom_ld
+sc_d       00011 . . ..... ..... 011 ..... 0101111 @atom_st
+amoswap_d  00001 . . ..... ..... 011 ..... 0101111 @atom_st
+amoadd_d   00000 . . ..... ..... 011 ..... 0101111 @atom_st
+amoxor_d   00100 . . ..... ..... 011 ..... 0101111 @atom_st
+amoand_d   01100 . . ..... ..... 011 ..... 0101111 @atom_st
+amoor_d    01000 . . ..... ..... 011 ..... 0101111 @atom_st
+amomin_d   10000 . . ..... ..... 011 ..... 0101111 @atom_st
+amomax_d   10100 . . ..... ..... 011 ..... 0101111 @atom_st
+amominu_d  11000 . . ..... ..... 011 ..... 0101111 @atom_st
+amomaxu_d  11100 . . ..... ..... 011 ..... 0101111 @atom_st
+
+# *** RV64F Standard Extension (in addition to RV32F) ***
+fcvt_l_s   1100000  00010 ..... ... ..... 1010011 @r2_rm
+fcvt_lu_s  1100000  00011 ..... ... ..... 1010011 @r2_rm
+fcvt_s_l   1101000  00010 ..... ... ..... 1010011 @r2_rm
+fcvt_s_lu  1101000  00011 ..... ... ..... 1010011 @r2_rm
+
+# *** RV64D Standard Extension (in addition to RV32D) ***
+fcvt_l_d   1100001  00010 ..... ... ..... 1010011 @r2_rm
+fcvt_lu_d  1100001  00011 ..... ... ..... 1010011 @r2_rm
+fmv_x_d    1110001  00000 ..... 000 ..... 1010011 @r2
+fcvt_d_l   1101001  00010 ..... ... ..... 1010011 @r2_rm
+fcvt_d_lu  1101001  00011 ..... ... ..... 1010011 @r2_rm
+fmv_d_x    1111001  00000 ..... 000 ..... 1010011 @r2
#26 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/riscv: Splice decodetree inputs for riscv32 vs riscv64

In reply to Richard Henderson
Quoted 17 lines · Richard Henderson

This primarily solves the case for RVC that several insns are completely different, decode and all, between the two. But it also means that we need less ifdefing for RV{I,M,A,F,D}.

---
  target/riscv/insn_trans/trans_rva.inc.c | 46 +---------------
  target/riscv/insn_trans/trans_rvc.inc.c | 71 -------------------------
  target/riscv/insn_trans/trans_rvd.inc.c | 26 +--------
  target/riscv/insn_trans/trans_rvf.inc.c | 18 +------
  target/riscv/insn_trans/trans_rvi.inc.c | 49 +++--------------
  target/riscv/insn_trans/trans_rvm.inc.c | 22 +-------
  target/riscv/Makefile.objs              | 23 ++++++--
  target/riscv/insn16-32.decode           | 31 +++++++++++
  target/riscv/insn16-64.decode           | 33 ++++++++++++
  target/riscv/insn16.decode              | 24 +++------
  target/riscv/insn32.decode              | 53 +-----------------
  target/riscv/insn64.decode              | 71 +++++++++++++++++++++++++
  12 files changed, 176 insertions(+), 291 deletions(-)
Quoted 4 lines

create mode 100644 target/riscv/insn16-32.decode create mode 100644 target/riscv/insn16-64.decode create mode 100644 target/riscv/insn64.decode

Either this or one of the last two patches breaks booting fedora. I couldn't figure the problem out just yet.

Cheers,

Bastian

#27 lore raw

Re: [Qemu-devel] [PATCH 7/7] target/riscv: Splice decodetree inputs for riscv32 vs riscv64

Quoted 3 lines · Bastian Koppelmann

On 10/23/18 2:04 PM, Richard Henderson wrote:
Either this or one of the last two patches breaks booting fedora. I couldn't figure the problem out just yet.

I didn't do any testing on it, and may well have messed something up in the process. (I have not yet downloaded any images with which to do such testing either.)

My main purpose was as proof of concept, in that the process can be set up in a way that has some advantages. I was assuming already that you'd go back and work in some adjustments into your original patches, not that you'd take mine as-is.

r~