Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4 KiB

  1. page ,132
  2. title ftol2 - truncate TOS to 32-bit integer
  3. ;***
  4. ;ftol2.asm - truncate TOS to 32-bit integer
  5. ;
  6. ; Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ;
  10. ;Revision History:
  11. ;
  12. ; 01/26/01 Phil Lucido
  13. ; Optimized version from Intel to avoid Pentium FLDCW stalls.
  14. ;
  15. ;*******************************************************************************
  16. .xlist
  17. include cruntime.inc
  18. .list
  19. CODESEG
  20. public _ftol2
  21. _ftol2 proc
  22. tmp1 equ <[esp+24]>
  23. tmp2 equ <[esp+16]>
  24. tmp3 equ <[esp]>
  25. push ebp
  26. mov ebp,esp
  27. sub esp,32
  28. and esp,0fffffff0h
  29. fld st(0) ; duplicate FPU stack top
  30. fst dword ptr tmp1 ; store single to get the sign
  31. fistp qword ptr tmp2 ; sto as int
  32. fild qword ptr tmp2 ; ld int, cvt to fp
  33. mov edx,tmp1 ; get the sign (not fwd problem)
  34. mov eax,tmp2 ; low dword of integer
  35. test eax,eax
  36. je integer_QnaN_or_zero
  37. arg_is_not_integer_QnaN:
  38. fsubp st(1),st ; TOS=d-round(d),
  39. ; { st(1)=st(1)-st & pop ST}
  40. test edx,edx ; whats sign of integer
  41. jns positive ; number is negative
  42. fstp dword ptr tmp3 ; result of subtraction
  43. mov ecx,tmp3 ; dword of diff(single-precision)
  44. xor ecx,80000000h
  45. add ecx,7fffffffh ; if diff<0 then decrement integer
  46. adc eax,0 ; inc eax (add CARRY flag)
  47. mov edx,tmp2+4 ; high dword of integer - deferred
  48. adc edx,0
  49. jmp localexit
  50. positive:
  51. fstp dword ptr tmp3 ; 17-18 result of subtraction
  52. mov ecx,tmp3 ; dword of diff(single-precision)
  53. add ecx,7fffffffh ; if diff<0 then decrement integer
  54. sbb eax,0 ; dec eax (subtract CARRY flag)
  55. mov edx,tmp2+4 ; high dword of integer - deferred
  56. sbb edx,0
  57. jmp localexit
  58. integer_QnaN_or_zero: ; load the upper 32 bits of the converted integer
  59. mov edx,tmp2+4 ; high dword of integer (fwd problem)
  60. test edx,7fffffffh
  61. jnz arg_is_not_integer_QnaN
  62. fstp dword ptr tmp1
  63. fstp dword ptr tmp1
  64. localexit:
  65. leave
  66. ret
  67. _ftol2 endp
  68. end