[PATCH 02/27] arc: Decoder code

Richard Henderson richard.henderson at linaro.org
Wed Apr 7 02:25:04 BST 2021


On 4/5/21 7:31 AM, cupertinomiranda at gmail.com wrote:
> +static long long int
> +extract_uimm6_20(unsigned long long insn ATTRIBUTE_UNUSED,

global replace long long int with int64_t,
and unsigned long long int with uint64_t.


> +{
> +  unsigned value = 0;
> +
> +  value |= ((insn >> 6) & 0x003f) << 0;
> +
> +  return value;
> +}

return extract64(insn, 6, 6);

and so forth.  Please minimize the by-hand bit manipulation.

> +static const struct arc_opcode *find_format(insn_t *pinsn,
> +                                            uint64_t insn,
> +                                            uint8_t insn_len,
> +                                            uint32_t isa_mask)
> +{
> +    uint32_t i = 0;
> +    const struct arc_opcode *opcode = NULL;
> +    const uint8_t *opidx;
> +    const uint8_t *flgidx;
> +    bool has_limm = false;
> +
> +    do {
> +        bool invalid = false;
> +        uint32_t noperands = 0;
> +
> +        opcode = &arc_opcodes[i++];
> +        memset(pinsn, 0, sizeof(*pinsn));
> +
> +        if (!(opcode->cpu & isa_mask)) {
> +            continue;
> +        }
> +
> +        if (arc_opcode_len(opcode) != (int) insn_len) {
> +            continue;
> +        }
> +
> +        if ((insn & opcode->mask) != opcode->opcode) {
> +            continue;
> +        }

A linear search through the entire opcode table, really?
You can do better.

Before you re-invent the wheel, please first have a look at 
docs/devel/decodetree.rst.  I see no reason why you can't take those tables 
that you import your tables from binutils, as you're doing now, and then have a 
small program that converts to decodetree at build-time.


r~



More information about the linux-snps-arc mailing list