@samitouri / QOSamiQemu / commits / 3d3abbb146

disas/riscv: Pass rv_opcode_data pointer to/from decode_inst_decompress

Unify 4 functions, sharing code. Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260812223142.349142-6-richard.henderson@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Richard Henderson committed Aug 12, 2026 at 15:30 UTC 3d3abbb1469756811f50811aca27883e30d00ac6
1 file changed +21 -49
disas/riscv.c
+21 -49
@@ -5377,64 +5377,36 @@ static void decode_inst_lift_pseudo(rv_decode *dec)
5377
5378 /* decompress instruction */
5379
5380 -static void decode_inst_decompress_rv32(rv_decode *dec)
5380 +static const rv_opcode_data *decode_inst_decompress(rv_decode *dec, rv_isa isa,
5381 + const rv_opcode_data *op)
5382 {
5382 - const rv_opcode_data *opcode_data = dec->opcode_data;
5383 - int decomp_op = opcode_data[dec->op].decomp_rv32;
5384 - if (decomp_op != rv_op_illegal) {
5385 - if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz)
5386 - && dec->imm == 0) {
5387 - dec->op = rv_op_illegal;
5388 - } else {
5389 - dec->op = decomp_op;
5390 - dec->codec = opcode_data[decomp_op].codec;
5391 - }
5392 - }
5393 -}
5394 -
5395 -static void decode_inst_decompress_rv64(rv_decode *dec)
5396 -{
5397 - const rv_opcode_data *opcode_data = dec->opcode_data;
5398 - int decomp_op = opcode_data[dec->op].decomp_rv64;
5399 - if (decomp_op != rv_op_illegal) {
5400 - if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz)
5401 - && dec->imm == 0) {
5402 - dec->op = rv_op_illegal;
5403 - } else {
5404 - dec->op = decomp_op;
5405 - dec->codec = opcode_data[decomp_op].codec;
5406 - }
5407 - }
5408 -}
5383 + int decomp_op;
5384
5410 -static void decode_inst_decompress_rv128(rv_decode *dec)
5411 -{
5412 - const rv_opcode_data *opcode_data = dec->opcode_data;
5413 - int decomp_op = opcode_data[dec->op].decomp_rv128;
5414 - if (decomp_op != rv_op_illegal) {
5415 - if ((opcode_data[dec->op].decomp_data & rvcd_imm_nz)
5416 - && dec->imm == 0) {
5417 - dec->op = rv_op_illegal;
5418 - } else {
5419 - dec->op = decomp_op;
5420 - dec->codec = opcode_data[decomp_op].codec;
5421 - }
5422 - }
5423 -}
5424 -
5425 -static void decode_inst_decompress(rv_decode *dec, rv_isa isa)
5426 -{
5385 switch (isa) {
5386 case rv32:
5429 - decode_inst_decompress_rv32(dec);
5387 + decomp_op = op->decomp_rv32;
5388 break;
5389 case rv64:
5432 - decode_inst_decompress_rv64(dec);
5390 + decomp_op = op->decomp_rv64;
5391 break;
5392 case rv128:
5435 - decode_inst_decompress_rv128(dec);
5393 + decomp_op = op->decomp_rv128;
5394 break;
5395 + default:
5396 + g_assert_not_reached();
5397 + }
5398 +
5399 + if (decomp_op != rv_op_illegal) {
5400 + if ((op->decomp_data & rvcd_imm_nz) && dec->imm == 0) {
5401 + dec->opcode_data = rvi_opcode_data;
5402 + dec->op = rv_op_illegal;
5403 + } else {
5404 + dec->op = decomp_op;
5405 + }
5406 + op = &dec->opcode_data[decomp_op];
5407 + dec->codec = op->codec;
5408 }
5409 + return op;
5410 }
5411
5412 /* disassemble instruction */
@@ -5491,7 +5463,7 @@ static GString *disasm_inst(rv_isa isa, uint64_t pc, rv_inst inst,
5463
5464 op = &dec.opcode_data[dec.op];
5465 decode_inst_operands(&dec, isa, op);
5494 - decode_inst_decompress(&dec, isa);
5466 + op = decode_inst_decompress(&dec, isa, op);
5467 decode_inst_lift_pseudo(&dec);
5468 return format_inst(24, &dec);
5469 }