AMD Athlon Processor x86 Optimization Manual page 106

X86 code optimization
Table of Contents

Advertisement

AMD Athlon™ Processor x86 Code Optimization
90
$r_two_divs:
MOV
ECX, EAX
MOV
EAX, EDX
XOR
EDX, EDX
DIV
EBX
MOV
EAX, ECX
DIV
EBX
MOV
EAX, EDX
XOR
EDX, EDX
POP
EBX
RET
$r_big_divisor:
PUSH
EDI
MOV
EDI, ECX
SHR
EDX, 1
RCR
EAX, 1
ROR
EDI, 1
RCR
EBX, 1
BSR
ECX, ECX
SHRD
EBX, EDI, CL
SHRD
EAX, EDX, CL
SHR
EDX, CL
ROL
EDI, 1
DIV
EBX
MOV
EBX, [ESP+12] ;dividend lo-word
MOV
ECX, EAX
IMUL
EDI, EAX
MUL
DWORD PTR [ESP+20] ;quotient * divisor lo-word
ADD
EDX, EDI
SUB
EBX, EAX
MOV
ECX, [ESP+16] ;dividend_hi
MOV
EAX, [ESP+20] ;divisor_lo
SBB
ECX, EDX
SBB
EDX, EDX
AND
EAX, EDX
AND
EDX, [ESP+24] ;(remainder < 0)? divisor_hi : 0
ADD
EAX, EBX
ADC
EDX, ECX
POP
EDI
POP
EBX
RET
_ullrem ENDP
;save dividend_lo in ECX
;get dividend_hi
;zero extend it into EDX:EAX
;EAX = quotient_hi, EDX = intermediate
; remainder
;EAX = dividend_lo
;EAX = quotient_lo
;EAX = remainder_lo
;EDX = remainder_hi = 0
;restore EBX as per calling convention
;done, return to caller
;save EDI as per calling convention
;save divisor_hi
;shift both divisor and dividend right
; by 1 bit
;ECX = number of remaining shifts
;scale down divisor and dividend such
; that divisor is less than 2^32
;
(i.e. fits in EBX)
;restore original divisor (EDI:ESI)
;compute quotient
;save quotient
;quotient * divisor hi-word (low only)
;EDX:EAX = quotient * divisor
;dividend_lo – (quot.*divisor)–lo
;subtract divisor * quot. from
;
dividend
;(remainder < 0)? 0xFFFFFFFF : 0
;(remainder < 0)? divisor_lo : 0
;remainder += (remainder < 0)?
; divisor : 0
;restore EDI as per calling convention
;restore EBX as per calling convention
;done, return to caller
Efficient 64-Bit Integer Arithmetic
22007E/0—November 1999

Advertisement

Table of Contents
loading

Table of Contents