Adding instruction encoding
If the instructions need to be specific for how they are encoded with respect to bit fields, this can be done by specifying the bit field in the .td
file when defining an instruction.
How to do it…
To include instruction encoding while defining instructions, proceed with the following steps:
A register operand that will be used to register the
add
instruction will have some defined encoding for its instruction. The size of the instruction is 32 bits, and the encoding for it is as follows:bits 0 to 3 -> src2, second register operand bits 4 to 11 -> all zeros bits 12 to 15 -> dst, for destination register bits 16 to 19 -> src1, first register operand bit 20 -> zero bit 21 to 24 -> for opcode bit 25 to 27 -> all zeros bit 28 to 31 -> 1110
This can be achieved by specifying the preceding bit pattern in the
.td
filesIn the
TOYInstrFormats.td
file, define a new variable, calledInst
:class InstTOY<dag outs, dag ins, string asmstr, list<dag>...