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.

298 lines
7.7 KiB

  1. page ,132
  2. title 87disp - common transcendental dispatch routine
  3. ;***
  4. ;87disp.asm - common transcendental dispatch routine (80x87/emulator version)
  5. ;
  6. ; Copyright (c) 1984-2001, Microsoft Corporation. All rights reserved.
  7. ;
  8. ;Purpose:
  9. ; Common transcendental dispatch routine (80x87/emulator version)
  10. ;
  11. ;Revision History:
  12. ; 07-07-84 GFW initial version
  13. ; 11-20-85 GFW mask overflow/underflow/precision exceptions;
  14. ; fixed affine/projective infinity confusion
  15. ; 09-12-86 BCM added _Flanguage to distinguish languages
  16. ; 10-21-86 BCM use _cpower rather than _Flanguage to
  17. ; distinguish C and FORTRAN exponentiation semantics
  18. ; 06-11-87 GFW faster dispatch code - all in-line
  19. ; 10-26-87 BCM minor changes for new cmacros.inc
  20. ; 04-25-88 WAJ _cpower is now on stack for MTHREAD
  21. ; 08-24-88 WAJ 386 version
  22. ; 02-01-92 GDP ported to NT
  23. ; 09-06-94 CFW Replace MTHREAD with _MT.
  24. ;
  25. ;*******************************************************************************
  26. .xlist
  27. include cruntime.inc
  28. include mrt386.inc
  29. include elem87.inc
  30. .list
  31. .data
  32. globalT _indefinite, 0FFFFC000000000000000R
  33. globalT _piby2, 03FFFC90FDAA22168C235R
  34. staticQ One, 03FF0000000000000R
  35. ifndef _MT ; by default assume C pow() semantics
  36. globalB _cpower, 1 ; if zero, assume FORTRAN (or other) exponentiation
  37. endif ;_MT ; semantics
  38. labelB XAMtoTagTab
  39. ; C2 C1 C0 C3 Meaning Meaning Tag 0
  40. db 2 * ISIZE ; 0 0 0 0 +Unnormal => NAN 10 0
  41. db 1 * ISIZE ; 0 0 0 1 +Zero => Zero 01 0
  42. db 2 * ISIZE ; 0 0 1 0 +NAN => NAN 10 0
  43. db 2 * ISIZE ; 0 0 1 1 Empty => NAN 10 0
  44. db 2 * ISIZE ; 0 1 0 0 -Unnormal => NAN 10 0
  45. db 1 * ISIZE ; 0 1 0 1 -Zero => Zero 01 0
  46. db 2 * ISIZE ; 0 1 1 0 -NAN => NAN 10 0
  47. db 2 * ISIZE ; 0 1 1 1 Empty => NAN 10 0
  48. db 0 * ISIZE ; 1 0 0 0 +Normal => Valid 00 0
  49. db 1 * ISIZE ; 1 0 0 1 +Denormal => Zero 01 0
  50. db 3 * ISIZE ; 1 0 1 0 +Infinity => Infinity 11 0
  51. db 2 * ISIZE ; 1 0 1 1 Empty => NAN 10 0
  52. db 0 * ISIZE ; 1 1 0 0 -Normal => Valid 00 0
  53. db 1 * ISIZE ; 1 1 0 1 -Denormal => Zero 01 0
  54. db 3 * ISIZE ; 1 1 1 0 -Infinity => Infinity 11 0
  55. db 2 * ISIZE ; 1 1 1 1 Empty => NAN 10 0
  56. CODESEG
  57. xamTOS macro
  58. cmp [rdx].fnumber, OP_SQRT ; check for sqrt
  59. JSNE cwdefault
  60. mov bx, word ptr (DSF.savCntrl)
  61. or bh, 2 ; set precision control to 53 bits
  62. and bh, 0feh
  63. mov bl, 03fh ; mask exceptions
  64. jmp setcw
  65. lab cwdefault
  66. mov bx, 133fh ; default cw
  67. lab setcw
  68. mov DSF.setCntrl, bx ; set new control word
  69. fldcw DSF.setCntrl ; load new control word
  70. mov rbx, dataoffset XAMtoTagTab ; Prepare for XLAT
  71. fxam
  72. mov DSF.Function, rdx ; save function jmp table address
  73. fstsw DSF.StatusWord
  74. mov DSF.ErrorType, 0 ; clear error code
  75. endm
  76. comdisp macro
  77. CBI
  78. and rcx, 0404h ; clear all but signs from CX
  79. mov rbx, rdx
  80. add rbx, rax
  81. add rbx, size funtab ; skip over name, error vals, etc.
  82. jmp [rbx] ; jmp to function
  83. endm
  84. ; Will dispatch to the special case routines for the single argument
  85. ; transcendental functions. It assumes on entry that the 8087 stack
  86. ; has the argument on the top of its stack and that DX has been set
  87. ; to the address of the dispatch table (which should be in Tag order).
  88. ; This routine will FXAM the top of the 8087 stack, generate Tag info
  89. ; from the condition code, and jump to the corresponding dispatch table
  90. ; entry. In the process of creating the offset for the XLAT instruction
  91. ; bit 2 of CL will be loaded with the sign of the argument. DI may not
  92. ; be used in any computations.
  93. _trandisp1 proc near
  94. xamTOS ; setup control word and check TOS
  95. fwait
  96. mov cl, CondCode
  97. shl cl, 1
  98. sar cl, 1
  99. rol cl, 1
  100. mov al, cl
  101. and al, 0fh
  102. xlat
  103. comdisp
  104. _trandisp1 endp
  105. ; Will dispatch to the special case routines for the double argument
  106. ; transcendental functions. It assumes on entry that the 8087 has arg1
  107. ; next to the top and arg2 on top of the 8087 stack and that DX has
  108. ; been set to the address of the dispatch table (which should be in
  109. ; Tag-arg1,Tag-arg2 order). This routine will FXAM the top two
  110. ; registers of the 8087 stack,generate Tag info from the condition
  111. ; codes, and jump to the corresponding dispatch table entry. In the
  112. ; process of creating the offsets for the XLAT statements bit 2 of
  113. ; CH and bit 2 of CL will be loaded with the signs of the arguments
  114. ; next to the top and on top, respectively, of the 8087 stack. DI may
  115. ; not be used in any computations.
  116. _trandisp2 proc near
  117. xamTOS ; setup control word and check TOS
  118. fxch
  119. mov cl, CondCode
  120. fxam
  121. fstsw DSF.StatusWord
  122. fxch
  123. mov ch, CondCode
  124. shl ch, 1
  125. sar ch, 1
  126. rol ch, 1
  127. mov al, ch
  128. and al, 0fh
  129. xlat
  130. mov ah, al
  131. shl cl, 1
  132. sar cl, 1
  133. rol cl, 1
  134. mov al, cl
  135. and al, 0fh
  136. xlat
  137. shl ah, 1
  138. shl ah, 1
  139. or al, ah
  140. comdisp
  141. _trandisp2 endp
  142. page
  143. ;----------------------------------------------------------
  144. ;
  145. ; SPECIAL CASE RETURN FUNCTIONS
  146. ;
  147. ;----------------------------------------------------------
  148. ;
  149. ; INPUTS - The signs of the last, second to last
  150. ; arguments are in CH, CL respectively.
  151. ;
  152. ; OUTPUT - The result is the stack top.
  153. ;
  154. ;----------------------------------------------------------
  155. labelNP _rttospopde, PUBLIC
  156. call setDOMAIN
  157. labelNP _rttospop, PUBLIC
  158. fxch ; remove ST(1)
  159. labelNP _rtnospop, PUBLIC
  160. fstp st(0) ; remove ST(0)
  161. labelNP _rttosnpop, PUBLIC
  162. ret ; return TOS
  163. labelNP _rtnospopde, PUBLIC
  164. call setDOMAIN
  165. jmp _rtnospop
  166. ;----------------------------------------------------------
  167. labelNP _rtzeropop, PUBLIC
  168. fstp st(0) ; remove ST(0)
  169. labelNP _rtzeronpop, PUBLIC
  170. fstp st(0) ; remove ST(0)
  171. fldz ; push 0.0 onto stack
  172. ret
  173. ;----------------------------------------------------------
  174. labelNP _rtonepop, PUBLIC
  175. fstp st(0) ; remove ST(0)
  176. labelNP _rtonenpop, PUBLIC
  177. fstp st(0) ; remove ST(0)
  178. fld1 ; push 1.0 onto stack
  179. ret
  180. ;----------------------------------------------------------
  181. isQNAN macro
  182. fstp DSF.Fac ; use ten byte storage
  183. fld DSF.Fac
  184. test byte ptr [DSF.Fac+7], 40h ; Test for QNaN or SNaN
  185. endm
  186. labelNP _tosnan1, PUBLIC ; ST(0) is a NaN
  187. isQNAN
  188. JSZ _tossnan1
  189. mov DSF.Errortype, DOMAIN_QNAN
  190. ret
  191. lab _tossnan1
  192. mov DSF.Errortype, DOMAIN
  193. fadd [One] ; Convert SNaN to QNaN
  194. ret
  195. labelNP _nosnan2, PUBLIC ; ST(1) is a NaN
  196. fxch
  197. labelNP _tosnan2, PUBLIC ; ST(0) is a NaN
  198. isQNAN
  199. JSZ _tossnan2
  200. mov DSF.Errortype, DOMAIN_QNAN
  201. jmp _tosnan2ret
  202. lab _tossnan2
  203. mov DSF.Errortype, DOMAIN
  204. lab _tosnan2ret
  205. fadd ; Propagate NaN and pop
  206. ret
  207. labelNP _nan2, PUBLIC
  208. isQNAN
  209. JSZ _snan2
  210. fxch
  211. isQNAN
  212. JSZ _snan2
  213. mov DSF.Errortype, DOMAIN_QNAN
  214. jmp _nan2ret
  215. lab _snan2
  216. mov DSF.Errortype, DOMAIN
  217. lab _nan2ret
  218. fadd ; Propagate NaN and pop
  219. ret
  220. ;----------------------------------------------------------
  221. labelNP _rtindfpop, PUBLIC
  222. fstp st(0) ; remove ST(0)
  223. labelNP _rtindfnpop, PUBLIC
  224. fstp st(0) ; remove ST(0)
  225. fld [_indefinite] ; push real indefinite onto stack
  226. cmp DSF.ErrorType, 0 ; if error set
  227. JSG retj ; must be SING, don't set DOMAIN
  228. labelNP _rttosnpopde, PUBLIC
  229. lab setDOMAIN
  230. mov DSF.ErrorType, DOMAIN
  231. lab retj
  232. or cl, cl ; test sign in cl
  233. ret
  234. ;----------------------------------------------------------
  235. labelNP _rtchsifneg, PUBLIC
  236. or cl, cl ; if arg is negative
  237. JSZ chsifnegret ; negate top of stack
  238. fchs
  239. lab chsifnegret
  240. ret
  241. end