![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
#include <qv4instr_moth_p.h>
Classes | |
| struct | Factory |
| struct | Factory< Data, std::void_t< decltype(Data::offset)> > |
Public Types | |
| enum class | Type : int { Count } |
Public Member Functions | |
| template<typename Data> | |
| Instr (const Data &datadata, int populated) | |
| template<typename Data> | |
| Data | as () const |
| int | operator[] (int i) const |
Static Public Member Functions | |
| static Type | wideInstructionType (Type tt) |
| static Type | narrowInstructionType (Type tt) |
| static bool | isWide (Type tt) |
| static bool | isNarrow (Type tt) |
| static int | encodedLength (Type tt) |
| static Type | unpack (const uchar *cc) |
| static uchar * | pack (uchar *cc, Type tt) |
Static Public Attributes | |
| static constexpr int | MaxArgCount = 4 |
Definition at line 495 of file qv4instr_moth_p.h.
|
strong |
| Enumerator | |
|---|---|
| Count | |
Definition at line 499 of file qv4instr_moth_p.h.
Definition at line 594 of file qv4instr_moth_p.h.
References MaxArgCount.
Definition at line 634 of file qv4instr_moth_p.h.
|
inlinestatic |
Definition at line 508 of file qv4instr_moth_p.h.
|
inlinestatic |
Definition at line 507 of file qv4instr_moth_p.h.
|
inlinestatic |
Definition at line 506 of file qv4instr_moth_p.h.
Definition at line 505 of file qv4instr_moth_p.h.
|
inline |
Definition at line 642 of file qv4instr_moth_p.h.
Definition at line 583 of file qv4instr_moth_p.h.
Bytecode format:
Instructions are compacted in the bytecode to save space. Every instruction gets compacted independently. There are many possible layouts coming in 4 main varieties based on two factors:
If the instruction's Type <= 255, the OP code is encoded using only one byte. Otherwise, the first byte is 0x1 and the second byte is Type & 0xff.
If the instruction takes arguments and they each fit in one byte, encode them this way. Otherwise, each argument is encoded using 4 bytes in little endian. In both cases, only the arguments actually needed by the instruction are encoded. Each instruction type receives two consecutive values in Instr::Type. The even variant has narrow arguments and the odd one has wide arguments and gets the suffix "_Wide".
The 4 main formats with arg counts ranging from 0 to 4 (x: OP code bits, abcd: argument bits):
The current design has a few nice properties: -The argument encoding width can be determined by simply checking for the lowest bit of the instruction Type. -The 127 first instructions (Nop is first and each instruction has a normal and Wide argument encoding variant) will have their OP code encoded on 1 byte. This is currently the vast majority of them. All but the rarest or slowest instructions can therefore have a compact encoding of their OP code.
Examples:
LoadInt 127: LoadInt is the 8th instruction added after Nop. Its value in Type is <= 255 so its OP code is encoded on 1 byte. It takes one argument which can be encoded losslessly in a signed byte. It therefore uses narrow argument encoding. Its bytecode encoding in HEX is thus: 10 7f | | | --> ARG1: 127 -----> OP: 8th instruction; each comes in normal and _Wide variant => 2*8=16 or 0x10
LoadInt 128: This time, not all arguments fit in one byte. Wide argument encoding is used. The bytecode encoding in HEX is thus. 11 80 00 00 00 | | | | | | -----------> ARG1: Little endian representation of 128 (not in two's complement form) --------------> OP: The instruction became LoadInt_Wide.
InitializeBlockDeadTemporalZone r1, 1 This instruction is the 129th instruction added after Nop. Its value is > 255 so its OP code is encoded on 2 bytes. It takes 2 arguments which each fit in one byte. The bytecode encoding in HEX is thus: 01 02 07 01 | | | | | | | --> ARG2 | | -----> ARG1 | --------> OP: 2-byte OP code -> Type value 258 & 0xff = 2 -----------> OP: 2-byte OP code -> 0x1 prefix
See also: QV4_SHOW_BYTECODE and dumpBytecode for much easier debugging
Definition at line 582 of file qv4instr_moth_p.h.
Definition at line 504 of file qv4instr_moth_p.h.
|
staticconstexpr |
Definition at line 497 of file qv4instr_moth_p.h.
Referenced by Instr().