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:

  1. 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 ...

Get LLVM Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.