Example 2-23 Algorithm To Avoid Changing The Rounding Mode - Intel ARCHITECTURE IA-32 Reference Manual

Architecture optimization
Table of Contents

Advertisement

IA-32 Intel® Architecture Optimization

Example 2-23 Algorithm to Avoid Changing the Rounding Mode

_fto132proc
lea
ecx,[esp-8]
sub
esp,16
and
ecx,-8
fld
st(0)
fistp
qword ptr[ecx]
fild
qword ptr[ecx]
mov
edx,[ecx+4]; high dword of integer
mov
eax,[ecx]
test
eax,eax
je
integer_QnaN_or_zero
arg_is_not_integer_QnaN:
fsubp
st(1),st
test
edx,edx
jns
positive
fstp
dword ptr[ecx]; result of subtraction
mov
ecx,[ecx]
add
esp,16
xor
ecx,80000000h
add
ecx,7fffffffh ; if diff<0 then decrement
adc
eax,0
ret
positive:
2-66
; allocate frame
; align pointer on boundary of 8
; duplicate FPU stack top
; low dword of integer
; TOS=d-round(d),
; { st(1)=st(1)-st & pop ST}
; what's sign of integer
; number is negative
; dword of diff(single-
; precision)
; integer
; inc eax (add CARRY flag)
continued

Advertisement

Table of Contents
loading

Table of Contents