On Sun, 2026-08-09 at 15:35 -0700, Richard Henderson wrote:
> Unroll first iteration, so that always_true_p is not used,
> Drop some local variables and use 'decoders' directly.
> 
> Signed-off-by: Richard Henderson <[email protected]>

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

Alistair

> ---
>  disas/riscv.c | 63 +++++++++++++++++++++++++------------------------
> --
>  1 file changed, 31 insertions(+), 32 deletions(-)
> 
> diff --git a/disas/riscv.c b/disas/riscv.c
> index 70ea41f125..9880b8de20 100644
> --- a/disas/riscv.c
> +++ b/disas/riscv.c
> @@ -5419,41 +5419,40 @@ static GString *disasm_inst(rv_isa isa,
> uint64_t pc, rv_inst inst,
>          .inst = inst,
>          .cfg = cfg,
>      };
> -
> -    static const struct {
> -        bool (*guard_func)(const RISCVCPUConfig *);
> -        const rv_opcode_data *opcode_data;
> -        void (*decode_func)(rv_decode *, rv_isa);
> -    } decoders[] = {
> -        { always_true_p, rvi_opcode_data, decode_inst_opcode },
> -        { has_xtheadba_p, xthead_opcode_data, decode_xtheadba },
> -        { has_xtheadbb_p, xthead_opcode_data, decode_xtheadbb },
> -        { has_xtheadbs_p, xthead_opcode_data, decode_xtheadbs },
> -        { has_xtheadcmo_p, xthead_opcode_data, decode_xtheadcmo },
> -        { has_xtheadcondmov_p, xthead_opcode_data,
> decode_xtheadcondmov },
> -        { has_xtheadfmemidx_p, xthead_opcode_data,
> decode_xtheadfmemidx },
> -        { has_xtheadfmv_p, xthead_opcode_data, decode_xtheadfmv },
> -        { has_xtheadmac_p, xthead_opcode_data, decode_xtheadmac },
> -        { has_xtheadmemidx_p, xthead_opcode_data,
> decode_xtheadmemidx },
> -        { has_xtheadmempair_p, xthead_opcode_data,
> decode_xtheadmempair },
> -        { has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
> -        { has_XVentanaCondOps_p, ventana_opcode_data,
> decode_xventanacondops },
> -        { has_xlrbr_p, rv_xlrbr_opcode_data, decode_xlrbr },
> -    };
> -
>      const rv_opcode_data *op;
>  
> -    for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {
> -        bool (*guard_func)(const RISCVCPUConfig *) =
> decoders[i].guard_func;
> -        const rv_opcode_data *opcode_data = decoders[i].opcode_data;
> -        void (*decode_func)(rv_decode *, rv_isa) =
> decoders[i].decode_func;
> +    dec.opcode_data = rvi_opcode_data;
> +    decode_inst_opcode(&dec, isa);
>  
> -        /* always_true_p don't dereference cfg */
> -        if (((i == 0) || cfg) && guard_func(cfg)) {
> -            dec.opcode_data = opcode_data;
> -            decode_func(&dec, isa);
> -            if (dec.op != rv_op_illegal)
> -                break;
> +    if (dec.op == rv_op_illegal && cfg) {
> +        static const struct {
> +            bool (*guard_func)(const RISCVCPUConfig *);
> +            const rv_opcode_data *opcode_data;
> +            void (*decode_func)(rv_decode *, rv_isa);
> +        } decoders[] = {
> +            { has_xtheadba_p, xthead_opcode_data, decode_xtheadba },
> +            { has_xtheadbb_p, xthead_opcode_data, decode_xtheadbb },
> +            { has_xtheadbs_p, xthead_opcode_data, decode_xtheadbs },
> +            { has_xtheadcmo_p, xthead_opcode_data, decode_xtheadcmo
> },
> +            { has_xtheadcondmov_p, xthead_opcode_data,
> decode_xtheadcondmov },
> +            { has_xtheadfmemidx_p, xthead_opcode_data,
> decode_xtheadfmemidx },
> +            { has_xtheadfmv_p, xthead_opcode_data, decode_xtheadfmv
> },
> +            { has_xtheadmac_p, xthead_opcode_data, decode_xtheadmac
> },
> +            { has_xtheadmemidx_p, xthead_opcode_data,
> decode_xtheadmemidx },
> +            { has_xtheadmempair_p, xthead_opcode_data,
> decode_xtheadmempair },
> +            { has_xtheadsync_p, xthead_opcode_data,
> decode_xtheadsync },
> +            { has_XVentanaCondOps_p, ventana_opcode_data,
> decode_xventanacondops },
> +            { has_xlrbr_p, rv_xlrbr_opcode_data, decode_xlrbr },
> +        };
> +
> +        for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {
> +            if (decoders[i].guard_func(cfg)) {
> +                dec.opcode_data = decoders[i].opcode_data;
> +                decoders[i].decode_func(&dec, isa);
> +                if (dec.op != rv_op_illegal) {
> +                    break;
> +                }
> +            }
>          }
>      }
>  

Reply via email to