takahirox/riscv-rust

Simpler decoding

Closed this issue · 1 comments

We may simplify decoding with the sets of mask and data. For example decoding ADDI instruction can be written as

if (word & 0x0000707f) == 0x00000013 {
  return Instruction::ADDI;
}

then we may rewrite decode function with loop

// pseudo-code
for d in decoding_sets {
  if (word & d.mask) == d.data {
    return d.instruction;
  }
}

Resolved by #105