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.

195 lines
3.9 KiB

  1. page ,132
  2. subttl emfmul.asm - Multiplication
  3. ;***
  4. ;emfmisc.asm - Multiplication
  5. ;
  6. ; Copyright (c) 1986-89, Microsoft Corporation
  7. ;
  8. ;Purpose:
  9. ; Multiplication
  10. ;
  11. ;
  12. ; This Module contains Proprietary Information of Microsoft
  13. ; Corporation and should be treated as Confidential.
  14. ;
  15. ;Revision History:
  16. ; See emulator.hst
  17. ;
  18. ;*******************************************************************************
  19. ;-----------------------------------------;
  20. ; ;
  21. ; Multiplication ;
  22. ; ;
  23. ;-----------------------------------------;
  24. ; Perform multiply by summing partial products of 16x16 hardware multiply.
  25. ; Before each multiply, the operands are checked for zero to see if it can be
  26. ; skipped, since it's a slow operation on the 8086. The sum is kept in
  27. ; registers as much as possible. Any insignificant bits lost are ORed together
  28. ; and kept in a word on the top of the stack. This can be used for sticky bit
  29. ; rounding. First we will need some macros.
  30. ProfBegin FMUL
  31. MULP MACRO SIOFFSET,DIOFFSET,NEXTLOC
  32. ;Will multiply the words found at the given offsets if those words
  33. ;are non-0. since we assume the numbers are normalized and the
  34. ;most significant word has offset 6 we know that words with offset
  35. ;6 are non-0 hence the conditional code in this macro.
  36. MOV AX,SIOFFSET[esi]
  37. IF SIOFFSET - 6 ;When SI offset is 6 it is most sig word hence not 0
  38. OR AX,AX
  39. JZ short NEXTLOC
  40. ENDIF
  41. IF DIOFFSET - 6
  42. MOV DX,DIOFFSET[edi]
  43. OR DX,DX
  44. JZ short NEXTLOC
  45. MUL DX
  46. ELSE
  47. MUL WORD PTR DIOFFSET[edi]
  48. ENDIF
  49. ENDM
  50. ADDP MACRO HI,MID,LO
  51. ;Will add the double word result of a multiply to the triple word
  52. ; at HI:MID:LO using HI to record overflow
  53. ADD LO,AX
  54. ADC MID,DX
  55. ADC HI,0
  56. ENDM
  57. STICKY MACRO R
  58. ;R is the register containing the least significant word which
  59. ;should be ORed to the sticky bit (kept on the stack) and then
  60. ;cleared so the register can be reused
  61. POP eax
  62. OR AX,R
  63. PUSH eax
  64. XOR R,R
  65. ENDM
  66. page
  67. RMBRQQ: ; Routine MUL Both must see if we have two singles.
  68. if fastSP
  69. MOV BX,DX
  70. XOR BX,Single + 256*Single
  71. TEST BX,Single + 256*Single
  72. JNZ RMDRQQ
  73. MOV BX,OFFSET TMSRQQ
  74. JMP [BX]
  75. endif ;fastSP
  76. pub RMDRQQ ;RoutineMulDouble SI & DI point to valid non-0 reals
  77. ; AX CX are the exponents
  78. ; DL DH are the signs
  79. if fastSP
  80. CALL CoerceToDouble ; insure that both args are double
  81. endif ;fastSP
  82. PUSH ebp ; Must save BP
  83. MOV BH,DH ; Save Single double flag
  84. XOR DH,DL ; Get sign onto stack
  85. PUSH edx
  86. ADD AX,CX ; New exponent is sum of old plus 1
  87. INC AX ; because of the normalize step
  88. PUSH eax ; Save it while we Multiply
  89. AND BH,DL
  90. pub PROD1
  91. XOR BX,BX
  92. MOV BP,BX
  93. MOV CX,BX
  94. MULP 0,0,PROD2
  95. MOV BP,AX ; Save insignificant bits
  96. MOV CX,DX
  97. pub PROD2
  98. PUSH ebp ; Save Sticky bit on stack
  99. xor ebp, ebp ; bp is now the working high word of bp:bx:cx
  100. MULP 0,2,PROD3
  101. ADDP BP,BX,CX
  102. pub PROD3
  103. MULP 2,0,PROD4
  104. ADDP BP,BX,CX
  105. pub PROD4
  106. STICKY CX
  107. MULP 0,4,PROD5
  108. ADDP CX,BP,BX
  109. pub PROD5
  110. MULP 2,2,PROD6
  111. ADDP CX,BP,BX
  112. pub PROD6
  113. MULP 4,0,PROD7
  114. ADDP CX,BP,BX
  115. pub PROD7
  116. STICKY BX
  117. MULP 0,6,PROD8
  118. ADDP BX,CX,BP
  119. pub PROD8
  120. MULP 2,4,PROD9
  121. ADDP BX,CX,BP
  122. pub PROD9
  123. MULP 4,2,PROD10
  124. ADDP BX,CX,BP
  125. pub PROD10
  126. MULP 6,0,PROD11
  127. ADDP BX,CX,BP
  128. pub PROD11
  129. MOV DX,BP ; Everything but guard and round go to sticky
  130. AND BP,03FFFH
  131. STICKY BP
  132. PUSH edx ; Save guard and round on stack
  133. MULP 2,6,PROD12
  134. ADDP BP,BX,CX
  135. pub PROD12
  136. MULP 4,4,PROD13
  137. ADDP BP,BX,CX
  138. pub PROD13
  139. MULP 6,2,PROD14
  140. ADDP BP,BX,CX
  141. pub PROD14
  142. PUSH ecx ; Save LSW on stack (not enough registers)
  143. XOR CX,CX
  144. MULP 4,6,PROD15
  145. ADDP CX,BP,BX
  146. pub PROD15
  147. MULP 6,4,PROD16
  148. ADDP CX,BP,BX
  149. pub PROD16
  150. MULP 6,6,PROD17
  151. ADD AX,BP
  152. ADC DX,CX
  153. POP ecx
  154. POP ebp ; Result in DX:AX:BX:CX:BP Sticky on stack
  155. MOV DI,DX
  156. MOV DX,CX
  157. MOV CX,BX
  158. MOV BX,AX ; Result in DI:BX:CX:DX:BP
  159. POP eax ; Merge Sticky bit into BP
  160. OR AX,AX
  161. JZ short STBITOK
  162. OR BP,1
  163. pub STBITOK
  164. POP esi ; Exponent in SI, Sign on Stack, Old BP on Stack
  165. JMP NORMSHF ; Result must be normalized at most 1 bit
  166. ProfEnd FMUL