REX prefix

Last updated

The REX prefix (from "register extensions") and REX coding scheme was introduced as part of AMD's x86-64 instruction set architecture that extended Intel's IA-32 instruction set architecture for microprocessors from Intel, AMD and others.

Contents

It provides additional space for encoding 64-bit addressing modes and additional registers present in the x86-64 architecture.

The one-byte REX prefix can be added to new and existing instructions. It provides 4 bits of payload in total and allows addressing 16 registers.

A two-byte REX2 prefix was proposed by Intel's Advanced Performance Extensions in 2023 that would offer 8 bits of payload and allow addressing 32 registers.

Instruction encoding

Instruction format using the REX prefix
# of bytes1, 2110, 10, 1, 2, 40, 1
Part[Prefixes][REX]OPCODEModR/M[SIB][DISP][IMM]

The REX coding scheme uses an opcode prefix consisting of one byte, which may be added to existing or new instruction codes. [1]

It has the four high-order bits set to four, which replaces sixteen opcodes numbered 0x40–0x4F. Previously, those opcodes were individual INC and DEC instructions for the eight standard processor registers; x86-64 code must use ModR/M INC and DEC instructions. [2]

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:

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:

REX encoding
ByteBit
REX
76543210
0 (0x4_)0100WRXB
REX2 (2-byte REX)
76543210
0 (0xD5)11010101
1M0R4X4B4WR3X3B3

The REX prefix's bit-field W changes the operand size to 64 bits, R expands reg to 4 bits, B expands r/m (or opreg in the few opcodes that encode the register in the 3 lowest opcode bits, such as "POP reg"), and X and B expand index and base in the SIB byte.

The REX2 prefix is a 2-byte variant of the REX prefix, that is proposed with Intel's Advanced Performance Extensions and allows addressing 32 registers.

History

See also

References

  1. Intel Corporation (January 2009). "Intel Advanced Vector Extensions Programming Reference".
  2. Intel Corporation (2016-09-01). "Intel® 64 and IA-32 Architectures Developer's Manual: Vol. 2A". p. 2-8. Retrieved 2021-09-13.
  3. "AMD Discloses New Technologies At Microporcessor Forum" (Press release). AMD. October 5, 1999. Archived from the original on March 8, 2012. Retrieved November 9, 2010.
  4. "AMD Releases x86-64 Architectural Specification; Enables Market Driven Migration to 64-Bit Computing" (Press release). AMD. August 10, 2000. Archived from the original on March 8, 2012. Retrieved November 9, 2010.
  5. "Craig Barrett confirms 64 bit address extensions for Xeon. And Prescott". The Inquirer. February 17, 2004. Archived from the original on January 12, 2013. Retrieved August 20, 2017.
  6. ""A Roundup of 64-Bit Computing", from internetnews.com". Archived from the original on September 25, 2012. Retrieved September 18, 2006.