AsmJit
Low-Latency Machine Code Generation
Instruction database (introspection, read/write, validation, ...).
AsmJit provides a public instruction database that can be used to query information about a complete instruction. The instruction database requires the knowledge of the following:
Each instruction can be then queried for the following information:
In addition to query functionality AsmJit is also able to validate whether an instruction and its operands are valid. This is useful for making sure that what user tries to emit is correct and it can be also used by other projects that parse user input, like AsmTK project.
The instruction query API is provided by InstAPI namespace. The following queries are possible:
The instruction validation API is provided by InstAPI namespace in the similar fashion like the Query API, however, validation can also be turned on at BaseEmitter level. The following is possible:
Describes an instruction id and modifiers used together with the id.
Each architecture has a set of valid instructions indexed from 0. Instruction with 0 id is, however, a special instruction that describes a "no instruction" or "invalid instruction". Different architectures can assign a. different instruction to the same id, each architecture typically has its own instructions indexed from 1.
Instruction identifiers listed by architecture:
Instruction id parts.
A mask that specifies a bit-layout of InstId.
Instruction options.
Instruction options complement instruction identifier and attributes.
Hint that is used when both input operands to the instruction are the same.
Provides hints to the instruction RW query regarding special cases in which two or more operands are the same registers. This is required by instructions such as XOR, AND, OR, SUB, etc... These hints will influence the RW operations query.
CPU read/write flags used by InstRWInfo.
These flags can be used to get a basic overview about CPU specifics flags used by instructions.
Operand read/write flags describe how the operand is accessed and some additional features.
Constant | Description |
---|---|
kNone | No flags. |
kRead | Operand is read. |
kWrite | Operand is written. |
kRW | Operand is both read and written. |
kRegMem | Register operand can be replaced by a memory operand. |
kConsecutive | The register must be allocated to the index of the previous register + 1. This flag is used by all architectures to describe instructions that use consecutive registers, where only the first one is encoded in the instruction, and the others are just a sequence that starts with the first one. On X86/X86_64 architecture this is used by instructions such as V4FMADDPS, V4FMADDSS, V4FNMADDPS, V4FNMADDSS, VP4DPWSSD, VP4DPWSSDS, VP2INTERSECTD, and VP2INTERSECTQ. On ARM/AArch64 this is used by vector load and store instructions that can load or store multiple registers at once. |
kZExt | The |
kUnique | The register must have assigned a unique physical ID, which cannot be assigned to any other register. |
kRegPhysId | Register operand must use OpRWInfo::physId(). |
kMemPhysId | Base register of a memory operand must use OpRWInfo::physId(). |
kMemFake | This memory operand is only used to encode registers and doesn't access memory. X86 SpecificInstructions that use such feature include BNDLDX, BNDSTX, and LEA. |
kMemBaseRead | Base register of the memory operand will be read. |
kMemBaseWrite | Base register of the memory operand will be written. |
kMemBaseRW | Base register of the memory operand will be read & written. |
kMemIndexRead | Index register of the memory operand will be read. |
kMemIndexWrite | Index register of the memory operand will be written. |
kMemIndexRW | Index register of the memory operand will be read & written. |
kMemBasePreModify | Base register of the memory operand will be modified before the operation. |
kMemBasePostModify | Base register of the memory operand will be modified after the operation. |
Flags used by InstRWInfo.
Constant | Description |
---|---|
kNone | No flags. |
kMovOp | Describes a move operation. This flag is used by RA to eliminate moves that are guaranteed to be moves only. |
Validation flags that can be used with InstAPI::validate().
Constant | Description |
---|---|
kNone | No flags. |
kEnableVirtRegs | Allow virtual registers in the instruction. |