snapvector.nasm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ; Sys_SnapVector NASM code (Andrew Henderson)
  22. ; See win32/win_shared.c for the Win32 equivalent
  23. ; This code is provided to ensure that the
  24. ; rounding behavior (and, if necessary, the
  25. ; precision) of DLL and QVM code are identical
  26. ; e.g. for network-visible operations.
  27. ; See ftol.nasm for operations on a single float,
  28. ; as used in compiled VM and DLL code that does
  29. ; not use this system trap.
  30. ;
  31. segment .data
  32. fpucw dd 0
  33. cw037F dd 0x037F ; Rounding to nearest (even).
  34. segment .text
  35. ; void Sys_SnapVector( float *v )
  36. global Sys_SnapVector
  37. Sys_SnapVector:
  38. push eax
  39. push ebp
  40. mov ebp, esp
  41. fnstcw [fpucw]
  42. mov eax, dword [ebp + 12]
  43. fldcw [cw037F]
  44. fld dword [eax]
  45. fistp dword [eax]
  46. fild dword [eax]
  47. fstp dword [eax]
  48. fld dword [eax + 4]
  49. fistp dword [eax + 4]
  50. fild dword [eax + 4]
  51. fstp dword [eax + 4]
  52. fld dword [eax + 8]
  53. fistp dword [eax + 8]
  54. fild dword [eax + 8]
  55. fstp dword [eax + 8]
  56. fldcw [fpucw]
  57. pop ebp
  58. pop eax
  59. ret
  60. ; void Sys_SnapVectorCW( float *v, unsigned short int cw )
  61. global Sys_SnapVectorCW
  62. Sys_SnapVector_cw:
  63. push eax
  64. push ebp
  65. mov ebp, esp
  66. fnstcw [fpucw]
  67. mov eax, dword [ebp + 12]
  68. fldcw [ebp + 16]
  69. fld dword [eax]
  70. fistp dword [eax]
  71. fild dword [eax]
  72. fstp dword [eax]
  73. fld dword [eax + 4]
  74. fistp dword [eax + 4]
  75. fild dword [eax + 4]
  76. fstp dword [eax + 4]
  77. fld dword [eax + 8]
  78. fistp dword [eax + 8]
  79. fild dword [eax + 8]
  80. fstp dword [eax + 8]
  81. fldcw [fpucw]
  82. pop ebp
  83. pop eax
  84. ret