1/*
2===========================================================================
3Copyright (C) 1999-2005 Id Software, Inc.
4
5This file is part of Quake III Arena source code.
6
7Quake III Arena source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12Quake III Arena source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with Foobar; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20===========================================================================
21*/
22
23//
24// Sys_SnapVector NASM code (Andrew Henderson)
25// See win32/win_shared.c for the Win32 equivalent
26// This code is provided to ensure that the
27//  rounding behavior (and, if necessary, the
28//  precision) of DLL and QVM code are identical
29//  e.g. for network-visible operations.
30// See ftol.nasm for operations on a single float,
31//  as used in compiled VM and DLL code that does
32//  not use this system trap.
33//
34
35// 23/09/05 Ported to gas by intel2gas, best supporting actor Tim Angus
36// <tim@ngus.net>
37
38#include "qasm.h"
39
40#if id386
41.data
42
43fpucw:  .long   0
44cw037F: .long   0x037F
45
46.text
47
48// void Sys_SnapVector( float *v )
49.globl C(Sys_SnapVector)
50C(Sys_SnapVector):
51        pushl   %eax
52        pushl   %ebp
53        movl    %esp,%ebp
54
55        fnstcw  fpucw
56        movl    12(%ebp),%eax
57        fldcw   cw037F
58        flds    (%eax)
59        fistpl  (%eax)
60        fildl   (%eax)
61        fstps   (%eax)
62        flds    4(%eax)
63        fistpl  4(%eax)
64        fildl   4(%eax)
65        fstps   4(%eax)
66        flds    8(%eax)
67        fistpl  8(%eax)
68        fildl   8(%eax)
69        fstps   8(%eax)
70        fldcw   fpucw
71
72        popl %ebp
73        popl %eax
74        ret
75
76// void Sys_SnapVectorCW( float *v, unsigned short int cw )
77.globl C(Sys_SnapVectorCW)
78C(Sys_SnapVectorCW):
79        pushl   %eax
80        pushl   %ebp
81        movl    %esp,%ebp
82
83        fnstcw  fpucw
84        movl    12(%ebp),%eax
85        fldcw   16(%ebp)
86        flds    (%eax)
87        fistpl  (%eax)
88        fildl   (%eax)
89        fstps   (%eax)
90        flds    4(%eax)
91        fistpl  4(%eax)
92        fildl   4(%eax)
93        fstps   4(%eax)
94        flds    8(%eax)
95        fistpl  8(%eax)
96        fildl   8(%eax)
97        fstps   8(%eax)
98        fldcw   fpucw
99
100        popl %ebp
101        popl %eax
102        ret
103#endif
104