@samitouri / QOSamiQemu / commits / 59acf4d4e1

disas/riscv: Merge all c.mop.n to one pattern

Avoid performing arithmetic on rv_op_c_mop_1. Treat the 'n' as an immediate. Create a codec and format to match. Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260812223142.349142-49-richard.henderson@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Richard Henderson committed Aug 12, 2026 at 15:31 UTC 59acf4d4e1a723ebb57d008cdf68a2cc8aa72a65
3 files changed +12 -9
disas/riscv-op.c.inc
+1 -8
@@ -875,14 +875,7 @@ OP(amocas_d, "amocas.d", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
875 OP(amocas_q, "amocas.q", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
876 OP(mop_r, "mop.r", rv_codec_mop_r, rv_fmt_mop_r)
877 OP(mop_rr, "mop.rr", rv_codec_mop_rr, rv_fmt_mop_rr)
878 -OP(c_mop_1, "c.mop.1", rv_codec_ci_none, rv_fmt_none)
879 -OP(c_mop_3, "c.mop.3", rv_codec_ci_none, rv_fmt_none)
880 -OP(c_mop_5, "c.mop.5", rv_codec_ci_none, rv_fmt_none)
881 -OP(c_mop_7, "c.mop.7", rv_codec_ci_none, rv_fmt_none)
882 -OP(c_mop_9, "c.mop.9", rv_codec_ci_none, rv_fmt_none)
883 -OP(c_mop_11, "c.mop.11", rv_codec_ci_none, rv_fmt_none)
884 -OP(c_mop_13, "c.mop.13", rv_codec_ci_none, rv_fmt_none)
885 -OP(c_mop_15, "c.mop.15", rv_codec_ci_none, rv_fmt_none)
878 +OP(c_mop, "c.mop", rv_codec_cmop, rv_fmt_cmop)
879 OP(amoswap_b, "amoswap.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
880 OP(amoadd_b, "amoadd.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
881 OP(amoxor_b, "amoxor.b", rv_codec_r_a, rv_fmt_aqrl_rd_rs2_rs1)
disas/riscv.c
+9 -1
@@ -643,6 +643,11 @@ static uint32_t operand_lpl(rv_inst inst)
643 return extract32(inst, 12, 20);
644 }
645
646 +static uint32_t operand_cmop_imm(rv_inst inst)
647 +{
648 + return extract32(inst, 8, 3) * 2 + 1;
649 +}
650 +
651 static uint32_t operand_mop_r_imm(rv_inst inst)
652 {
653 return (extract32(inst, 30, 1) << 4) |
@@ -1027,7 +1032,7 @@ static const rv_opcode_data *decode_inst_opcode(rv_decode *dec, rv_isa isa)
1032 (((inst >> 11) & 0b11) == 0b0)) {
1033 unsigned int cmop_code = 0;
1034 cmop_code = ((inst >> 8) & 0b111);
1030 - op = rv_op_c_mop_1 + cmop_code;
1035 + op = rv_op_c_mop;
1036 if (dec->cfg->ext_zicfiss) {
1037 op = (cmop_code == 0) ? rv_op_c_sspush : op;
1038 op = (cmop_code == 2) ? rv_op_c_sspopchk : op;
@@ -3056,6 +3061,9 @@ static void decode_inst_operands(rv_decode *dec, rv_isa isa,
3061 case rv_codec_lp:
3062 dec->imm = operand_lpl(inst);
3063 break;
3064 + case rv_codec_cmop:
3065 + dec->imm = operand_cmop_imm(inst);
3066 + break;
3067 case rv_codec_cmop_ss:
3068 dec->rd = rv_ireg_zero;
3069 dec->rs1 = dec->rs2 = operand_crs1(inst);
disas/riscv.h
+2
@@ -159,6 +159,7 @@ typedef enum {
159 rv_codec_r2_imm2_imm5,
160 rv_codec_fli,
161 rv_codec_lp,
162 + rv_codec_cmop,
163 rv_codec_cmop_ss,
164 rv_codec_mop_r,
165 rv_codec_mop_rr,
@@ -286,6 +287,7 @@ typedef struct {
287 #define rv_fmt_rd_rs1_immh_imml_addr "O\t0,(1),i,j"
288 #define rv_fmt_rd2_imm "O\t0,2,(1),i"
289 #define rv_fmt_fli "O\t3,h"
290 +#define rv_fmt_cmop "O.i"
291 #define rv_fmt_mop_r "O.i\t0,1"
292 #define rv_fmt_mop_rr "O.i\t0,1,2"
293