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.

126 lines
3.4 KiB

  1. subttl emfconst.asm - Loading of 387 on chip constants
  2. page
  3. ;*******************************************************************************
  4. ;emfconst.asm - Loading of 387 on chip constants
  5. ;
  6. ; Microsoft Confidential
  7. ;
  8. ; Copyright (c) Microsoft Corporation 1991
  9. ; All Rights Reserved
  10. ;
  11. ;Purpose:
  12. ; FLDZ, FLD1, FLDPI, FLDL2T, FLDL2E, FLDLG2, FLDLN2 instructions
  13. ;Inputs:
  14. ; edi = [CURstk]
  15. ;
  16. ;Revision History:
  17. ;
  18. ; [] 09/05/91 TP Initial 32-bit version.
  19. ;
  20. ;*******************************************************************************
  21. PrevStackWrap edi,Ld1 ;Tied to PrevStackElem below
  22. EM_ENTRY eFLD1
  23. eFLD1:
  24. ;edi = [CURstk]
  25. PrevStackElem edi,Ld1 ;Point to receiving location
  26. cmp EMSEG:[edi].bTag,bTAG_EMPTY ;Is it empty?
  27. jnz FldErr ;in emload.asm
  28. mov EMSEG:[CURstk],edi
  29. mov EMSEG:[edi].lManLo,0
  30. mov EMSEG:[edi].lManHi,1 shl 31
  31. mov EMSEG:[edi].ExpSgn,bTAG_SNGL ;Exponent and sign are zero
  32. ret
  33. PrevStackWrap edi,Ldz ;Tied to PrevStackElem below
  34. EM_ENTRY eFLDZ
  35. eFLDZ:
  36. ;edi = [CURstk]
  37. PrevStackElem edi,Ldz ;Point to receiving location
  38. cmp EMSEG:[edi].bTag,bTAG_EMPTY ;Is it empty?
  39. jnz FldErr ;in emload.asm
  40. mov EMSEG:[CURstk],edi
  41. mov EMSEG:[edi].lManLo,0
  42. mov EMSEG:[edi].lManHi,0
  43. mov EMSEG:[edi].ExpSgn,bTAG_ZERO ;Exponent and sign are zero
  44. ret
  45. ;*******************************************************************************
  46. ;The 5 irrational constants need to be adjusted according to rounding mode.
  47. DefConst macro cName,low,high,expon,round
  48. c&cName&lo equ low
  49. c&cName&hi equ high
  50. c&cName&exp equ expon
  51. c&cName&rnd equ round
  52. endm
  53. DefConst FLDL2T,0CD1B8AFEH,0D49A784BH,00001H,0
  54. DefConst FLDL2E,05C17F0BCH,0B8AA3B29H,00000H,1
  55. DefConst FLDLG2,0FBCFF799H,09A209A84H,0FFFEH,1
  56. DefConst FLDLN2,0D1CF79ACH,0B17217F7H,0FFFFH,1
  57. DefConst FLDPI,02168C235H,0C90FDAA2H,00001H,1
  58. LoadConstant macro cName,nojmp
  59. EM_ENTRY e&cName
  60. e&cName:
  61. mov ebx,c&cName&hi
  62. mov edx,c&cName&lo
  63. mov ecx,c&cName&exp shl 16 + c&cName&rnd
  64. ifb <nojmp>
  65. jmp CommonConst
  66. endif
  67. endm
  68. LoadConstant FLDL2T
  69. LoadConstant FLDL2E
  70. LoadConstant FLDLG2
  71. LoadConstant FLDLN2
  72. LoadConstant FLDPI,nojmp
  73. CommonConst:
  74. ;ebx:edx = mantissa of constant, rounded to nearest
  75. ;high ecx = exponent
  76. ;ch = sign
  77. ;cl = rounding flag: 1 indicates roundup occured for round nearest, else 0
  78. ;edi = [CURstk]
  79. test EMSEG:[CWcntl],RoundControl ;Check rounding control bits
  80. .erre RCnear eq 0
  81. jnz NotNearConst ;Adjust constant if not round nearest
  82. StoreConst:
  83. mov cl,bTAG_VALID
  84. mov esi,edx
  85. jmp FldCont ;In emload.asm
  86. NotNearConst:
  87. ;It is known that the five constants positive irrational numbers.
  88. ;This means they are never exact, and chop and round down always
  89. ;produce the same answer. It is also know that the values are such
  90. ;that rounding only alters bits in the last byte.
  91. ;
  92. ;A flag in cl indicates if the number has been rounded up for round
  93. ;nearest (1 = rounded up, 0 = rounded down). In chop and round down
  94. ;modes, this flag can be directly subtracted to reverse the rounding.
  95. ;In round up mode, we want to add (1-flag) = -(flag-1).
  96. .erre RCchop eq 0CH ;Two bits set only for chop
  97. test EMSEG:[CWcntl],RCdown ;DOWN bit set?
  98. jnz DirectRoundConst ;If so, it's chop or down
  99. ;Round Up mode
  100. dec cl ;-1 if round up needed, else 0
  101. DirectRoundConst:
  102. sub dl,cl ;Directed rounding
  103. jmp StoreConst