
78
Replace Divides with Multiplies
AMD Athlon™ Processor x86 Code Optimization
22007E/0—November 1999
Signed Division
Utility
In the opt_utilities directory of the AMD documentation
CDROM, run sdiv.exe in a DOS window to find the fastest code
for signed division by a constant. The utility displays the code
after the user enters a signed constant divisor. Type “sdiv >
example.out” to output the code to a file.
Unsigned Division
Utility
In the opt_utilities directory of the AMD documentation
CDROM, run udiv.exe in a DOS window to find the fastest code
for unsigned division by a constant. The utility displays the code
after the user enters an unsigned constant divisor. Type “udiv >
example.out” to output the code to a file.
Unsigned Division by Multiplication of Constant
Algorithm: Divisors
1 <= d < 2
31
, Odd d
The following code shows an unsigned division using a constant
value multiplier.
;In:
d = divisor, 1 <= d < 2^31, odd d
;Out: a = algorithm
;
m = multiplier
;
s = shift factor
;algorithm 0
MOV
EDX, dividend
MOV
EAX, m
MUL
EDX
SHR
EDX, s ;EDX=quotient
;algorithm 1
MOV
EDX, dividend
MOV
EAX, m
MUL
EDX
ADD
EAX, m
ADC
EDX, 0
SHR
EDX, s ;EDX=quotient
Derivation of a, m, s
The derivation for the algorithm (a), multiplier (m), and shift
count (s), is found in the section “Unsigned Derivation for
Algorithm, Multiplier, and Shift Factor” on page 93.
Algorithm: Divisors
2
31
<= d < 2
32
For divisors 2
31
<= d < 2
32
, the possible quotient values are
either 0 or 1. This makes it easy to establish the quotient by
simple comparison of the dividend and divisor. In cases where
the dividend needs to be preserved, example 1 below is
recommended.
Содержание Athlon Processor x86
Страница 1: ...AMD Athlon Processor x86 Code Optimization Guide TM...
Страница 12: ...xii List of Figures AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 16: ...xvi Revision History AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 60: ...44 Code Padding Using Neutral Code Fillers AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 92: ...76 Push Memory Data Carefully AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 122: ...106 Take Advantage of the FSINCOS Instruction AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 156: ...140 AMD Athlon Processor Microarchitecture AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 176: ...160 Write Combining Operations AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 202: ...186 Page Attribute Table PAT AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 252: ...236 VectorPath Instructions AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Страница 256: ...240 Index AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...