I got a flashback to the Commodore 128 monitor, the built-in system monitor utility I used to learn 6502 assembly. Used it almost as much as the built-in sprite editor (sprdef).
All the possibilities are tested sequentially if ((opcode & mask) == match) ...
Are the mask bits continuous? Could you sort the mask,match tuples according to minimum or maximum possible opcode, so you could skip large swathes of opcodes? Or is the total number small enough to not bother? Sorry for regressing to a 4-year old, but this is kinda interesting.
No. It covers the whole 32 bit instruction, masking out all the fields containing register numbers, literals that parameterize an instruction (and the high 16 bits for 16 bit instructions), and keeping the fixed bits that make that instruction .. that instruction.
You could sort by "mask". You could sort by "match". But I can't see any way to sort by a combination of them.
RV64IMAFDC ends up with I guess a bit over 100 instructions in the list. That doesn't take long to do a linear search on.
Many programs move a mask/match pair that hits to the front of the list. That means that most of the time you get a hit in the first 10 or so. Just a few instructions such as add immediate, load register, store register, beq, bne, jal, ret pretty quickly make up well over 90% of all opcodes.
That's about as good as you'd get by sorting and binary searching anyway, even if it was possible.