sparcians / mavis

RISC-V Decoder
Apache License 2.0
1 stars 6 forks source link

Form of some Zbb extension instructions is incorrect #16

Open kathlenemagnus opened 3 months ago

kathlenemagnus commented 3 months ago

The Form of several Zbb instructions is incorrect. This is the list of affected instructions:

These instructions use the ISH Form, but they should use the ISHW Form instead. However, making this fix causes a failure that says that the clz instruction is incompatible with the slli instruction. Both of these instructions use the value 0x13 as their opcode value and the value 0x1 for their func3 value. When traversing the decode tree, Mavis expects instructions with the same value for a particular field to define the same fields. For the ISH Form, the next field is func6 while for the ISHW Form the next field is func7. So the error occurs because Mavis doesn't know how to compare a func6 field with a func7 field.

BTW the order the fields are evaluated is defined in a Form's opcode_fields:

const FieldsType Form_ISH::opcode_fields {
    Form_ISH::fields[Form_ISH::idType::OPCODE],
    Form_ISH::fields[Form_ISH::idType::FUNC3],
    Form_ISH::fields[Form_ISH::idType::FUNC6]
};
const FieldsType Form_ISHW::opcode_fields {
    Form_ISHW::fields[Form_ISHW::idType::OPCODE],
    Form_ISHW::fields[Form_ISHW::idType::FUNC3],
    Form_ISHW::fields[Form_ISHW::idType::FUNC7]
};

I've solved problems like this in the past by breaking up fields into subfields. So the ISHW field func7 might become func6 and func1 so that func6 can be compared against the ISH func6.