Re: [PATCH 50/56] disas/riscv: Merge all mop.r.n to one pattern

Alistair <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.nongnu.qemu-devel
Message-ID <[email protected]>
On Sun, 2026-08-09 at 15:35 -0700, Richard Henderson wrote:
> Avoid performing arithmetic on rv_op_mop_r_0.
> Treat the 'n' as an immediate.
> Create a codec and format to match.
> 
> Signed-off-by: Richard Henderson <[email protected]>

Reviewed-by: Alistair Francis <[email protected]>

Alistair

> ---
>  disas/riscv.h        |  2 ++
>  disas/riscv.c        | 15 ++++++++++++++-
>  disas/riscv-op.c.inc | 33 +--------------------------------
>  3 files changed, 17 insertions(+), 33 deletions(-)
> 
> diff --git a/disas/riscv.h b/disas/riscv.h
> index 5ac8c41616..b47a7f0150 100644
> --- a/disas/riscv.h
> +++ b/disas/riscv.h
> @@ -160,6 +160,7 @@ typedef enum {
>      rv_codec_fli,
>      rv_codec_lp,
>      rv_codec_cmop_ss,
> +    rv_codec_mop_r,
>  } rv_codec;
>  
>  /* structures */
> @@ -284,5 +285,6 @@ typedef struct {
>  #define rv_fmt_rd_rs1_immh_imml_addr  "O\t0,(1),i,j"
>  #define rv_fmt_rd2_imm                "O\t0,2,(1),i"
>  #define rv_fmt_fli                    "O\t3,h"
> +#define rv_fmt_mop_r                  "O.i\t0,1"
>  
>  #endif /* DISAS_RISCV_H */
> diff --git a/disas/riscv.c b/disas/riscv.c
> index 9dad56b486..450a5c8142 100644
> --- a/disas/riscv.c
> +++ b/disas/riscv.c
> @@ -643,6 +643,13 @@ static uint32_t operand_lpl(rv_inst inst)
>      return extract32(inst, 12, 20);
>  }
>  
> +static uint32_t operand_mop_r_imm(rv_inst inst)
> +{
> +    return (extract32(inst, 30, 1) << 4) |
> +           (extract32(inst, 26, 2) << 2) |
> +           extract32(inst, 20, 2);
> +}
> +
>  /* instruction metadata */
>  
>  static const rv_opcode_data rvi_opcode_data[] = {
> @@ -2546,7 +2553,7 @@ static const rv_opcode_data
> *decode_inst_opcode(rv_decode *dec, rv_isa isa)
>                                                         2, 2,
>                                                        
> extract32(inst, 26, 2)),
>                                               4, 1, extract32(inst,
> 30, 1));
> -                        op = rv_op_mop_r_0 + imm_mop5;
> +                        op = rv_op_mop_r;
>                          /* if zicfiss enabled and mop5 is shadow
> stack */
>                          if (dec->cfg->ext_zicfiss &&
>                              ((imm_mop5 & 0b11100) == 0b11100)) {
> @@ -3049,6 +3056,11 @@ static void decode_inst_operands(rv_decode
> *dec, rv_isa isa,
>          dec->rs1 = dec->rs2 = operand_crs1(inst);
>          dec->imm = 0;
>          break;
> +    case rv_codec_mop_r:
> +        dec->rd = operand_rd(inst);
> +        dec->rs1 = operand_rs1(inst);
> +        dec->imm = operand_mop_r_imm(inst);
> +        break;
>      default:
>          g_assert_not_reached();
>      }
> @@ -3134,6 +3146,7 @@ static GString *format_inst(size_t tab,
> rv_decode *dec,
>              g_string_append(buf, op->name);
>              break;
>          case '(':
> +        case '.':
>          case ',':
>          case ')':
>          case '-':
> diff --git a/disas/riscv-op.c.inc b/disas/riscv-op.c.inc
> index 3fe934688e..222d249a70 100644
> --- a/disas/riscv-op.c.inc
> +++ b/disas/riscv-op.c.inc
> @@ -873,38 +873,7 @@ OP(vwsll_vi, "vwsll.vi", rv_codec_v_i_u,
> rv_fmt_vd_vs2_uimm_vm)
>  OP(amocas_w, "amocas.w", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
>  OP(amocas_d, "amocas.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
>  OP(amocas_q, "amocas.q", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
> -OP(mop_r_0, "mop.r.0", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_1, "mop.r.1", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_2, "mop.r.2", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_3, "mop.r.3", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_4, "mop.r.4", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_5, "mop.r.5", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_6, "mop.r.6", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_7, "mop.r.7", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_8, "mop.r.8", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_9, "mop.r.9", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_10, "mop.r.10", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_11, "mop.r.11", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_12, "mop.r.12", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_13, "mop.r.13", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_14, "mop.r.14", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_15, "mop.r.15", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_16, "mop.r.16", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_17, "mop.r.17", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_18, "mop.r.18", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_19, "mop.r.19", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_20, "mop.r.20", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_21, "mop.r.21", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_22, "mop.r.22", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_23, "mop.r.23", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_24, "mop.r.24", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_25, "mop.r.25", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_26, "mop.r.26", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_27, "mop.r.27", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_28, "mop.r.28", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_29, "mop.r.29", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_30, "mop.r.30", rv_codec_r, rv_fmt_rd_rs1)
> -OP(mop_r_31, "mop.r.31", rv_codec_r, rv_fmt_rd_rs1)
> +OP(mop_r, "mop.r", rv_codec_mop_r, rv_fmt_mop_r)
>  OP(mop_rr_0, "mop.rr.0", rv_codec_r, rv_fmt_rd_rs1_rs2)
>  OP(mop_rr_1, "mop.rr.1", rv_codec_r, rv_fmt_rd_rs1_rs2)
>  OP(mop_rr_2, "mop.rr.2", rv_codec_r, rv_fmt_rd_rs1_rs2)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.