disas/riscv: Tidy disasm_inst main loop
Unroll first iteration, so that always_true_p is not used, Drop some local variables and use 'decoders' directly. Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260812223142.349142-9-richard.henderson@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Richard Henderson committed
Aug 12, 2026 at 15:30 UTC
aae0ef66d463f9dd47624d249f975904a1ff2c0a
1 file changed
+32
-33
disas/riscv.c
+32
-33
@@ -5419,41 +5419,40 @@ static GString *disasm_inst(rv_isa isa, uint64_t pc, rv_inst inst,
5419
.inst = inst,
5420
.cfg = cfg,
5421
};
5422
-
5423
- static const struct {
5424
- bool (*guard_func)(const RISCVCPUConfig *);
5425
- const rv_opcode_data *opcode_data;
5426
- void (*decode_func)(rv_decode *, rv_isa);
5427
- } decoders[] = {
5428
- { always_true_p, rvi_opcode_data, decode_inst_opcode },
5429
- { has_xtheadba_p, xthead_opcode_data, decode_xtheadba },
5430
- { has_xtheadbb_p, xthead_opcode_data, decode_xtheadbb },
5431
- { has_xtheadbs_p, xthead_opcode_data, decode_xtheadbs },
5432
- { has_xtheadcmo_p, xthead_opcode_data, decode_xtheadcmo },
5433
- { has_xtheadcondmov_p, xthead_opcode_data, decode_xtheadcondmov },
5434
- { has_xtheadfmemidx_p, xthead_opcode_data, decode_xtheadfmemidx },
5435
- { has_xtheadfmv_p, xthead_opcode_data, decode_xtheadfmv },
5436
- { has_xtheadmac_p, xthead_opcode_data, decode_xtheadmac },
5437
- { has_xtheadmemidx_p, xthead_opcode_data, decode_xtheadmemidx },
5438
- { has_xtheadmempair_p, xthead_opcode_data, decode_xtheadmempair },
5439
- { has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
5440
- { has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
5441
- { has_xlrbr_p, rv_xlrbr_opcode_data, decode_xlrbr },
5442
- };
5443
-
5422
const rv_opcode_data *op;
5423
5446
- for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {
5447
- bool (*guard_func)(const RISCVCPUConfig *) = decoders[i].guard_func;
5448
- const rv_opcode_data *opcode_data = decoders[i].opcode_data;
5449
- void (*decode_func)(rv_decode *, rv_isa) = decoders[i].decode_func;
5450
-
5451
- /* always_true_p don't dereference cfg */
5452
- if (((i == 0) || cfg) && guard_func(cfg)) {
5453
- dec.opcode_data = opcode_data;
5454
- decode_func(&dec, isa);
5455
- if (dec.op != rv_op_illegal)
5456
- break;
5424
+ dec.opcode_data = rvi_opcode_data;
5425
+ decode_inst_opcode(&dec, isa);
5426
+
5427
+ if (dec.op == rv_op_illegal && cfg) {
5428
+ static const struct {
5429
+ bool (*guard_func)(const RISCVCPUConfig *);
5430
+ const rv_opcode_data *opcode_data;
5431
+ void (*decode_func)(rv_decode *, rv_isa);
5432
+ } decoders[] = {
5433
+ { has_xtheadba_p, xthead_opcode_data, decode_xtheadba },
5434
+ { has_xtheadbb_p, xthead_opcode_data, decode_xtheadbb },
5435
+ { has_xtheadbs_p, xthead_opcode_data, decode_xtheadbs },
5436
+ { has_xtheadcmo_p, xthead_opcode_data, decode_xtheadcmo },
5437
+ { has_xtheadcondmov_p, xthead_opcode_data, decode_xtheadcondmov },
5438
+ { has_xtheadfmemidx_p, xthead_opcode_data, decode_xtheadfmemidx },
5439
+ { has_xtheadfmv_p, xthead_opcode_data, decode_xtheadfmv },
5440
+ { has_xtheadmac_p, xthead_opcode_data, decode_xtheadmac },
5441
+ { has_xtheadmemidx_p, xthead_opcode_data, decode_xtheadmemidx },
5442
+ { has_xtheadmempair_p, xthead_opcode_data, decode_xtheadmempair },
5443
+ { has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
5444
+ { has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
5445
+ { has_xlrbr_p, rv_xlrbr_opcode_data, decode_xlrbr },
5446
+ };
5447
+
5448
+ for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {
5449
+ if (decoders[i].guard_func(cfg)) {
5450
+ dec.opcode_data = decoders[i].opcode_data;
5451
+ decoders[i].decode_func(&dec, isa);
5452
+ if (dec.op != rv_op_illegal) {
5453
+ break;
5454
+ }
5455
+ }
5456
}
5457
}
5458