IA-32 Intel® Architecture Optimization
2-66
Example 2-23 Algorithm to Avoid Changing the Rounding Mode
_fto132proc
lea
ecx,[esp-8]
sub
esp,16
; allocate frame
and
ecx,-8
; align pointer on boundary of 8
fld
st(0)
; duplicate FPU stack top
fistp
qword ptr[ecx]
fild
qword ptr[ecx]
mov
edx,[ecx+4]; high dword of integer
mov
eax,[ecx]
; low dword of integer
test
eax,eax
je
integer_QnaN_or_zero
arg_is_not_integer_QnaN:
fsubp
st(1),st
; TOS=d-round(d),
; { st(1)=st(1)-st & pop ST}
test
edx,edx
; what’s sign of integer
jns
positive
; number is negative
fstp
dword ptr[ecx]; result of subtraction
mov
ecx,[ecx]
; dword of diff(single-
; precision)
add
esp,16
xor
ecx,80000000h
add
ecx,7fffffffh ; if diff<0 then decrement
; integer
adc
eax,0
; inc eax (add CARRY flag)
ret
positive:
continued
Summary of Contents for ARCHITECTURE IA-32
Page 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Page 220: ...IA 32 Intel Architecture Optimization 3 40...
Page 434: ...IA 32 Intel Architecture Optimization 9 20...
Page 514: ...IA 32 Intel Architecture Optimization B 60...
Page 536: ...IA 32 Intel Architecture Optimization C 22...