Use Xor Instruction To Clear Integer Registers; Efficient 64-Bit Integer Arithmetic - AMD Athlon Processor x86 Optimization Manual

X86 code optimization
Table of Contents

Advertisement

AMD Athlon™ Processor x86 Code Optimization

Use XOR Instruction to Clear Integer Registers

Efficient 64-Bit Integer Arithmetic

86
To clear an integer register to all 0s, use "XOR reg, reg". The
AMD Athlon processo r is able to avoid the false rea d
dependency on the XOR instruction.
Example 1 (Acceptable):
MOV
REG, 0
Example 2 (Preferred):
XOR
REG, REG
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
subroutines. If these s ubroutines are used often, the
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
22007E/0—November 1999
Use XOR Instruction to Clear Integer Registers

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Athlon Processor x86 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents