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.

442 lines
8.6 KiB

  1. page ,132
  2. subttl emlsdbl.asm - Load/Store Double Precision Numbers
  3. ;***
  4. ;emlsdbl.asm - Load/Store Double Precision Numbers
  5. ;
  6. ; Copyright (c) 1986-89, Microsoft Corporation
  7. ;
  8. ;Purpose:
  9. ; Load/Store Double Precision Numbers
  10. ;
  11. ; This Module contains Proprietary Information of Microsoft
  12. ; Corporation and should be treated as Confidential.
  13. ;
  14. ;Revision History:
  15. ; See emulator.hst
  16. ;
  17. ;*******************************************************************************
  18. ;*********************************************************************;
  19. ; ;
  20. ; Load Double Real ;
  21. ; ;
  22. ;*********************************************************************;
  23. ;
  24. ; Subroutine pushes double internal with double IEEE format at ES:SI
  25. ProfBegin LSDBL
  26. FLDSTOver:
  27. xchg edi, esi ; di = TOS, es:si = double in memory
  28. call OverStk
  29. xchg edi, esi ; di = TOS, es:si = double in memory
  30. jmp short FLDSTOk
  31. even
  32. pub eFLDdr
  33. mov edi, [CURstk] ; Get current register
  34. cmp edi, [LIMstk] ; Is current register the last register?
  35. jae short FLDSTOver ; Then report overflow.
  36. FLDSTOk:
  37. add edi, Reg87Len ; Move to next free register.
  38. mov [CURstk], edi ; Update current top of stack
  39. LDUS2AX
  40. mov bp, ax
  41. LDUS2AX
  42. mov dx, ax
  43. LDUS2AX
  44. mov cx, ax
  45. LDUS2AX ; get final 2 bytes of source
  46. mov esi, edi ; ds:si = TOS
  47. mov bx, ax ; Double in bx:cx:dx:bp
  48. ; assume we have a valid non-zero number so normalize and store
  49. SHL BP,1
  50. RCL DX,1
  51. RCL CX,1
  52. RCL BX,1
  53. SHL BP,1
  54. RCL DX,1
  55. RCL CX,1
  56. RCL BX,1
  57. SHL BP,1
  58. RCL DX,1
  59. RCL CX,1
  60. RCL BX,1
  61. OR BL,80H ; Set leading bit of mantissa
  62. MOV MB7[esi],BL
  63. MOV MB5[esi],CX
  64. MOV MB3[esi],DX
  65. MOV MB1[esi],BP
  66. OR CX,BP ; Will need to determine if number is 0 later
  67. OR CX,DX ; so mash all the bits together
  68. MOV DH,AH
  69. AND DH,Sign ; Mask everything but sign
  70. MOV Flag[esi],DH ; and store
  71. XOR DH,DH ; Clear for Tag
  72. MOV MB0[esi],DH ; Also clear out least significant byte
  73. AND AH,7FH ; Remove sign from exponent
  74. SHR AX,1 ; Adjust
  75. SHR AX,1
  76. SHR AX,1
  77. SHR AX,1
  78. CMP AX,DexpMax ; See if number is NAN or Inf
  79. JE short DNANorInf
  80. CMP AX,DexpMin ; See if number is Zero or Denormal
  81. JE short DZeroorDenorm
  82. SUB AX,DexpBias ; Unbias exponent
  83. pub DStoreExpnTag
  84. MOV Expon[esi],AX
  85. MOV Tag[esi],DH
  86. RET
  87. pub DNANorInf
  88. MOV AX,IexpMax - IexpBias ; Set exponent to internal max
  89. MOV DH,Special ; Set Tag to show NAN or Inf
  90. CMP BL,80H ; If anything other than leading bit
  91. JNE short DStoreExpnTag ; is set number is NAN (not Inf)
  92. OR CX,CX
  93. JNE DStoreExpnTag
  94. OR DH,ZROorINF ; Set Tag to show Inf
  95. JMP DStoreExpnTag
  96. pub DZeroorDenorm
  97. CMP BL,80H ; If anything other than leading bit
  98. JNE short DDenormal ; is set number is Denormal
  99. OR CX,CX
  100. JNE short DDenormal
  101. MOV AX,IexpMin - IexpBias ; Set exponent to internal min
  102. MOV DH,ZROorINF ; Set Tag to show 0
  103. JMP DStoreExpnTag
  104. pub DDenormal
  105. OR [CURerr],Denormal ; Set Denormal Exception
  106. SUB AX,DexpBias ; unbias the Exponent
  107. MOV BP,MB0[esi] ; must refetch mantissa and normalize
  108. MOV DX,MB2[esi]
  109. MOV CX,MB4[esi]
  110. MOV BX,MB6[esi]
  111. INC AX ; Shift once if exp = expmin
  112. pub DNormalize
  113. DEC AX ; Drop exponent
  114. SHL BP,1 ; Shift mantissa
  115. RCL DX,1
  116. RCL CX,1
  117. RCL BX,1
  118. OR BX,BX
  119. JNS DNormalize
  120. MOV MB0[esi],BP ; Store mantissa
  121. MOV MB2[esi],DX
  122. MOV MB4[esi],CX
  123. MOV MB6[esi],BX
  124. XOR DH,DH ; Clear Tag
  125. JMP DStoreExpnTag
  126. page
  127. ;*********************************************************************;
  128. ; ;
  129. ; Store Double Real ;
  130. ; ;
  131. ;*********************************************************************;
  132. ;
  133. pub DSpecial
  134. TEST CL,Special ; NAN or INF?
  135. JNE short DDNANorINF
  136. XOR AX,AX ; Number is zero
  137. STAX2US
  138. STAX2US
  139. STAX2US
  140. STAX2US
  141. JMP DCommonExit
  142. pub DDNANorINF
  143. TEST CL,ZROorINF
  144. JNE short DInf
  145. MOV DX,MB1[esi] ; Number is a NAN
  146. MOV BX,MB3[esi] ; Fetch Mantissa
  147. MOV AX,MB5[esi]
  148. MOV CL,MB7[esi]
  149. SHR CL,1 ; Shift into place
  150. RCR AX,1
  151. RCR BX,1
  152. RCR DX,1
  153. SHR CL,1
  154. RCR AX,1
  155. RCR BX,1
  156. RCR DX,1
  157. SHR CL,1
  158. RCR AX,1
  159. RCR BX,1
  160. RCR DX,1
  161. ; Now store the Mantissa
  162. XCHG DX,AX
  163. STAX2US
  164. MOV AX,BX
  165. STAX2US
  166. MOV AX,DX
  167. STAX2US
  168. MOV BH,Flag[esi] ; Pick up Sign
  169. AND BH,Sign
  170. MOV AX,DexpMax*16 ; Load shifted max exponent
  171. OR AH,BH ; Merge in sign
  172. OR AL,CL ; Merge in top bits of Mantissa
  173. STAX2US
  174. JMP DCommonExit
  175. pub DInf
  176. MOV BL,Flag[esi]
  177. AND BL,Sign
  178. JMP DSignedInfinity
  179. pub JMPDOver
  180. JMP DOver
  181. pub JMPDUnder
  182. JMP DUnder
  183. pub JMPDSpecial
  184. JMP DSpecial
  185. even
  186. pub eFSTdr
  187. ; internal TOS register at DS:SI to double IEEE in memory at ES:DI
  188. MOV edi,esi ; 10 save target memory offset
  189. MOV esi,[CURstk] ; 14 source offset is current TOS
  190. MOV CL,Tag[esi] ; See if number is NAN, Inf, or 0
  191. OR CL,CL
  192. JNZ short JMPDSpecial
  193. MOV CL,Flag[esi] ; Pick up sign
  194. if fastSP
  195. TEST CL,Single
  196. JZ DD1
  197. MOV word ptr MB0[esi],0
  198. MOV word ptr MB2[esi],0
  199. MOV byte ptr MB4[esi],0
  200. DD1:
  201. endif
  202. MOV BP,Expon[esi] ; See if we blatently over or under flow
  203. CMP BP,DexpMax - DexpBias
  204. JGE JMPDOver
  205. CMP BP,DexpMin - DexpBias
  206. JLE JMPDUnder
  207. ;Since we won't have room to decide about rounding after we load
  208. ;the mantissa we will determine the rounding style first
  209. MOV AL,MB0[esi] ; Low byte becomes sticky bit ...
  210. MOV DX,MB1[esi] ; when combined with lo 2 bits of next byte
  211. OR AL,AL
  212. JZ short NOSTK
  213. OR DL,1
  214. pub NOSTK
  215. TEST DL,7H ; See if anything will be chopped off in truncation
  216. JZ short DTRUNC
  217. OR [CURerr],Precision ; number is not exact so set flag and round
  218. MOV AL,[CWcntl] ; Pick up rounding control
  219. ; Mantissa gets incremented for rounding only on these conditions:
  220. ; (UP and +) or (DOWN and -) or
  221. ; (NEAR and Roundbit and (Sticky or Oddlastbit))
  222. SHR AL,1
  223. SHR AL,1
  224. SHR AL,1
  225. JC short StDOWNorCHOP53
  226. SHR AL,1
  227. JC short StUP53
  228. pub StNEAR53
  229. TEST DL,4H ; 3rd bit over is round bit
  230. JZ short DTRUNC
  231. TEST DL,0BH ; 4th bit is last bit, 1st and 2nd are Sticky
  232. JZ short DTRUNC
  233. pub DINC ; Know we must increment mantissa so
  234. MOV BX,MB3[esi] ; Fetch mantissa
  235. MOV AX,MB5[esi]
  236. MOV CL,MB7[esi]
  237. AND CL,7FH ; Mask off leading bit
  238. ADD DX,8H ; Add 1 to what will be last bit after the shift
  239. ADC BX,0
  240. ADC AX,0
  241. ADC CL,0
  242. JNS short DShift
  243. AND CL,7FH ; Mask off leading bit
  244. INC BP ; Increment exponent
  245. CMP BP,DexpMax - DexpBias
  246. JL short DShift ; And test for the rare chance we went over
  247. JMP short DOverReset
  248. even
  249. pub StUP53
  250. SHL CL,1 ; Test sign
  251. JNC short DINC ; UP and + means inc
  252. JMP SHORT DTRUNC
  253. pub StDOWNorCHOP53
  254. SHR AL,1
  255. JC short StCHOP53
  256. pub StDOWN53
  257. SHL CL,1 ; Test sign
  258. JC short DINC ; DOWN and - means inc
  259. StCHOP53:
  260. pub DTRUNC
  261. MOV BX,MB3[esi] ; Fetch mantissa
  262. MOV AX,MB5[esi]
  263. MOV CL,MB7[esi]
  264. AND CL,7FH ; Mask off leading bit
  265. pub DShift
  266. SHR CL,1
  267. RCR AX,1
  268. RCR BX,1
  269. RCR DX,1
  270. SHR CL,1
  271. RCR AX,1
  272. RCR BX,1
  273. RCR DX,1
  274. SHR CL,1
  275. RCR AX,1
  276. RCR BX,1
  277. RCR DX,1
  278. ; Now store the Mantissa
  279. XCHG DX,AX
  280. STAX2US
  281. MOV AX,BX
  282. STAX2US
  283. MOV AX,DX
  284. STAX2US
  285. MOV AX,BP ; Merge in the exponent
  286. ADD AX,DexpBias ; Bias exponent
  287. SHL AX,1 ; Shift into position
  288. SHL AX,1
  289. SHL AX,1
  290. SHL AX,1
  291. OR AL,CL ; Merge in top bits of Mantissa
  292. MOV CL,Flag[esi] ; Pick up sign
  293. AND CL,Sign
  294. OR AH,CL ; Merge in the sign
  295. STAX2US
  296. pub DCommonExit
  297. RET ; 8 return
  298. pub DOverReset ; We come here if we stored 6 bytes of mantissa
  299. ; befor detecting overflow so must reset pointer
  300. SUB edi,6 ; to double in memory
  301. pub DOver ; Here on overflow
  302. OR [CURerr],Overflow + Precision
  303. MOV BL,Flag[esi]
  304. AND BL,Sign ; Mask to sign
  305. MOV CL,[CWcntl] ; Determine rounding style
  306. SHR CL,1
  307. SHR CL,1
  308. SHR CL,1
  309. JC short StMOVDNorCHP53
  310. SHR CL,1
  311. JC short StMOVUP53
  312. StMOVNEAR53:
  313. pub DSignedInfinity
  314. MOV esi,offset IEEEinfinityD
  315. pub DStore
  316. csMVSI2US
  317. csMVSI2US
  318. csMVSI2US
  319. LODS word ptr cs:[esi]
  320. OR AH,BL ;Overstore correct sign
  321. STAX2US
  322. JMP DCommonExit
  323. pub StMOVDNorCHP53
  324. SHR CL,1
  325. JC short StMOVCHOP53
  326. pub StMOVDOWN53
  327. OR BL,BL ; DOWN and + means biggest
  328. JNZ short DSignedInfinity
  329. StMOVCHOP53:
  330. pub DSignedBiggest
  331. MOV esi,offset IEEEbiggestD
  332. JMP DStore
  333. pub StMOVUP53
  334. OR BL,BL ; UP and - means biggest
  335. JZ DSignedInfinity
  336. JMP DSignedBiggest
  337. pub DUnder
  338. OR [CURerr],Underflow+Precision ; Set flag
  339. ADD BP,DexpBias ; Bias the exponent which was less than
  340. NEG BP ; Min = 0 so convert to positive difference
  341. ifdef i386
  342. movzx ecx,BP ; Convert to shift count
  343. else
  344. MOV CX,BP ; Convert to shift count
  345. endif
  346. ADD ecx,4 ; 3 for Double format 1 to expose hidden bit
  347. MOV DH,Flag[esi] ; Need and exp of 0 for denormal
  348. AND DH,Sign
  349. MOV DL,MB7[esi]
  350. MOV BX,MB5[esi]
  351. MOV BP,MB3[esi]
  352. MOV AX,MB1[esi]
  353. pub DshiftLoop
  354. SHR DL,1
  355. RCR BX,1
  356. RCR BP,1
  357. RCR AX,1
  358. LOOP DshiftLoop
  359. STAX2US
  360. MOV AX,BP
  361. STAX2US
  362. MOV AX,BX
  363. STAX2US
  364. MOV AX,DX
  365. STAX2US
  366. JMP DCommonExit
  367. ProfEnd LSDBL