The VEX coding scheme uses a
opcode prefix consisting of two or three
bytes, which may be added to existing or new instruction codes. Two instructions (that were previously defined as invalid opcodes in 64-bit mode) were repurposed as the leading byte of the new VEX prefixes: for the three-byte variant and for the two-byte variant. The VEX prefix replaces the , and opcode prefixes, the REX prefix, and the , or opcode prefixes. It may
not be used with one-byte opcodes which do not begin with , nor with the LOCK () prefix. It may be preceded only by address size () or segment (, , , , , ) prefixes. In the x86 architecture, instructions with a memory operand almost always use the
ModR/M byte which specifies the
addressing mode. This byte has three bit fields: •
mod, bits [7:6] - combined with the
r/m field, encodes either 8 registers or 24 addressing modes. Also encodes opcode information for some instructions. •
reg/opcode, bits [5:3] - depending on primary opcode byte, specifies either a register or three more bits of opcode information. •
r/m, bits [2:0] - can specify a register as an operand, or combine with the
mod field to encode an addressing mode. The base-plus-index and scale-plus-index forms of 32-bit addressing (encoded with r/m = 100 and mod ≠ 11) require another addressing byte, the SIB byte. It has the following fields: •
scale factor, encoded with bits [7:6] •
index register, bits [5:3] •
base register, bits [2:0]. The
VEX3 prefix contains all bit-fields from the REX prefix as well as various other prefixes, expanding addressing mode, register enumeration, operand size and width: • R̅, X̅ and B̅ bits are complements of the REX prefix's R, X and B bits; these provide a fourth (high) bit for register index fields (ModRM reg, SIB index, and ModRM r/m; SIB base; or opcode reg fields, respectively) allowing access to 16 instead of 8 registers. • One W bit, equivalent to the REX prefix's W bit, specifies a 64-bit operand; for non-integer instructions, it is a general opcode extension bit. • Four v̅ bits are the complement of an additional source register index. • One L bit indicates the vector length; 0 for 128-bit SSE (XMM) registers, and 1 for 256-bit AVX (YMM) registers. • Two p bits encode additional prefix bytes. The values 0, 1, 2, and 3 correspond to implied no, 0x66, 0xF3, and 0xF2 prefixes. These encode the operand type for SSE floating-point instructions: packed single, packed double, scalar single and scalar double, respectively. • Five
m bits are used to specify
opcode map to use. Of the 32 possible opcode maps that can be encoded with
m4m3m2m1m0 , opcode maps 1, 2 and 3 are used to provide compact replacements for legacy 2-byte and 3-byte opcodes - these three opcode maps are equivalent to leading escape byte sequences 0x0F, and , respectively. The other VEX opcode maps have seen little use - as of December 2023, the only known uses of other maps are map 0 for the
Xeon Phi-specific JKZD/JKNZD instructions and map 7 for the planned URDMSR/UWRMSR instructions. Maps 4/5/6 are used with the
EVEX prefix, but none of the instructions in those maps are VEX-encodable. The
VEX2 prefix is a 2-byte abbreviation of the VEX3 prefix, which may be used when the omitted fields have the following values: • W = 0: 32-bit operand size • B̅ = 1 (B = 0): Base register is among the first 8 • X̅ = 1 (X = 0): Index register (if a SIB byte is present) is among the first 8 • m = 00001: 2-byte opcode beginning with 0x0F Instructions which require different values for these fields must be encoded with the VEX3 prefix. VEX2 does include an R̅ bit, an L bit, two p bits, and an additional 4-bit source register (v), so is useful for many SSE and AVX instructions as long as the register/memory operand uses only the first 8 registers. ==Technical description==