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.

165 lines
3.7 KiB

  1. ;***
  2. ;
  3. ; Copyright (c) 1984-2001, Microsoft Corporation. All rights reserved.
  4. ;
  5. ;Purpose:
  6. ; support for sin(), cos() and tan() functions
  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. extrn _pi_by_2_to_61:tbyte
  19. extrn _DEFAULT_CW_in_mem:word
  20. ifdef _COS_
  21. _NAME_ db 'cos',0
  22. _FUNC_ equ <cos>
  23. _IFUNC_ equ <_CIcos>
  24. elseifdef _TAN_
  25. _NAME_ db 'tan',0
  26. _FUNC_ equ <tan>
  27. _IFUNC_ equ <_CItan>
  28. elseifdef _SIN_
  29. _SIN_ equ 1
  30. _NAME_ db 'sin',0
  31. _FUNC_ equ <sin>
  32. _IFUNC_ equ <_CIsin>
  33. endif
  34. CODESEG
  35. extrn _startOneArgErrorHandling:near
  36. extrn _fload_withFB:near
  37. extrn _convertTOStoQNaN:near
  38. extrn _checkTOS_withFB:near
  39. extrn _math_exit:near
  40. extrn _fast_exit:near
  41. ; arg ErrorType result
  42. ;-------------------------------------------
  43. ;+/-infinity DOMAIN indefinite | ? Do we really need
  44. ;QNaN DOMAIN_QNAN QNaN | ? to distinguish them???
  45. ;SNaN DOMAIN indefinite | ? it costs 14 bytes per function
  46. ;indefinite is like QNaN
  47. ;denormal fld converts it to normal (80 bits)
  48. public _FUNC_,_IFUNC_
  49. _IFUNC_ proc
  50. sub esp,DBLSIZE+4 ; for argument
  51. fst qword ptr [esp]
  52. call _checkTOS_withFB
  53. call start
  54. add esp, DBLSIZE+4
  55. ret
  56. _FUNC_ label proc
  57. lea edx, [esp+4]
  58. call _fload_withFB
  59. start:
  60. push edx ; allocate space for Control Word
  61. fstcw [esp] ; store Control Word
  62. ; at this point we have on stack: cw(4), ret_addr(4), arg1(8bytes)
  63. jz inf_or_nan
  64. cmp word ptr[esp], default_CW
  65. je CW_is_set_to_default
  66. ; fsin/fcos/fptan are not affected by precizion bits.
  67. ; So we may ignore user's CW
  68. fldcw _DEFAULT_CW_in_mem
  69. CW_is_set_to_default:
  70. ifdef _COS_
  71. fcos
  72. fstsw ax
  73. elseifdef _SIN_
  74. fsin
  75. fstsw ax
  76. elseifdef _TAN_
  77. fptan
  78. fstsw ax
  79. endif
  80. sahf
  81. jp reduce_arg
  82. ifdef _TAN_
  83. fstp st(0)
  84. endif
  85. exit:
  86. cmp __fastflag, 0
  87. jnz _fast_exit
  88. ; prepare in registers arguments for math_exit
  89. ifdef _COS_
  90. mov edx,OP_COS
  91. elseifdef _SIN_
  92. mov edx,OP_SIN
  93. elseifdef _TAN_
  94. mov edx,OP_TAN
  95. endif
  96. lea ecx,[_NAME_]
  97. jmp _math_exit
  98. reduce_arg:
  99. fld TBYTE PTR [_pi_by_2_to_61]
  100. fxch st(1)
  101. redux_loop:
  102. fprem1
  103. fstsw ax
  104. sahf
  105. jp redux_loop
  106. ;reapply
  107. fstp st(1)
  108. ifdef _COS_
  109. fcos
  110. elseifdef _SIN_
  111. fsin
  112. elseifdef _TAN_
  113. fptan
  114. fstp st(0)
  115. endif
  116. jmp exit
  117. not_infinity:
  118. call _convertTOStoQNaN ; eax MUST contain high dword
  119. jmp _Error_handling ; eax=error number
  120. inf_or_nan:
  121. test eax, 000fffffh
  122. jnz not_infinity
  123. cmp dword ptr[esp+8], 0
  124. jne not_infinity
  125. fstp st(0)
  126. fld [_indefinite]
  127. mov eax,DOMAIN
  128. _Error_handling:
  129. cmp __fastflag, 0
  130. jnz _fast_exit
  131. ifdef _COS_
  132. mov edx,OP_COS
  133. elseifdef _SIN_
  134. mov edx,OP_SIN
  135. elseifdef _TAN_
  136. mov edx,OP_TAN
  137. endif
  138. lea ecx,[_NAME_]
  139. call _startOneArgErrorHandling
  140. pop edx ; remove saved CW from stack
  141. ret
  142. _IFUNC_ endp
  143. end