Leaked source code of windows server 2003
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.

118 lines
3.6 KiB

  1. ;***
  2. ;
  3. ; Copyright (c) 1984-2001, Microsoft Corporation. All rights reserved.
  4. ;
  5. ;Purpose:
  6. ; support for sqrt() function
  7. ;
  8. ;Revision History:
  9. ;
  10. ;*******************************************************************************
  11. .xlist
  12. include cruntime.inc
  13. include elem87.inc
  14. .list
  15. .data
  16. extrn _indefinite:tbyte
  17. extrn __fastflag:dword
  18. _NAME_ db 'sqrt',0,0,0,0
  19. CODESEG
  20. extrn _startOneArgErrorHandling:near
  21. extrn _fload_withFB:near
  22. extrn _convertTOStoQNaN:near
  23. extrn _checkTOS_withFB:near
  24. extrn _math_exit:near
  25. extrn _fast_exit:near
  26. extrn _load_CW:near
  27. ; MUST BE MODIFIED
  28. ; arg ErrorType result
  29. ;-------------------------------------------
  30. ;QNaN DOMAIN_QNAN QNaN
  31. ;SNaN DOMAIN indefinite
  32. ;negative DOMAIN indefinite
  33. ;-infinity DOMAIN indefinite
  34. ;+infinity - infinity
  35. ;+0.0 - +0.0
  36. ;-0.0 - -0.0
  37. ;indefinite is like QNaN
  38. ;denormal fld converts it to normal (80 bits)
  39. public sqrt,_CIsqrt
  40. _CIsqrt proc
  41. sub esp,DBLSIZE+4 ; for argument
  42. fst qword ptr [esp]
  43. call _checkTOS_withFB
  44. call start
  45. add esp,DBLSIZE+4
  46. ret
  47. sqrt label proc
  48. lea edx,[esp+4]
  49. call _fload_withFB
  50. start:
  51. push edx ; allocate space for Control Word
  52. fstcw [esp] ; store Control Word
  53. mov eax,[esp+0ch] ; eax contains high dword
  54. ; at this point we have on stack: cw(4), ret_addr(4), arg1(8bytes)
  55. jz inf_or_nan
  56. cmp word ptr[esp], default_CW
  57. je CW_is_set_to_default
  58. call _load_CW ; use user's precision bits
  59. CW_is_set_to_default:
  60. test eax,80000000h
  61. jnz test_if_x_zero
  62. x_is_denormal: ; denormal is like normal
  63. fsqrt
  64. exit:
  65. cmp __fastflag,0
  66. jnz _fast_exit
  67. ; prepare in registers arguments for math_exit
  68. mov edx,OP_SQRT
  69. lea ecx,[_NAME_]
  70. jmp _math_exit
  71. test_if_x_zero: ; x <= 0
  72. test eax,7ff00000H
  73. jnz negative_x
  74. test eax,000fffffH
  75. jnz negative_x ; denormal operand
  76. cmp dword ptr[esp+8],0 ; test if low dword is zero
  77. jnz negative_x ; denormal operand
  78. jmp exit
  79. not_infinity:
  80. call _convertTOStoQNaN ; eax MUST contain high dword
  81. jmp _Error_handling ; eax=error number
  82. inf_or_nan:
  83. test eax,000fffffh
  84. jnz not_infinity
  85. cmp dword ptr[esp+8],0 ; test if low dword is zero
  86. jnz not_infinity
  87. and eax,80000000H ; test sign of infinity
  88. jz exit ; infinity is already in ST(0)
  89. negative_x:
  90. fstp st(0)
  91. fld [_indefinite]
  92. mov eax,DOMAIN
  93. _Error_handling:
  94. cmp __fastflag,0
  95. jnz _fast_exit
  96. mov edx,OP_SQRT
  97. lea ecx,[_NAME_]
  98. call _startOneArgErrorHandling
  99. pop edx ; remove saved CW from stack
  100. ret
  101. _CIsqrt endp
  102. end