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.

244 lines
6.2 KiB

  1. page ,132
  2. title 87triga - inverse trigonometric functions - ASIN, ACOS, ATAN
  3. ;***
  4. ;87triga.asm - inverse trigonometric functions - ASIN, ACOS, ATAN
  5. ;
  6. ; Copyright (c) 1984-2001, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ; Routines for ASIN, ACOS, ATAN
  10. ;
  11. ;Revision History:
  12. ;
  13. ; 07/04/84 Greg Whitten
  14. ; initial version
  15. ;
  16. ; 10/01/84 Brad Verheiden
  17. ; Fixed bug in _rtforatnby0 which did not remove an
  18. ; element from the floating stack
  19. ;
  20. ; 10/28/85 Jamie Bariteau
  21. ; Added comment about inputs to fFATN2, made fFATN2
  22. ; public
  23. ; made _fFATN2 and _rtpiby2 public labels
  24. ;
  25. ; 10/30/87 Bill Johnston
  26. ; Minor changes for new cmacros.
  27. ;
  28. ; 08/25/88 Bill Johnston
  29. ; 386 version.
  30. ;
  31. ; 02/10/92 Georgios Papagiannakopoulos
  32. ; NT port -- Bug fix for atan(-INF)
  33. ;
  34. ; 03/27/92 GDP support underflow
  35. ;
  36. ; 01/03/96 JWM Modify return value of atan2(0,0)
  37. ;
  38. ; 05/10/00 GB Modify return value for atan2(-0.0, 1.0)
  39. ;
  40. ;*******************************************************************************
  41. .xlist
  42. include cruntime.inc
  43. include mrt386.inc
  44. include elem87.inc
  45. .list
  46. .data
  47. extrn _indefinite:tbyte
  48. extrn _piby2:tbyte
  49. jmptab OP_ATAN2,5,<'atan2',0>,<0,0,0,0,0,0>,2
  50. DNCPTR codeoffset fFATN2 ; 0000 NOS Valid non-0, TOS Valid non-0
  51. DNCPTR codeoffset _rtforatnby0 ; 0001 NOS Valid non-0, TOS 0
  52. DNCPTR codeoffset _tosnan2 ; 0010 NOS Valid non-0, TOS NAN
  53. DNCPTR codeoffset _rtforatn20 ; 0011 NOS Valid non-0, TOS Inf
  54. DNCPTR codeoffset _rtforatn20 ; 0100 NOS 0, TOS Valid non-0
  55. DNCPTR codeoffset _rtforatn20 ; 0101 NOS 0, TOS 0
  56. DNCPTR codeoffset _tosnan2 ; 0110 NOS 0, TOS NAN
  57. DNCPTR codeoffset _rtforatn20 ; 0111 NOS 0, TOS Inf
  58. DNCPTR codeoffset _nosnan2 ; 1000 NOS NAN, TOS Valid non-0
  59. DNCPTR codeoffset _nosnan2 ; 1001 NOS NAN, TOS 0
  60. DNCPTR codeoffset _nan2 ; 1010 NOS NAN, TOS NAN
  61. DNCPTR codeoffset _nosnan2 ; 1011 NOS NAN, TOS Inf
  62. DNCPTR codeoffset _rtforatnby0 ; 1100 NOS Inf, TOS Valid non-0
  63. DNCPTR codeoffset _rtforatnby0 ; 1101 NOS Inf, TOS 0
  64. DNCPTR codeoffset _tosnan2 ; 1110 NOS Inf, TOS NAN
  65. DNCPTR codeoffset _rtindfpop ; 1111 NOS Inf, TOS Inf
  66. page
  67. CODESEG
  68. extrn _rtchsifneg:near
  69. extrn _rtindfpop:near
  70. extrn _rtindfnpop:near
  71. extrn _rtnospop:near
  72. extrn _rtonenpop:near
  73. extrn _rttospop:near
  74. extrn _rttosnpop:near
  75. extrn _rttosnpopde:near
  76. extrn _rtzeronpop:near
  77. extrn _tosnan1:near
  78. extrn _tosnan2:near
  79. extrn _nosnan2:near
  80. extrn _nan2:near
  81. ;----------------------------------------------------------
  82. ;
  83. ; INVERSE TRIGONOMETRIC FUNCTIONS
  84. ;
  85. ;----------------------------------------------------------
  86. ;
  87. ; INPUTS - For single argument functions the argument
  88. ; is the stack top. For fFATN2 the numerator
  89. ; is next to stack top, the denominator is
  90. ; the stack top.
  91. ; For single argument functions the sign is
  92. ; in bit 2 of CL. For fFATN2 the numerator
  93. ; sign is bit 2 of CH, the denominator
  94. ; sign is bit 2 of CL.
  95. ;
  96. ; Note:
  97. ; _clog calls fFATN2 with the signs of the arguments
  98. ; in bit 0 of CL and CH respectively. This should
  99. ; work since fFATN2 tests for sign of numerator and
  100. ; denominator by using "or CL,CL" and "or CH,CH"
  101. ;
  102. ; OUTPUT - The result is the stack top
  103. ;
  104. ;----------------------------------------------------------
  105. lab fFASN
  106. call AugmentSinCos ; num.=arg, den.=sqrt(1-arg^2)
  107. xchg ch, cl ; sign(num.)=sign(arg)
  108. jmp short fFPATAN
  109. lab fFACS
  110. call AugmentSinCos ; num.=arg, den.=sqrt(1-arg^2)
  111. fxch ; num.=sqrt(1-arg^2), den.=arg
  112. jmp short fFPATAN
  113. lab fFATN
  114. fabs
  115. fld1 ; denominator is 1
  116. mov ch, cl
  117. xor cl, cl ; sign of denominator is +ve
  118. jmp short fFPATAN
  119. labelNP _fFATN2, PUBLIC
  120. lab fFATN2
  121. mov DSF.ErrorType, CHECKRANGE ; indicate possible over/under flow on exit
  122. fabs
  123. fxch
  124. fabs
  125. fxch
  126. lab fFPATAN
  127. fpatan ; compute partial arctangent
  128. or cl, cl ; if denominator was +ve
  129. JSZ PatanNumeratorTest ; bypass -ve denominator adjust
  130. fldpi
  131. fsubrp st(1), st(0) ; change Patan to pi - Patan
  132. lab PatanNumeratorTest
  133. or ch, ch ; if numerator was +ve
  134. JSZ PatanDone ; bypass -ve numerator adjust
  135. fchs ; change Patan to -Patan
  136. lab PatanDone
  137. ret
  138. page
  139. lab AugmentSinCos
  140. fabs ; NOS=x = |input|
  141. fld st(0) ; NOS=x, TOS=x
  142. fld st(0) ; NNOS=x, NOS=x, TOS=x
  143. fld1 ; NNNOS=x, NNOS=x, NOS=x, TOS=1
  144. fsubrp st(1),st(0) ; NNOS=x, NOS=x, TOS=1-x
  145. fxch ; NNOS=x, NOS=1-x, TOS=x
  146. fld1 ; NNNOS=x, NNOS=1-x, NOS=x, TOS=1
  147. fadd ; NNOS=x, NOS=1-x, TOS=1+x
  148. fmul ; NOS=x, TOS=1-x^2
  149. ftst
  150. fstsw DSF.StatusWord
  151. fwait
  152. test CondCode, 1 ; if 1-x^2 < 0
  153. JSNZ DescriminantNeg ; return a NAN
  154. xor ch, ch ; sign of TOS is +ve
  155. fsqrt ; NOS=x, TOS=sqrt(1-x^2)
  156. ret
  157. lab DescriminantNeg
  158. pop rax ; remove return address from stack
  159. jmp _rtindfpop ; replace top of stack with a NAN
  160. page
  161. ;----------------------------------------------------------
  162. ;
  163. ; SPECIAL CASE RETURN FUNCTIONS
  164. ;
  165. ;----------------------------------------------------------
  166. ;
  167. ; INPUTS - The signs of the last, second to last
  168. ; arguments are in CH, CL respectively.
  169. ;
  170. ; OUTPUT - The result is the stack top.
  171. ;
  172. ;----------------------------------------------------------
  173. labelNP _rtpiby2, PUBLIC
  174. fstp st(0) ; remove ST(0)
  175. fld [_piby2] ; push pi/2 onto stack
  176. ret
  177. lab _rtforatn20
  178. fstp st(0) ; remove ST(0)
  179. or cl ,cl ; if denominator is +ve
  180. JSZ zeronpop ; return zero
  181. fstp st(0)
  182. fldpi ; push pi onto stack
  183. or ch, ch ; if numerator was +ve
  184. JSZ postv
  185. fchs
  186. lab postv
  187. ret
  188. lab zeronpop
  189. fstp st(0)
  190. fldz ; push 0.0 onto stack
  191. or ch, ch ; if numerator was +ve
  192. JSZ postv
  193. fchs
  194. ret
  195. lab _rtforatn200
  196. lab indfpop
  197. fstp st(0) ; remove ST(0)
  198. lab indfnpop
  199. jmp _rtindfnpop ; return real indefinite
  200. lab _rtforatnby0
  201. fstp st(0) ; remove an argument before returning
  202. mov cl, ch ; cl is sign(TOS)
  203. jmp short _rtsignpiby2
  204. lab _rtforatninf
  205. lab _rtsignpiby2
  206. call _rtpiby2 ; push pi/2 onto stack
  207. jmp _rtchsifneg ; return with sign change if negative
  208. end