86
Use XOR Instruction to Clear Integer Registers
AMD Athlon™ Processor x86 Code Optimization
22007E/0—November 1999
Use XOR Instruction to Clear Integer Registers
To clear an integer register to all 0s, use “XOR reg, reg”. The
A M D A t hl o n p ro ce s s o r i s ab l e t o avo i d th e fa l s e re a d
dependency on the XOR instruction.
Example 1 (Acceptable):
MOV
REG, 0
Example 2 (Preferred):
XOR
REG, REG
Efficient 64-Bit Integer Arithmetic
This section contains a collection of code snippets and
subroutines showing the efficient implementation of 64-bit
arithmetic. Addition, subtraction, negation, and shifts are best
handled by inline code. Multiplies, divides, and remainders are
less common operations and should usually be implemented as
s u b ro u t i n e s . I f t h e s e s u b ro u t i n e s a re u s e d o f t e n , t h e
programmer should consider inlining them. Except for division
and remainder, the code presented works for both signed and
unsigned integers. The division and remainder code shown
works for unsigned integers, but can easily be extended to
handle signed integers.
Example 1 (Addition):
;add operand in ECX:EBX to operand EDX:EAX, result in
;
EDX:EAX
ADD EAX, EBX
ADC EDX, ECX
Example 2 (Subtraction):
;subtract operand in ECX:EBX from operand EDX:EAX, result in
;
EDX:EAX
SUB EAX, EBX
SBB EDX, ECX
Example 3 (Negation):
;negate operand in EDX:EAX
NOT EDX
NEG EAX
SBB EDX, –1 ;fixup: increment hi-word if low-word was 0
Summary of Contents for Athlon Processor x86
Page 1: ...AMD Athlon Processor x86 Code Optimization Guide TM...
Page 12: ...xii List of Figures AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 16: ...xvi Revision History AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 202: ...186 Page Attribute Table PAT AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 252: ...236 VectorPath Instructions AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 256: ...240 Index AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...