Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

snapvector.nasm (2414B)


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