/[pcsx2_0.9.7]/trunk/common/src/x86emitter/tools.cpp
ViewVC logotype

Contents of /trunk/common/src/x86emitter/tools.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 10 months ago) by william
File size: 7149 byte(s)
committing r3113 initial commit again...
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #include "PrecompiledHeader.h"
17 #include "tools.h"
18
19 // To make sure regs don't get changed while in the recompiler,
20 // use Freeze/Thaw in MMXRegisters, XMMRegisters, & Registers.
21
22
23 // used to disable register freezing during cpuBranchTests (registers
24 // are safe then since they've been completely flushed)
25 bool g_EEFreezeRegs = false;
26
27 /////////////////////////////////////////////////////////////////////
28 // MMX Register Freezing
29 //
30
31 namespace MMXRegisters
32 {
33 u8 stack_depth = 0;
34 __aligned16 u64 data[8];
35
36 __forceinline bool Saved()
37 {
38 return ( stack_depth > 0);
39 }
40
41 __forceinline void Freeze()
42 {
43 if (!g_EEFreezeRegs) return;
44
45 //DevCon.Warning("MMXRegisters::Freeze: depth[%d]\n", stack_depth);
46 stack_depth++;
47
48 if (stack_depth > 1)
49 {
50 //DevCon.Warning("MMX Already Saved!\n");
51 return;
52 }
53
54 #ifdef _MSC_VER
55 __asm {
56 mov ecx, offset data
57 movntq mmword ptr [ecx+0], mm0
58 movntq mmword ptr [ecx+8], mm1
59 movntq mmword ptr [ecx+16], mm2
60 movntq mmword ptr [ecx+24], mm3
61 movntq mmword ptr [ecx+32], mm4
62 movntq mmword ptr [ecx+40], mm5
63 movntq mmword ptr [ecx+48], mm6
64 movntq mmword ptr [ecx+56], mm7
65 emms
66 }
67 #else
68 __asm__ volatile(
69 ".intel_syntax noprefix\n"
70 "movq [%[data]+0x00], mm0\n"
71 "movq [%[data]+0x08], mm1\n"
72 "movq [%[data]+0x10], mm2\n"
73 "movq [%[data]+0x18], mm3\n"
74 "movq [%[data]+0x20], mm4\n"
75 "movq [%[data]+0x28], mm5\n"
76 "movq [%[data]+0x30], mm6\n"
77 "movq [%[data]+0x38], mm7\n"
78 "emms\n"
79 ".att_syntax\n" : : [data]"r"(data) : "memory"
80 );
81 #endif
82 }
83
84 __forceinline void Thaw()
85 {
86 if (!g_EEFreezeRegs) return;
87
88 //DevCon.Warning("MMXRegisters::Thaw: depth[%d]\n", stack_depth);
89
90 if (!Saved())
91 {
92 //DevCon.Warning("MMX Not Saved!\n");
93 return;
94 }
95 stack_depth--;
96
97 if (Saved()) return;
98
99 #ifdef _MSC_VER
100 __asm {
101 mov ecx, offset data
102 movq mm0, mmword ptr [ecx+0]
103 movq mm1, mmword ptr [ecx+8]
104 movq mm2, mmword ptr [ecx+16]
105 movq mm3, mmword ptr [ecx+24]
106 movq mm4, mmword ptr [ecx+32]
107 movq mm5, mmword ptr [ecx+40]
108 movq mm6, mmword ptr [ecx+48]
109 movq mm7, mmword ptr [ecx+56]
110 emms
111 }
112 #else
113 __asm__ volatile(
114 ".intel_syntax noprefix\n"
115 "movq mm0, [%[data]+0x00]\n"
116 "movq mm1, [%[data]+0x08]\n"
117 "movq mm2, [%[data]+0x10]\n"
118 "movq mm3, [%[data]+0x18]\n"
119 "movq mm4, [%[data]+0x20]\n"
120 "movq mm5, [%[data]+0x28]\n"
121 "movq mm6, [%[data]+0x30]\n"
122 "movq mm7, [%[data]+0x38]\n"
123 "emms\n"
124 ".att_syntax\n" : : [data]"r"(data) : "memory"
125 );
126 #endif
127 }
128 }
129
130 //////////////////////////////////////////////////////////////////////
131 // XMM Register Freezing
132 //
133
134 namespace XMMRegisters
135 {
136 u8 stack_depth = 0;
137 __aligned16 u64 data[2*iREGCNT_XMM];
138
139 __forceinline bool Saved()
140 {
141 return ( stack_depth > 0);
142 }
143
144 __forceinline void Freeze()
145 {
146 if (!g_EEFreezeRegs) return;
147
148 //DevCon.Warning("XMMRegisters::Freeze: depth[%d]\n", Depth());
149
150 stack_depth++;
151
152 if (stack_depth > 1)
153 {
154 //DevCon.Warning("XMM Already saved\n");
155 return;
156 }
157
158 #ifdef _MSC_VER
159 __asm {
160 mov ecx, offset data
161 movaps xmmword ptr [ecx+0x00], xmm0
162 movaps xmmword ptr [ecx+0x10], xmm1
163 movaps xmmword ptr [ecx+0x20], xmm2
164 movaps xmmword ptr [ecx+0x30], xmm3
165 movaps xmmword ptr [ecx+0x40], xmm4
166 movaps xmmword ptr [ecx+0x50], xmm5
167 movaps xmmword ptr [ecx+0x60], xmm6
168 movaps xmmword ptr [ecx+0x70], xmm7
169 }
170 #else
171 __asm__ volatile(
172 ".intel_syntax noprefix\n"
173 "movaps [%[data]+0x00], xmm0\n"
174 "movaps [%[data]+0x10], xmm1\n"
175 "movaps [%[data]+0x20], xmm2\n"
176 "movaps [%[data]+0x30], xmm3\n"
177 "movaps [%[data]+0x40], xmm4\n"
178 "movaps [%[data]+0x50], xmm5\n"
179 "movaps [%[data]+0x60], xmm6\n"
180 "movaps [%[data]+0x70], xmm7\n"
181 ".att_syntax\n" : : [data]"r"(data) : "memory"
182 );
183 #endif // _MSC_VER
184 }
185
186 __forceinline void Thaw()
187 {
188 if (!g_EEFreezeRegs) return;
189
190 //DevCon.Warning("XMMRegisters::Thaw: depth[%d]\n", Depth());
191
192 if (!Saved())
193 {
194 //DevCon.Warning("XMM Regs not saved!\n");
195 return;
196 }
197
198 // TODO: really need to backup all regs?
199 stack_depth--;
200 if (Saved()) return;
201
202 #ifdef _MSC_VER
203 __asm
204 {
205 mov ecx, offset data
206 movaps xmm0, xmmword ptr [ecx+0x00]
207 movaps xmm1, xmmword ptr [ecx+0x10]
208 movaps xmm2, xmmword ptr [ecx+0x20]
209 movaps xmm3, xmmword ptr [ecx+0x30]
210 movaps xmm4, xmmword ptr [ecx+0x40]
211 movaps xmm5, xmmword ptr [ecx+0x50]
212 movaps xmm6, xmmword ptr [ecx+0x60]
213 movaps xmm7, xmmword ptr [ecx+0x70]
214 }
215 #else
216 __asm__ volatile(
217 ".intel_syntax noprefix\n"
218 "movaps xmm0, [%[data]+0x00]\n"
219 "movaps xmm1, [%[data]+0x10]\n"
220 "movaps xmm2, [%[data]+0x20]\n"
221 "movaps xmm3, [%[data]+0x30]\n"
222 "movaps xmm4, [%[data]+0x40]\n"
223 "movaps xmm5, [%[data]+0x50]\n"
224 "movaps xmm6, [%[data]+0x60]\n"
225 "movaps xmm7, [%[data]+0x70]\n"
226 ".att_syntax\n" : : [data]"r"(data) : "memory"
227 );
228 #endif // _MSC_VER
229 }
230 };
231
232 //////////////////////////////////////////////////////////////////////
233 // Register Freezing
234 //
235
236 namespace Registers
237 {
238 __forceinline bool Saved()
239 {
240 return (XMMRegisters::Saved() || MMXRegisters::Saved());
241 }
242
243 __forceinline void Freeze()
244 {
245 XMMRegisters::Freeze();
246 MMXRegisters::Freeze();
247 }
248
249 __forceinline void Thaw()
250 {
251 XMMRegisters::Thaw();
252 MMXRegisters::Thaw();
253 }
254 }

  ViewVC Help
Powered by ViewVC 1.1.22