I noticed that in function 'decode_opc()'(/target-mips/translate.c), there are 
so many switch case sentence, why don't we change it to a table-driven 
architecture? I've written a simple demo as following:


struct MIPSInstruction{
    int     op;
    void  (*op_func)(CPUMIPSState *, DisasContext *);
};


struct MIPSInstruction op_translate_table[] = {
    { OPC_SPECIAL,  decode_opc_special         },
    { OPC_SPECIAL2, decode_opc_special2_legacy },
    { OPC_SPECIAL3, decode_opc_special3        },
    ...
};


static void decode_opc(CPUMIPSState *env, DisasContext *ctx)
{
    int op;


    ...


    op = MASK_OP_MAJOR(ctx->opcode);
    for (size_t i = 0; i < sizeof(op_translate_table) / 
sizeof(op_translate_table[0]); i++) {
        if ((op == op_translate_table[i].op) && (op_translate_table.op_func != 
NULL)) {
            op_translate_table.op_func(env, ctx);
        }
    }


    ...
}

Reply via email to