-
Notifications
You must be signed in to change notification settings - Fork 5
/
EmitRCU.cpp
353 lines (308 loc) · 17.4 KB
/
EmitRCU.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#include "basetypes.h"
#include "EmitMisc.h"
#include "EmitRCU.h"
#include "InstructionCache.h"
#include "InstructionDependencies.h"
#include "mpe.h"
#include "X86EmitTypes.h"
void Emit_DECRc0(EmitterVariables * const vars, const Nuance &nuance)
{
const x86BaseReg rc0ReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_RC0);
//const x86BaseReg ccReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_CC);
const x86BaseReg rc0WriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_RC0);
const x86BaseReg ccWriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_CC);
const int32 rc0Disp = GetMiscRegEmitDisp(vars,REGINDEX_RC0);
const int32 ccDisp = GetMiscRegEmitDisp(vars,REGINDEX_CC);
//eax = rc0WriteBack, ebx = rc0M1, ecx = flagSetMask, ebp = 0
if(vars->miscRegOutDep & DEPENDENCY_FLAG_C0Z)
{
//cc &= ~CC_COUNTER0_ZERO
vars->mpe->nativeCodeCache.X86Emit_ANDIM(~CC_COUNTER0_ZERO, x86MemPtr::x86MemPtr_dword, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
//rc0WriteBack = rc0
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, rc0ReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc0Disp);
//flagSetMask = CC_COUNTER0_ZERO
vars->mpe->nativeCodeCache.X86Emit_MOVIR(CC_COUNTER0_ZERO, x86Reg::x86Reg_ecx);
//rc0M1 = rc0
vars->mpe->nativeCodeCache.X86Emit_MOVRR(x86Reg::x86Reg_ebx, x86Reg::x86Reg_eax);
//ebp = 0
vars->mpe->nativeCodeCache.X86Emit_XORRR(x86Reg::x86Reg_ebp, x86Reg::x86Reg_ebp);
//rc0M1 = rc0 - 1
vars->mpe->nativeCodeCache.X86Emit_DECR(x86Reg::x86Reg_ebx);
//if(rc0M1 >= 0), rc0WriteBack = rc0 (otherwise rc0M1)
vars->mpe->nativeCodeCache.X86Emit_CMOVNLRR(x86Reg::x86Reg_eax, x86Reg::x86Reg_ebx);
//if(rc0M1) > 0), flagSetMask = 0 (otherwise CC_COUNTER0_ZERO)
vars->mpe->nativeCodeCache.X86Emit_CMOVNLERR(x86Reg::x86Reg_ecx, x86Reg::x86Reg_ebp);
if(vars->miscRegOutDep & DEPENDENCY_MASK_RC0)
{
//rc0 = rc0WriteBack
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax, rc0WriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc0Disp);
}
if(vars->miscRegOutDep & DEPENDENCY_FLAG_C0Z)
{
//cc = cc | flagSetMask
vars->mpe->nativeCodeCache.X86Emit_ORRM(x86Reg::x86Reg_ecx, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
}
void Emit_DECRc1(EmitterVariables * const vars, const Nuance &nuance)
{
const x86BaseReg rc1ReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_RC1);
//const x86BaseReg ccReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_CC);
const x86BaseReg rc1WriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_RC1);
const x86BaseReg ccWriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_CC);
const int32 rc1Disp = GetMiscRegEmitDisp(vars,REGINDEX_RC1);
const int32 ccDisp = GetMiscRegEmitDisp(vars,REGINDEX_CC);
if(vars->miscRegOutDep & DEPENDENCY_FLAG_C1Z)
{
vars->mpe->nativeCodeCache.X86Emit_ANDIM(~CC_COUNTER1_ZERO, x86MemPtr::x86MemPtr_dword, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, rc1ReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc1Disp);
vars->mpe->nativeCodeCache.X86Emit_MOVIR(CC_COUNTER1_ZERO, x86Reg::x86Reg_ecx);
vars->mpe->nativeCodeCache.X86Emit_MOVRR(x86Reg::x86Reg_ebx, x86Reg::x86Reg_eax);
vars->mpe->nativeCodeCache.X86Emit_XORRR(x86Reg::x86Reg_ebp, x86Reg::x86Reg_ebp);
vars->mpe->nativeCodeCache.X86Emit_DECR(x86Reg::x86Reg_ebx);
vars->mpe->nativeCodeCache.X86Emit_CMOVNLRR(x86Reg::x86Reg_eax, x86Reg::x86Reg_ebx);
vars->mpe->nativeCodeCache.X86Emit_CMOVNLERR(x86Reg::x86Reg_ecx, x86Reg::x86Reg_ebp);
if(vars->miscRegOutDep & DEPENDENCY_MASK_RC1)
{
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax, rc1WriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc1Disp);
}
if(vars->miscRegOutDep & DEPENDENCY_FLAG_C1Z)
{
vars->mpe->nativeCodeCache.X86Emit_ORRM(x86Reg::x86Reg_ecx, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
}
void Emit_DECBoth(EmitterVariables * const vars, const Nuance &nuance)
{
//const x86BaseReg rc0ReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_RC0);
//const x86BaseReg rc1ReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_RC1);
//const x86BaseReg ccReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_CC);
//const x86BaseReg rc0WriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_RC0);
//const x86BaseReg rc1WriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_RC1);
//const x86BaseReg ccWriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_CC);
//const int32 rc0Disp = GetMiscRegEmitDisp(vars,REGINDEX_RC0);
//const int32 rc1Disp = GetMiscRegEmitDisp(vars,REGINDEX_RC1);
//const int32 ccDisp = GetMiscRegEmitDisp(vars,REGINDEX_CC);
Emit_DECRc0(vars,nuance);
Emit_DECRc1(vars,nuance);
/*
//eax = rc0WriteBack, ebx = rc0M1, ecx = flagSetMask, ebp = 0
if(vars->miscRegOutDep & DEPENDENCY_FLAG_C0Z)
{
//cc &= ~(CC_COUNTER0_ZERO | CC_COUNTER1_ZERO)
vars->mpe->nativeCodeCache.X86Emit_ANDIM(~(CC_COUNTER0_ZERO | CC_COUNTER1_ZERO), x86MemPtr::x86MemPtr_dword, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
//rc0WriteBack = rc0
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, rc0ReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc0Disp);
//flagSetMask = CC_COUNTER0_ZERO
vars->mpe->nativeCodeCache.X86Emit_MOVIR(CC_COUNTER0_ZERO, x86Reg::x86Reg_ecx);
//rc0M1 = rc0
vars->mpe->nativeCodeCache.X86Emit_MOVRR(x86Reg::x86Reg_ebx, x86Reg::x86Reg_eax);
//ebp = 0
vars->mpe->nativeCodeCache.X86Emit_XORRR(x86Reg::x86Reg_ebp, x86Reg::x86Reg_ebp);
//rc0M1 = rc0 - 1
vars->mpe->nativeCodeCache.X86Emit_DECR(x86Reg::x86Reg_ebx);
//if(rc0M1 >= 0), rc0WriteBack = rc0M1 (otherwise rc0)
vars->mpe->nativeCodeCache.X86Emit_CMOVNLRR(x86Reg::x86Reg_eax, x86Reg::x86Reg_ebx);
//if(rc0M1 > 0), flagSetMask = 0 (otherwise CC_COUNTER0_ZERO)
vars->mpe->nativeCodeCache.X86Emit_CMOVNLERR(x86Reg::x86Reg_ecx, x86Reg::x86Reg_ebp);
//rc0 = rc0WriteBack
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax, rc0WriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc0Disp);
//cc = cc | flagSetMask
vars->mpe->nativeCodeCache.X86Emit_ORRM(x86Reg::x86Reg_ecx, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
//eax = rc1WriteBack, ebx = rc1M1, ecx = flagSetMask, ebp = 0
//rc1WriteBack = rc1
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, rc1ReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc1Disp);
//flagSetMask = CC_COUNTER1_ZERO
vars->mpe->nativeCodeCache.X86Emit_MOVIR(CC_COUNTER1_ZERO, x86Reg::x86Reg_ecx);
//rc1M1 = rc1
vars->mpe->nativeCodeCache.X86Emit_MOVRR(x86Reg::x86Reg_ebx, x86Reg::x86Reg_eax);
//rc1M1 = rc1 - 1
vars->mpe->nativeCodeCache.X86Emit_DECR(x86Reg::x86Reg_ebx);
//if(rc1M1 >= 0), rc1WriteBack = rc1M1 (otherwise rc1)
vars->mpe->nativeCodeCache.X86Emit_CMOVNLRR(x86Reg::x86Reg_eax, x86Reg::x86Reg_ebx);
//if(rc1M1 > 0), flagSetMask = 0 (otherwise CC_COUNTER1_ZERO)
vars->mpe->nativeCodeCache.X86Emit_CMOVNLERR(x86Reg::x86Reg_ecx, x86Reg::x86Reg_ebp);
//rc1 = rc1WriteBack
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax, rc1WriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, rc1Disp);
//cc = cc | flagSetMask
vars->mpe->nativeCodeCache.X86Emit_ORRM(x86Reg::x86Reg_ecx, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
*/
}
void Emit_DEC(EmitterVariables * const vars, const Nuance &nuance)
{
if(nuance.fields[FIELD_RCU_INFO] & RCU_DEC_RC0)
{
Emit_DECRc0(vars, nuance);
}
if(nuance.fields[FIELD_RCU_INFO] & RCU_DEC_RC1)
{
Emit_DECRc1(vars, nuance);
}
}
void Emit_ADDRImmediateOnly(EmitterVariables * const vars, const Nuance &nuance)
{
const uint32 indexRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_DEST];
const x86BaseReg indexRegReadBaseReg = GetMiscRegReadBaseReg(vars,indexRegIndex);
const x86BaseReg indexRegWriteBaseReg = GetMiscRegWriteBaseReg(vars,indexRegIndex);
const int32 indexRegDisp = GetMiscRegEmitDisp(vars,indexRegIndex);
if(vars->miscRegOutDep)
{
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax,indexRegReadBaseReg,x86IndexReg::x86IndexReg_none,x86ScaleVal::x86Scale_1,indexRegDisp);
vars->mpe->nativeCodeCache.X86Emit_ADDIR(nuance.fields[FIELD_RCU_SRC], x86Reg::x86Reg_eax);
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax,indexRegWriteBaseReg,x86IndexReg::x86IndexReg_none,x86ScaleVal::x86Scale_1,indexRegDisp);
}
}
void Emit_ADDRImmediate(EmitterVariables * const vars, const Nuance &nuance)
{
Emit_ADDRImmediateOnly(vars, nuance);
Emit_DEC(vars, nuance);
}
void Emit_ADDRScalarOnly(EmitterVariables * const vars, const Nuance &nuance)
{
const uint32 indexRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_DEST];
const uint32 scalarRegIndex = nuance.fields[FIELD_RCU_SRC];
const x86BaseReg indexRegReadBaseReg = GetMiscRegReadBaseReg(vars,indexRegIndex);
const x86BaseReg indexRegWriteBaseReg = GetMiscRegWriteBaseReg(vars,indexRegIndex);
const x86BaseReg scalarRegReadBaseReg = GetScalarRegReadBaseReg(vars,scalarRegIndex);
const int32 indexRegDisp = GetMiscRegEmitDisp(vars,indexRegIndex);
const int32 scalarRegDisp = GetScalarRegEmitDisp(vars,scalarRegIndex);
if(vars->miscRegOutDep)
{
//eax = rcu_dest
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, scalarRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, scalarRegDisp);
vars->mpe->nativeCodeCache.X86Emit_ADDMR(x86Reg::x86Reg_eax, indexRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, indexRegDisp);
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax, indexRegWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, indexRegDisp);
}
}
void Emit_ADDRScalar(EmitterVariables * const vars, const Nuance &nuance)
{
Emit_ADDRScalarOnly(vars, nuance);
Emit_DEC(vars, nuance);
}
void Emit_MVRImmediateOnly(EmitterVariables * const vars, const Nuance &nuance)
{
const uint32 indexRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_DEST];
const x86BaseReg indexRegWriteBaseReg = GetMiscRegWriteBaseReg(vars,indexRegIndex);
const int32 indexRegDisp = GetMiscRegEmitDisp(vars,indexRegIndex);
if(vars->miscRegOutDep)
{
vars->mpe->nativeCodeCache.X86Emit_MOVIM(nuance.fields[FIELD_RCU_SRC], x86MemPtr::x86MemPtr_dword, indexRegWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, indexRegDisp);
}
}
void Emit_MVRImmediate(EmitterVariables * const vars, const Nuance &nuance)
{
Emit_MVRImmediateOnly(vars, nuance);
Emit_DEC(vars, nuance);
}
void Emit_MVRScalarOnly(EmitterVariables * const vars, const Nuance &nuance)
{
const uint32 indexRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_DEST];
const uint32 scalarRegIndex = nuance.fields[FIELD_RCU_SRC];
const x86BaseReg indexRegWriteBaseReg = GetMiscRegWriteBaseReg(vars,indexRegIndex);
const x86BaseReg scalarRegReadBaseReg = GetScalarRegReadBaseReg(vars,scalarRegIndex);
const int32 indexRegDisp = GetMiscRegEmitDisp(vars,indexRegIndex);
const int32 scalarRegDisp = GetScalarRegEmitDisp(vars,scalarRegIndex);
if(vars->miscRegOutDep)
{
//eax = rcu_src
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, scalarRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, scalarRegDisp);
//rcu_dest = eax
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_eax, indexRegWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, indexRegDisp);
}
}
void Emit_MVRScalar(EmitterVariables * const vars, const Nuance &nuance)
{
Emit_MVRScalarOnly(vars,nuance);
Emit_DEC(vars,nuance);
}
void Emit_RangeOnly(EmitterVariables * const vars, const Nuance &nuance)
{
constexpr uint32 l_testmodmi = 0;
constexpr uint32 l_exit = 1;
const uint32 srcRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_SRC];
//const uint32 destRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_DEST];
//const x86BaseReg ccReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_CC);
const x86BaseReg xyRangeReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_XYRANGE);
const x86BaseReg uvRangeReadBaseReg = GetMiscRegReadBaseReg(vars,REGINDEX_UVRANGE);
const x86BaseReg srcRegReadBaseReg = GetMiscRegReadBaseReg(vars,nuance.fields[FIELD_RCU_SRC]);
//const x86BaseReg destRegReadBaseReg = GetMiscRegReadBaseReg(vars,nuance.fields[FIELD_RCU_DEST]);
const x86BaseReg ccWriteBaseReg = GetMiscRegWriteBaseReg(vars,REGINDEX_CC);
//const x86BaseReg destRegWriteBaseReg = GetMiscRegWriteBaseReg(vars,nuance.fields[FIELD_RCU_DEST]);
const int32 xyRangeDisp = GetMiscRegEmitDisp(vars,REGINDEX_XYRANGE);
const int32 uvRangeDisp = GetMiscRegEmitDisp(vars,REGINDEX_UVRANGE);
const int32 srcRegDisp = GetMiscRegEmitDisp(vars,srcRegIndex);
//const int32 destRegDisp = GetMiscRegEmitDisp(vars,destRegIndex);
const int32 ccDisp = GetMiscRegEmitDisp(vars,REGINDEX_CC);
vars->mpe->nativeCodeCache.patchMgr.Reset();
switch(nuance.fields[FIELD_RCU_SRC])
{
case 0:
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, xyRangeReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, xyRangeDisp);
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_ebx, srcRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, srcRegDisp);
break;
case 1:
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, xyRangeReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, xyRangeDisp);
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_ebx, srcRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, srcRegDisp);
vars->mpe->nativeCodeCache.X86Emit_SHLIR(x86Reg::x86Reg_eax, 16);
break;
case 2:
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, uvRangeReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, uvRangeDisp);
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_ebx, srcRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, srcRegDisp);
break;
case 3:
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_eax, uvRangeReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, uvRangeDisp);
vars->mpe->nativeCodeCache.X86Emit_MOVMR(x86Reg::x86Reg_ebx, srcRegReadBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, srcRegDisp);
vars->mpe->nativeCodeCache.X86Emit_SHLIR(x86Reg::x86Reg_eax, 16);
break;
}
if(vars->miscRegOutDep & (DEPENDENCY_FLAG_MODGE | DEPENDENCY_FLAG_MODMI))
{
vars->mpe->nativeCodeCache.X86Emit_ANDIM(~(FLAG_DEPENDENCIES(vars->miscRegOutDep & (DEPENDENCY_FLAG_MODMI | DEPENDENCY_FLAG_MODGE))), x86MemPtr::x86MemPtr_dword, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
vars->mpe->nativeCodeCache.X86Emit_ANDIR(0x03FF0000, x86Reg::x86Reg_eax);
vars->mpe->nativeCodeCache.X86Emit_MOVRR(x86Reg::x86Reg_ecx, x86Reg::x86Reg_ebx);
vars->mpe->nativeCodeCache.X86Emit_ANDIR(0xFFFF0000, x86Reg::x86Reg_ecx);
//eax = rcu_range, ebx = rcu_src, ecx = rcu_src & 0xFFFF0000
vars->mpe->nativeCodeCache.X86Emit_CMPRR(x86Reg::x86Reg_ecx, x86Reg::x86Reg_eax);
vars->mpe->nativeCodeCache.X86Emit_JCC_Label(X86_CC_L,l_testmodmi);
vars->mpe->nativeCodeCache.X86Emit_SUBRR(x86Reg::x86Reg_ebx, x86Reg::x86Reg_eax);
if(vars->miscRegOutDep & DEPENDENCY_FLAG_MODGE)
{
vars->mpe->nativeCodeCache.X86Emit_ORIM(CC_MODGE, x86MemPtr::x86MemPtr_dword, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
vars->mpe->nativeCodeCache.X86Emit_JMPI_Label(l_exit);
vars->mpe->nativeCodeCache.SetLabelPointer(l_testmodmi);
//compare rcu_src to zero
vars->mpe->nativeCodeCache.X86Emit_CMPIR(0,x86Reg::x86Reg_ebx);
vars->mpe->nativeCodeCache.X86Emit_JCC_Label(X86_CC_NL,l_exit);
vars->mpe->nativeCodeCache.X86Emit_ADDRR(x86Reg::x86Reg_ebx, x86Reg::x86Reg_eax);
if(vars->miscRegOutDep & DEPENDENCY_FLAG_MODMI)
{
vars->mpe->nativeCodeCache.X86Emit_ORIM(CC_MODMI, x86MemPtr::x86MemPtr_dword, ccWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, ccDisp);
}
vars->mpe->nativeCodeCache.SetLabelPointer(l_exit);
vars->mpe->nativeCodeCache.patchMgr.ApplyPatches();
//ebx = modulo_writeback
}
void Emit_Range(EmitterVariables * const vars, const Nuance &nuance)
{
Emit_RangeOnly(vars,nuance);
Emit_DEC(vars,nuance);
}
void Emit_ModuloOnly(EmitterVariables * const vars, const Nuance &nuance)
{
const uint32 destRegIndex = REGINDEX_RX + nuance.fields[FIELD_RCU_DEST];
const x86BaseReg destRegWriteBaseReg = GetMiscRegWriteBaseReg(vars,nuance.fields[FIELD_RCU_DEST]);
const int32 destRegDisp = GetMiscRegEmitDisp(vars,destRegIndex);
Emit_RangeOnly(vars,nuance);
if(vars->miscRegOutDep & (~DEPENDENCY_FLAG_ALLFLAGS))
{
vars->mpe->nativeCodeCache.X86Emit_MOVRM(x86Reg::x86Reg_ebx, destRegWriteBaseReg, x86IndexReg::x86IndexReg_none, x86ScaleVal::x86Scale_1, destRegDisp);
}
}
void Emit_Modulo(EmitterVariables * const vars, const Nuance &nuance)
{
Emit_ModuloOnly(vars,nuance);
Emit_DEC(vars,nuance);
}