ftol.nasm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ;===========================================================================
  2. ;Copyright (C) 1999-2005 Id Software, Inc.
  3. ;
  4. ;This file is part of Quake III Arena source code.
  5. ;
  6. ;Quake III Arena source code is free software; you can redistribute it
  7. ;and/or modify it under the terms of the GNU General Public License as
  8. ;published by the Free Software Foundation; either version 2 of the License,
  9. ;or (at your option) any later version.
  10. ;
  11. ;Quake III Arena source code is distributed in the hope that it will be
  12. ;useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;GNU General Public License for more details.
  15. ;
  16. ;You should have received a copy of the GNU General Public License
  17. ;along with Foobar; if not, write to the Free Software
  18. ;Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. ;===========================================================================
  20. ;
  21. ; qftol -- fast floating point to long conversion.
  22. ;
  23. segment .data
  24. temp dd 0.0
  25. fpucw dd 0
  26. ; Precision Control Field , 2 bits / 0x0300
  27. ; PC24 0x0000 Single precision (24 bits).
  28. ; PC53 0x0200 Double precision (53 bits).
  29. ; PC64 0x0300 Extended precision (64 bits).
  30. ; Rounding Control Field, 2 bits / 0x0C00
  31. ; RCN 0x0000 Rounding to nearest (even).
  32. ; RCD 0x0400 Rounding down (directed, minus).
  33. ; RCU 0x0800 Rounding up (directed plus).
  34. ; RC0 0x0C00 Rounding towards zero (chop mode).
  35. ; rounding towards nearest (even)
  36. cw027F dd 0x027F ; double precision
  37. cw037F dd 0x037F ; extended precision
  38. ; rounding towards zero (chop mode)
  39. cw0E7F dd 0x0E7F ; double precision
  40. cw0F7F dd 0x0F7F ; extended precision
  41. segment .text
  42. ;
  43. ; int qftol( void ) - default control word
  44. ;
  45. global qftol
  46. qftol:
  47. fistp dword [temp]
  48. mov eax, [temp]
  49. ret
  50. ;
  51. ; int qftol027F( void ) - DirectX FPU
  52. ;
  53. global qftol027F
  54. qftol027F:
  55. fnstcw [fpucw]
  56. fldcw [cw027F]
  57. fistp dword [temp]
  58. fldcw [fpucw]
  59. mov eax, [temp]
  60. ret
  61. ;
  62. ; int qftol037F( void ) - Linux FPU
  63. ;
  64. global qftol037F
  65. qftol037F:
  66. fnstcw [fpucw]
  67. fldcw [cw037F]
  68. fistp dword [temp]
  69. fldcw [fpucw]
  70. mov eax, [temp]
  71. ret
  72. ;
  73. ; int qftol0F7F( void ) - ANSI
  74. ;
  75. global qftol0F7F
  76. qftol0F7F:
  77. fnstcw [fpucw]
  78. fldcw [cw0F7F]
  79. fistp dword [temp]
  80. fldcw [fpucw]
  81. mov eax, [temp]
  82. ret
  83. ;
  84. ; int qftol0E7F( void )
  85. ;
  86. global qftol0E7F
  87. qftol0E7F:
  88. fnstcw [fpucw]
  89. fldcw [cw0E7F]
  90. fistp dword [temp]
  91. fldcw [fpucw]
  92. mov eax, [temp]
  93. ret
  94. ;
  95. ; long Q_ftol( float q )
  96. ;
  97. global Q_ftol
  98. Q_ftol:
  99. fld dword [esp+4]
  100. fistp dword [temp]
  101. mov eax, [temp]
  102. ret
  103. ;
  104. ; long qftol0F7F( float q ) - Linux FPU
  105. ;
  106. global Q_ftol0F7F
  107. Q_ftol0F7F:
  108. fnstcw [fpucw]
  109. fld dword [esp+4]
  110. fldcw [cw0F7F]
  111. fistp dword [temp]
  112. fldcw [fpucw]
  113. mov eax, [temp]
  114. ret