Debian Codegraph @

code/asm/ftola.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 2011 Thilo Schulz <[email protected]>
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #include "qasm-inline.h"
24
25 #if defined (__i386__) || defined(__x86_64__)
26 static const unsigned short fpucw = 0x0C7F;
27
28 /*
29 * GNU inline asm ftol conversion functions using SSE or FPU
30 */
31
32 long qftolsse(float f)
33 {
34 long retval;
35
36 __asm__ volatile
37 (
38 "cvttss2si %1, %0\n"
39 : "=r" (retval)
40 : "x" (f)
41 );
42
43 return retval;
44 }
45
46 int qvmftolsse(void)
47 {
48 int retval;
49
50 __asm__ volatile
51 (
52 "movss (" EDI ", " EBX ", 4), %%xmm0\n"
53 "cvttss2si %%xmm0, %0\n"
54 : "=r" (retval)
55 :
56 : "%xmm0"
57 );
58
59 return retval;
60 }
61
62 long qftolx87(float f)
63 {
64 long retval;
65 unsigned short oldcw = 0;
66
67 __asm__ volatile
68 (
69 "fnstcw %2\n"
70 "fldcw %3\n"
71 "flds %1\n"
72 "fistpl %1\n"
73 "fldcw %2\n"
74 "mov %1, %0\n"
75 : "=r" (retval)
76 : "m" (f), "m" (oldcw), "m" (fpucw)
77 );
78
79 return retval;
80 }
81
82 int qvmftolx87(void)
83 {
84 int retval;
85 unsigned short oldcw = 0;
86
87 __asm__ volatile
88 (
89 "fnstcw %1\n"
90 "fldcw %2\n"
91 "flds (" EDI ", " EBX ", 4)\n"
92 "fistpl (" EDI ", " EBX ", 4)\n"
93 "fldcw %1\n"
94 "mov (" EDI ", " EBX ", 4), %0\n"
95 : "=r" (retval)
96 : "m" (oldcw), "m" (fpucw)
97 );
98
99 return retval;
100 }
101 #endif