@samitouri / QOSamiQemu / commits / ef25a26b7d

disas/riscv: Tidy decode of mop.r.n and mop.rr.n

Merge nested if's. Reuse operand_mop_{r,rr}_imm for zicfiss decode. Return pointers directly. Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260812223142.349142-51-richard.henderson@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Richard Henderson committed Aug 12, 2026 at 15:31 UTC ef25a26b7dc29ba4b78a70d22a6a806dd4637537
1 file changed +24 -35
disas/riscv.c
+24 -35
@@ -2555,44 +2555,33 @@ static const rv_opcode_data *decode_inst_opcode(rv_decode *dec, rv_isa isa)
2555 case 3: op = rv_op_csrrc; break;
2556 case 4:
2557 if (dec->cfg && dec->cfg->ext_zimop) {
2558 - int imm_mop5, imm_mop3, reg_num;
2559 - if ((extract32(inst, 22, 10) & 0b1011001111)
2560 - == 0b1000000111) {
2561 - imm_mop5 = deposit32(deposit32(extract32(inst, 20, 2),
2562 - 2, 2,
2563 - extract32(inst, 26, 2)),
2564 - 4, 1, extract32(inst, 30, 1));
2565 - op = rv_op_mop_r;
2566 - /* if zicfiss enabled and mop5 is shadow stack */
2567 - if (dec->cfg->ext_zicfiss &&
2568 - ((imm_mop5 & 0b11100) == 0b11100)) {
2569 - /* rs1=0 means ssrdp */
2570 - if ((inst & (0b011111 << 15)) == 0) {
2571 - op = rv_op_ssrdp;
2572 - }
2573 - /* rd=0 means sspopchk */
2574 - reg_num = (inst >> 15) & 0b011111;
2575 - if (((inst & (0b011111 << 7)) == 0) &&
2576 - ((reg_num == 1) || (reg_num == 5))) {
2577 - op = rv_op_sspopchk;
2558 + if (((inst >> 22) & 0b1011001111) == 0b1000000111) {
2559 + if (dec->cfg->ext_zicfiss
2560 + && operand_mop_r_imm(inst) == 28) {
2561 + switch (operand_rs1(inst)) {
2562 + case 0:
2563 + return &rvi_opcode_data[rv_op_ssrdp];
2564 + case 1:
2565 + case 5:
2566 + if (operand_rd(inst) == 0) {
2567 + return &rvi_opcode_data[rv_op_sspopchk];
2568 }
2569 + }
2570 }
2580 - } else if ((extract32(inst, 25, 7) & 0b1011001)
2581 - == 0b1000001) {
2582 - imm_mop3 = deposit32(extract32(inst, 26, 2),
2583 - 2, 1, extract32(inst, 30, 1));
2584 - op = rv_op_mop_rr;
2585 - /* if zicfiss enabled and mop3 is shadow stack */
2586 - if (dec->cfg->ext_zicfiss &&
2587 - ((imm_mop3 & 0b111) == 0b111)) {
2588 - /* rs1=0 and rd=0 means sspush */
2589 - reg_num = (inst >> 20) & 0b011111;
2590 - if (((inst & (0b011111 << 15)) == 0) &&
2591 - ((inst & (0b011111 << 7)) == 0) &&
2592 - ((reg_num == 1) || (reg_num == 5))) {
2593 - op = rv_op_sspush;
2594 - }
2571 + return &rvi_opcode_data[rv_op_mop_r];
2572 + }
2573 + if (((inst >> 25) & 0b1011001) == 0b1000001) {
2574 + if (dec->cfg->ext_zicfiss
2575 + && operand_mop_rr_imm(inst) == 7
2576 + && operand_rd(inst) == 0
2577 + && operand_rs1(inst) == 0) {
2578 + switch (operand_rs2(inst)) {
2579 + case 1:
2580 + case 5:
2581 + return &rvi_opcode_data[rv_op_sspush];
2582 + }
2583 }
2584 + return &rvi_opcode_data[rv_op_mop_rr];
2585 }
2586 }
2587 break;