AMD amd64 architecture User Manual

Page of 336
74
General-Purpose Programming
AMD64 Technology
24592—Rev. 3.15—November 2009
3.5.2 REX Prefixes
REX prefixes are a new group of instruction-prefix bytes that can be used only in 64-bit mode. They
enable the 64-bit register extensions. REX prefixes specify the following features:
Use of an extended GPR register, shown in Figure 3-3 on page 27.
Use of an extended XMM register, shown in Figure 4-12 on page 117.
Use of a 64-bit (quadword) operand size, as described in “Operands” on page 36.
Use of extended control and debug registers, as described in Volume 2.
REX prefix bytes have a value in the range 40h to 4Fh, depending on the particular combination of
register extensions desired. With few exceptions, a REX prefix is required to access a 64-bit GPR or
one of the extended GPR or XMM registers. A few instructions (described in “General-PurposeInstructions in 64-Bit Mode” in Volume 3) default to 64-bit operand size and do not need the REX
prefix to access an extended 64-bit GPR.
An instruction can have only one REX prefix, and one such prefix is all that is needed to express the
full selection of 64-bit-mode register-extension features. The prefix, if used, must immediately
precede the first opcode byte of an instruction. Any other placement of a REX prefix is ignored. The
legacy instruction-size limit of 15 bytes still applies to instructions that contain a REX prefix.
For further details on the REX prefixes, see “REX Prefixes” in Volume 3.
3.6
Feature Detection
The CPUID instruction provides information about the processor implementation and its capabilities.
Software operating at any privilege level can execute the CPUID instruction to collect this information.
After the information is collected, software can select procedures that optimize performance for a
particular hardware implementation. For example, application software can determine whether the
AMD64 architecture’s long mode is supported by the processor, and it can determine the processor
implementation’s performance capabilities.
Support for the CPUID instruction is implementation-dependent, as determined by software’s ability
to write the RFLAGS.ID bit. The following code sample shows how to test for the presence of the
CPUID instruction.
pushfd
; save EFLAGS
pop
eax
; store EFLAGS in EAX
mov
ebx, eax
; save in EBX for later testing
xor
eax, 00200000h
; toggle bit 21
push
eax
; push to stack
popfd
; save changed EAX to EFLAGS
pushfd
; push EFLAGS to TOS
pop
eax
; store EFLAGS in EAX
cmp
eax, ebx
; see if bit 21 has changed
jz
NO_CPUID
; if no change, no CPUID