AMD 250 Computer Hardware User Manual


 
Chapter 7 Scheduling Optimizations 153
Software Optimization Guide for AMD64 Processors
25112 Rev. 3.06 September 2005
7.5 MOVZX and MOVSX
Optimization
Use the MOVZX and MOVSX instructions to zero-extend or sign-extend, respectively, an operand to
a larger size.
Application
This optimization applies to:
32-bit software
64-bit software
Rationale
Typical code for zero extension that replaces MOVZX uses more decode and execution resources than
MOVZX. It also has higher latency due to the superset dependency between the XOR and the MOV,
which requires a merge operation.
Example
When zero-extending an operand (in this case, a byte), avoid code such as the following:
xor rax, rax
mov al, mem
Instead, use the MOVZX instruction:
movzx rax, BYTE PTR mem