4. Adding Support for New instructions

This section discusses the tasks required to add support of a new instruction generation in CTG.

4.1. Update the Attributes YAML

The first step would be to update the attributes YAML to define a node for the new instruction. The new node must follow the same template as defined earlier.

One must try to use the existing datasets and fields as much as possible and avoid creation of new redundant datasets unless absolutely required. One can also define abstract functions to generate the datasets on the go instead of having to elaborate them completely in the YAML itself.

Some of the abstract functions are available in constants() for reference.

4.2. Create a new format

If the instruction uses a new instruction format type, which is not already present in the CTG currently, then the behavior of that will have to be defined in the generator() class.

This would involve updating the dictionaries OPS() and VALS() with the new type. Next create a function __XX_instr__ in generator() similar to the existing ones which defines how the op_comb and val_comb solutions are merged to create the corresponding instruction.

4.3. Additional Register Allocations

Currently the signature register allocation assumes a max of 3 registers being used by an instruction. However, if your instruction uses more registers then the swreg() function will also need an update.

Similarly the test register allocation function testreg() function will also have to be updated.

4.4. Adding Instruction Macros

CTG does not generate direct instruction. It rather uses the template field in the attributes YAML as a template to generate tests. This template is usually an assembly macro. The definition of these macros must be defined in env/arch_test.h header file.