Statistics
| Branch: | Revision:

root / ops_template.h @ d57c4e01

History | View | Annotate | Download (19.1 kB)

1

    
2
#define DATA_BITS (1 << (3 + SHIFT))
3
#define SHIFT_MASK (DATA_BITS - 1)
4
#define SIGN_MASK (1 << (DATA_BITS - 1))
5

    
6
#if DATA_BITS == 8
7
#define SUFFIX b
8
#define DATA_TYPE uint8_t
9
#define DATA_STYPE int8_t
10
#define DATA_MASK 0xff
11
#elif DATA_BITS == 16
12
#define SUFFIX w
13
#define DATA_TYPE uint16_t
14
#define DATA_STYPE int16_t
15
#define DATA_MASK 0xffff
16
#elif DATA_BITS == 32
17
#define SUFFIX l
18
#define DATA_TYPE uint32_t
19
#define DATA_STYPE int32_t
20
#define DATA_MASK 0xffffffff
21
#else
22
#error unhandled operand size
23
#endif
24

    
25
/* dynamic flags computation */
26

    
27
static int glue(compute_all_add, SUFFIX)(void)
28
{
29
    int cf, pf, af, zf, sf, of;
30
    int src1, src2;
31
    src1 = CC_SRC;
32
    src2 = CC_DST - CC_SRC;
33
    cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1;
34
    pf = parity_table[(uint8_t)CC_DST];
35
    af = (CC_DST ^ src1 ^ src2) & 0x10;
36
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
37
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
38
    of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
39
    return cf | pf | af | zf | sf | of;
40
}
41

    
42
static int glue(compute_c_add, SUFFIX)(void)
43
{
44
    int src1, cf;
45
    src1 = CC_SRC;
46
    cf = (DATA_TYPE)CC_DST < (DATA_TYPE)src1;
47
    return cf;
48
}
49

    
50
static int glue(compute_all_adc, SUFFIX)(void)
51
{
52
    int cf, pf, af, zf, sf, of;
53
    int src1, src2;
54
    src1 = CC_SRC;
55
    src2 = CC_DST - CC_SRC - 1;
56
    cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1;
57
    pf = parity_table[(uint8_t)CC_DST];
58
    af = (CC_DST ^ src1 ^ src2) & 0x10;
59
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
60
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
61
    of = lshift((src1 ^ src2 ^ -1) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
62
    return cf | pf | af | zf | sf | of;
63
}
64

    
65
static int glue(compute_c_adc, SUFFIX)(void)
66
{
67
    int src1, cf;
68
    src1 = CC_SRC;
69
    cf = (DATA_TYPE)CC_DST <= (DATA_TYPE)src1;
70
    return cf;
71
}
72

    
73
static int glue(compute_all_sub, SUFFIX)(void)
74
{
75
    int cf, pf, af, zf, sf, of;
76
    int src1, src2;
77
    src1 = CC_SRC;
78
    src2 = CC_SRC - CC_DST;
79
    cf = (DATA_TYPE)src1 < (DATA_TYPE)src2;
80
    pf = parity_table[(uint8_t)CC_DST];
81
    af = (CC_DST ^ src1 ^ src2) & 0x10;
82
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
83
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
84
    of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
85
    return cf | pf | af | zf | sf | of;
86
}
87

    
88
static int glue(compute_c_sub, SUFFIX)(void)
89
{
90
    int src1, src2, cf;
91
    src1 = CC_SRC;
92
    src2 = CC_SRC - CC_DST;
93
    cf = (DATA_TYPE)src1 < (DATA_TYPE)src2;
94
    return cf;
95
}
96

    
97
static int glue(compute_all_sbb, SUFFIX)(void)
98
{
99
    int cf, pf, af, zf, sf, of;
100
    int src1, src2;
101
    src1 = CC_SRC;
102
    src2 = CC_SRC - CC_DST - 1;
103
    cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2;
104
    pf = parity_table[(uint8_t)CC_DST];
105
    af = (CC_DST ^ src1 ^ src2) & 0x10;
106
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
107
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
108
    of = lshift((src1 ^ src2) & (src1 ^ CC_DST), 12 - DATA_BITS) & CC_O;
109
    return cf | pf | af | zf | sf | of;
110
}
111

    
112
static int glue(compute_c_sbb, SUFFIX)(void)
113
{
114
    int src1, src2, cf;
115
    src1 = CC_SRC;
116
    src2 = CC_SRC - CC_DST - 1;
117
    cf = (DATA_TYPE)src1 <= (DATA_TYPE)src2;
118
    return cf;
119
}
120

    
121
static int glue(compute_all_logic, SUFFIX)(void)
122
{
123
    int cf, pf, af, zf, sf, of;
124
    cf = 0;
125
    pf = parity_table[(uint8_t)CC_DST];
126
    af = 0;
127
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
128
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
129
    of = 0;
130
    return cf | pf | af | zf | sf | of;
131
}
132

    
133
static int glue(compute_c_logic, SUFFIX)(void)
134
{
135
    return 0;
136
}
137

    
138
static int glue(compute_all_inc, SUFFIX)(void)
139
{
140
    int cf, pf, af, zf, sf, of;
141
    int src1, src2;
142
    src1 = CC_DST - 1;
143
    src2 = 1;
144
    cf = CC_SRC;
145
    pf = parity_table[(uint8_t)CC_DST];
146
    af = (CC_DST ^ src1 ^ src2) & 0x10;
147
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
148
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
149
    of = ((CC_DST & DATA_MASK) == SIGN_MASK) << 11;
150
    return cf | pf | af | zf | sf | of;
151
}
152

    
153
#if DATA_BITS == 32
154
static int glue(compute_c_inc, SUFFIX)(void)
155
{
156
    return CC_SRC;
157
}
158
#endif
159

    
160
static int glue(compute_all_dec, SUFFIX)(void)
161
{
162
    int cf, pf, af, zf, sf, of;
163
    int src1, src2;
164
    src1 = CC_DST + 1;
165
    src2 = 1;
166
    cf = CC_SRC;
167
    pf = parity_table[(uint8_t)CC_DST];
168
    af = (CC_DST ^ src1 ^ src2) & 0x10;
169
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
170
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
171
    of = ((CC_DST & DATA_MASK) == ((uint32_t)SIGN_MASK - 1)) << 11;
172
    return cf | pf | af | zf | sf | of;
173
}
174

    
175
static int glue(compute_all_shl, SUFFIX)(void)
176
{
177
    int cf, pf, af, zf, sf, of;
178
    cf = (CC_SRC >> (DATA_BITS - 1)) & CC_C;
179
    pf = parity_table[(uint8_t)CC_DST];
180
    af = 0; /* undefined */
181
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
182
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
183
    /* of is defined if shift count == 1 */
184
    of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O;
185
    return cf | pf | af | zf | sf | of;
186
}
187

    
188
#if DATA_BITS == 32
189
static int glue(compute_c_shl, SUFFIX)(void)
190
{
191
    return CC_SRC & 1;
192
}
193
#endif
194

    
195
static int glue(compute_all_sar, SUFFIX)(void)
196
{
197
    int cf, pf, af, zf, sf, of;
198
    cf = CC_SRC & 1;
199
    pf = parity_table[(uint8_t)CC_DST];
200
    af = 0; /* undefined */
201
    zf = ((DATA_TYPE)CC_DST == 0) << 6;
202
    sf = lshift(CC_DST, 8 - DATA_BITS) & 0x80;
203
    /* of is defined if shift count == 1 */
204
    of = lshift(CC_SRC ^ CC_DST, 12 - DATA_BITS) & CC_O; 
205
    return cf | pf | af | zf | sf | of;
206
}
207

    
208
/* various optimized jumps cases */
209

    
210
void OPPROTO glue(op_jb_sub, SUFFIX)(void)
211
{
212
    int src1, src2;
213
    src1 = CC_SRC;
214
    src2 = CC_SRC - CC_DST;
215

    
216
    if ((DATA_TYPE)src1 < (DATA_TYPE)src2)
217
        PC = PARAM1;
218
    else
219
        PC = PARAM2;
220
    FORCE_RET();
221
}
222

    
223
void OPPROTO glue(op_jz_sub, SUFFIX)(void)
224
{
225
    if ((DATA_TYPE)CC_DST == 0)
226
        PC = PARAM1;
227
    else
228
        PC = PARAM2;
229
    FORCE_RET();
230
}
231

    
232
void OPPROTO glue(op_jbe_sub, SUFFIX)(void)
233
{
234
    int src1, src2;
235
    src1 = CC_SRC;
236
    src2 = CC_SRC - CC_DST;
237

    
238
    if ((DATA_TYPE)src1 <= (DATA_TYPE)src2)
239
        PC = PARAM1;
240
    else
241
        PC = PARAM2;
242
    FORCE_RET();
243
}
244

    
245
void OPPROTO glue(op_js_sub, SUFFIX)(void)
246
{
247
    if (CC_DST & SIGN_MASK)
248
        PC = PARAM1;
249
    else
250
        PC = PARAM2;
251
    FORCE_RET();
252
}
253

    
254
void OPPROTO glue(op_jl_sub, SUFFIX)(void)
255
{
256
    int src1, src2;
257
    src1 = CC_SRC;
258
    src2 = CC_SRC - CC_DST;
259

    
260
    if ((DATA_STYPE)src1 < (DATA_STYPE)src2)
261
        PC = PARAM1;
262
    else
263
        PC = PARAM2;
264
    FORCE_RET();
265
}
266

    
267
void OPPROTO glue(op_jle_sub, SUFFIX)(void)
268
{
269
    int src1, src2;
270
    src1 = CC_SRC;
271
    src2 = CC_SRC - CC_DST;
272

    
273
    if ((DATA_STYPE)src1 <= (DATA_STYPE)src2)
274
        PC = PARAM1;
275
    else
276
        PC = PARAM2;
277
    FORCE_RET();
278
}
279

    
280
/* various optimized set cases */
281

    
282
void OPPROTO glue(op_setb_T0_sub, SUFFIX)(void)
283
{
284
    int src1, src2;
285
    src1 = CC_SRC;
286
    src2 = CC_SRC - CC_DST;
287

    
288
    T0 = ((DATA_TYPE)src1 < (DATA_TYPE)src2);
289
}
290

    
291
void OPPROTO glue(op_setz_T0_sub, SUFFIX)(void)
292
{
293
    T0 = ((DATA_TYPE)CC_DST == 0);
294
}
295

    
296
void OPPROTO glue(op_setbe_T0_sub, SUFFIX)(void)
297
{
298
    int src1, src2;
299
    src1 = CC_SRC;
300
    src2 = CC_SRC - CC_DST;
301

    
302
    T0 = ((DATA_TYPE)src1 <= (DATA_TYPE)src2);
303
}
304

    
305
void OPPROTO glue(op_sets_T0_sub, SUFFIX)(void)
306
{
307
    T0 = lshift(CC_DST, -(DATA_BITS - 1)) & 1;
308
}
309

    
310
void OPPROTO glue(op_setl_T0_sub, SUFFIX)(void)
311
{
312
    int src1, src2;
313
    src1 = CC_SRC;
314
    src2 = CC_SRC - CC_DST;
315

    
316
    T0 = ((DATA_STYPE)src1 < (DATA_STYPE)src2);
317
}
318

    
319
void OPPROTO glue(op_setle_T0_sub, SUFFIX)(void)
320
{
321
    int src1, src2;
322
    src1 = CC_SRC;
323
    src2 = CC_SRC - CC_DST;
324

    
325
    T0 = ((DATA_STYPE)src1 <= (DATA_STYPE)src2);
326
}
327

    
328
/* shifts */
329

    
330
void OPPROTO glue(glue(op_rol, SUFFIX), _T0_T1_cc)(void)
331
{
332
    int count, src;
333
    count = T1 & SHIFT_MASK;
334
    if (count) {
335
        CC_SRC = cc_table[CC_OP].compute_all() & ~(CC_O | CC_C);
336
        src = T0;
337
        T0 &= DATA_MASK;
338
        T0 = (T0 << count) | (T0 >> (DATA_BITS - count));
339
        CC_SRC |= (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | 
340
            (T0 & CC_C);
341
        CC_OP = CC_OP_EFLAGS;
342
    }
343
    FORCE_RET();
344
}
345

    
346
void OPPROTO glue(glue(op_ror, SUFFIX), _T0_T1_cc)(void)
347
{
348
    int count, src;
349
    count = T1 & SHIFT_MASK;
350
    if (count) {
351
        CC_SRC = cc_table[CC_OP].compute_all() & ~(CC_O | CC_C);
352
        src = T0;
353
        T0 &= DATA_MASK;
354
        T0 = (T0 >> count) | (T0 << (DATA_BITS - count));
355
        CC_SRC |= (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | 
356
            ((T0 >> (DATA_BITS - 1)) & CC_C);
357
        CC_OP = CC_OP_EFLAGS;
358
    }
359
    FORCE_RET();
360
}
361

    
362
void OPPROTO glue(glue(op_rcl, SUFFIX), _T0_T1_cc)(void)
363
{
364
    int count, res, eflags;
365
    unsigned int src;
366

    
367
    count = T1 & 0x1f;
368
#if DATA_BITS == 16
369
    count = rclw_table[count];
370
#elif DATA_BITS == 8
371
    count = rclb_table[count];
372
#endif
373
    if (count) {
374
        eflags = cc_table[CC_OP].compute_all();
375
        T0 &= DATA_MASK;
376
        src = T0;
377
        res = (T0 << count) | ((eflags & CC_C) << (count - 1));
378
        if (count > 1)
379
            res |= T0 >> (DATA_BITS + 1 - count);
380
        T0 = res;
381
        CC_SRC = (eflags & ~(CC_C | CC_O)) |
382
            (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | 
383
            ((src >> (DATA_BITS - count)) & CC_C);
384
        CC_OP = CC_OP_EFLAGS;
385
    }
386
    FORCE_RET();
387
}
388

    
389
void OPPROTO glue(glue(op_rcr, SUFFIX), _T0_T1_cc)(void)
390
{
391
    int count, res, eflags;
392
    unsigned int src;
393

    
394
    count = T1 & 0x1f;
395
#if DATA_BITS == 16
396
    count = rclw_table[count];
397
#elif DATA_BITS == 8
398
    count = rclb_table[count];
399
#endif
400
    if (count) {
401
        eflags = cc_table[CC_OP].compute_all();
402
        T0 &= DATA_MASK;
403
        src = T0;
404
        res = (T0 >> count) | ((eflags & CC_C) << (DATA_BITS - count));
405
        if (count > 1)
406
            res |= T0 << (DATA_BITS + 1 - count);
407
        T0 = res;
408
        CC_SRC = (eflags & ~(CC_C | CC_O)) |
409
            (lshift(src ^ T0, 11 - (DATA_BITS - 1)) & CC_O) | 
410
            ((src >> (count - 1)) & CC_C);
411
        CC_OP = CC_OP_EFLAGS;
412
    }
413
    FORCE_RET();
414
}
415

    
416
void OPPROTO glue(glue(op_shl, SUFFIX), _T0_T1_cc)(void)
417
{
418
    int count;
419
    count = T1 & 0x1f;
420
    if (count) {
421
        CC_SRC = (DATA_TYPE)T0 << (count - 1);
422
        T0 = T0 << count;
423
        CC_DST = T0;
424
        CC_OP = CC_OP_SHLB + SHIFT;
425
    }
426
    FORCE_RET();
427
}
428

    
429
void OPPROTO glue(glue(op_shr, SUFFIX), _T0_T1_cc)(void)
430
{
431
    int count;
432
    count = T1 & 0x1f;
433
    if (count) {
434
        T0 &= DATA_MASK;
435
        CC_SRC = T0 >> (count - 1);
436
        T0 = T0 >> count;
437
        CC_DST = T0;
438
        CC_OP = CC_OP_SARB + SHIFT;
439
    }
440
    FORCE_RET();
441
}
442

    
443
void OPPROTO glue(glue(op_sar, SUFFIX), _T0_T1_cc)(void)
444
{
445
    int count, src;
446
    count = T1 & 0x1f;
447
    if (count) {
448
        src = (DATA_STYPE)T0;
449
        CC_SRC = src >> (count - 1);
450
        T0 = src >> count;
451
        CC_DST = T0;
452
        CC_OP = CC_OP_SARB + SHIFT;
453
    }
454
    FORCE_RET();
455
}
456

    
457
#if DATA_BITS == 16
458
/* XXX: overflow flag might be incorrect in some cases in shldw */
459
void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_im_cc)(void)
460
{
461
    int count;
462
    unsigned int res;
463
    count = PARAM1;
464
    T1 &= 0xffff;
465
    res = T1 | (T0 << 16);
466
    CC_SRC = res >> (32 - count);
467
    res <<= count;
468
    if (count > 16)
469
        res |= T1 << (count - 16);
470
    T0 = res >> 16;
471
    CC_DST = T0;
472
}
473

    
474
void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_ECX_cc)(void)
475
{
476
    int count;
477
    unsigned int res;
478
    count = ECX & 0x1f;
479
    if (count) {
480
        T1 &= 0xffff;
481
        res = T1 | (T0 << 16);
482
        CC_SRC = res >> (32 - count);
483
        res <<= count;
484
        if (count > 16)
485
          res |= T1 << (count - 16);
486
        T0 = res >> 16;
487
        CC_DST = T0;
488
        CC_OP = CC_OP_SARB + SHIFT;
489
    }
490
}
491

    
492
void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_im_cc)(void)
493
{
494
    int count;
495
    unsigned int res;
496

    
497
    count = PARAM1;
498
    res = (T0 & 0xffff) | (T1 << 16);
499
    CC_SRC = res >> (count - 1);
500
    res >>= count;
501
    if (count > 16)
502
        res |= T1 << (32 - count);
503
    T0 = res;
504
    CC_DST = T0;
505
}
506

    
507

    
508
void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_ECX_cc)(void)
509
{
510
    int count;
511
    unsigned int res;
512

    
513
    count = ECX & 0x1f;
514
    if (count) {
515
        res = (T0 & 0xffff) | (T1 << 16);
516
        CC_SRC = res >> (count - 1);
517
        res >>= count;
518
        if (count > 16)
519
            res |= T1 << (32 - count);
520
        T0 = res;
521
        CC_DST = T0;
522
        CC_OP = CC_OP_SARB + SHIFT;
523
    }
524
}
525
#endif
526

    
527
#if DATA_BITS == 32
528
void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_im_cc)(void)
529
{
530
    int count;
531
    count = PARAM1;
532
    T0 &= DATA_MASK;
533
    T1 &= DATA_MASK;
534
    CC_SRC = T0 << (count - 1);
535
    T0 = (T0 << count) | (T1 >> (DATA_BITS - count));
536
    CC_DST = T0;
537
}
538

    
539
void OPPROTO glue(glue(op_shld, SUFFIX), _T0_T1_ECX_cc)(void)
540
{
541
    int count;
542
    count = ECX & 0x1f;
543
    if (count) {
544
        T0 &= DATA_MASK;
545
        T1 &= DATA_MASK;
546
        CC_SRC = T0 << (count - 1);
547
        T0 = (T0 << count) | (T1 >> (DATA_BITS - count));
548
        CC_DST = T0;
549
        CC_OP = CC_OP_SHLB + SHIFT;
550
    }
551
}
552

    
553
void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_im_cc)(void)
554
{
555
    int count;
556
    count = PARAM1;
557
    T0 &= DATA_MASK;
558
    T1 &= DATA_MASK;
559
    CC_SRC = T0 >> (count - 1);
560
    T0 = (T0 >> count) | (T1 << (DATA_BITS - count));
561
    CC_DST = T0;
562
}
563

    
564

    
565
void OPPROTO glue(glue(op_shrd, SUFFIX), _T0_T1_ECX_cc)(void)
566
{
567
    int count;
568
    count = ECX & 0x1f;
569
    if (count) {
570
        T0 &= DATA_MASK;
571
        T1 &= DATA_MASK;
572
        CC_SRC = T0 >> (count - 1);
573
        T0 = (T0 >> count) | (T1 << (DATA_BITS - count));
574
        CC_DST = T0;
575
        CC_OP = CC_OP_SARB + SHIFT;
576
    }
577
}
578
#endif
579

    
580
/* carry add/sub (we only need to set CC_OP differently) */
581

    
582
void OPPROTO glue(glue(op_adc, SUFFIX), _T0_T1_cc)(void)
583
{
584
    int cf;
585
    cf = cc_table[CC_OP].compute_c();
586
    CC_SRC = T0;
587
    T0 = T0 + T1 + cf;
588
    CC_DST = T0;
589
    CC_OP = CC_OP_ADDB + SHIFT + cf * 3;
590
}
591

    
592
void OPPROTO glue(glue(op_sbb, SUFFIX), _T0_T1_cc)(void)
593
{
594
    int cf;
595
    cf = cc_table[CC_OP].compute_c();
596
    CC_SRC = T0;
597
    T0 = T0 - T1 - cf;
598
    CC_DST = T0;
599
    CC_OP = CC_OP_SUBB + SHIFT + cf * 3;
600
}
601

    
602
/* bit operations */
603
#if DATA_BITS >= 16
604

    
605
void OPPROTO glue(glue(op_bt, SUFFIX), _T0_T1_cc)(void)
606
{
607
    int count;
608
    count = T1 & SHIFT_MASK;
609
    CC_SRC = T0 >> count;
610
}
611

    
612
void OPPROTO glue(glue(op_bts, SUFFIX), _T0_T1_cc)(void)
613
{
614
    int count;
615
    count = T1 & SHIFT_MASK;
616
    CC_SRC = T0 >> count;
617
    T0 |= (1 << count);
618
}
619

    
620
void OPPROTO glue(glue(op_btr, SUFFIX), _T0_T1_cc)(void)
621
{
622
    int count;
623
    count = T1 & SHIFT_MASK;
624
    CC_SRC = T0 >> count;
625
    T0 &= ~(1 << count);
626
}
627

    
628
void OPPROTO glue(glue(op_btc, SUFFIX), _T0_T1_cc)(void)
629
{
630
    int count;
631
    count = T1 & SHIFT_MASK;
632
    CC_SRC = T0 >> count;
633
    T0 ^= (1 << count);
634
}
635

    
636
#endif
637

    
638
/* string operations */
639
/* XXX: maybe use lower level instructions to ease exception handling */
640

    
641
void OPPROTO glue(op_movs, SUFFIX)(void)
642
{
643
    int v;
644
    v = glue(ldu, SUFFIX)((void *)ESI);
645
    glue(st, SUFFIX)((void *)EDI, v);
646
    ESI += (DF << SHIFT);
647
    EDI += (DF << SHIFT);
648
}
649

    
650
void OPPROTO glue(op_rep_movs, SUFFIX)(void)
651
{
652
    int v, inc;
653
    inc = (DF << SHIFT);
654
    while (ECX != 0) {
655
        v = glue(ldu, SUFFIX)((void *)ESI);
656
        glue(st, SUFFIX)((void *)EDI, v);
657
        ESI += inc;
658
        EDI += inc;
659
        ECX--;
660
    }
661
}
662

    
663
void OPPROTO glue(op_stos, SUFFIX)(void)
664
{
665
    glue(st, SUFFIX)((void *)EDI, EAX);
666
    EDI += (DF << SHIFT);
667
}
668

    
669
void OPPROTO glue(op_rep_stos, SUFFIX)(void)
670
{
671
    int inc;
672
    inc = (DF << SHIFT);
673
    while (ECX != 0) {
674
        glue(st, SUFFIX)((void *)EDI, EAX);
675
        EDI += inc;
676
        ECX--;
677
    }
678
}
679

    
680
void OPPROTO glue(op_lods, SUFFIX)(void)
681
{
682
    int v;
683
    v = glue(ldu, SUFFIX)((void *)ESI);
684
#if SHIFT == 0
685
    EAX = (EAX & ~0xff) | v;
686
#elif SHIFT == 1
687
    EAX = (EAX & ~0xffff) | v;
688
#else
689
    EAX = v;
690
#endif
691
    ESI += (DF << SHIFT);
692
}
693

    
694
/* don't know if it is used */
695
void OPPROTO glue(op_rep_lods, SUFFIX)(void)
696
{
697
    int v, inc;
698
    inc = (DF << SHIFT);
699
    while (ECX != 0) {
700
        v = glue(ldu, SUFFIX)((void *)ESI);
701
#if SHIFT == 0
702
        EAX = (EAX & ~0xff) | v;
703
#elif SHIFT == 1
704
        EAX = (EAX & ~0xffff) | v;
705
#else
706
        EAX = v;
707
#endif
708
        ESI += inc;
709
        ECX--;
710
    }
711
}
712

    
713
void OPPROTO glue(op_scas, SUFFIX)(void)
714
{
715
    int v;
716

    
717
    v = glue(ldu, SUFFIX)((void *)EDI);
718
    EDI += (DF << SHIFT);
719
    CC_SRC = EAX;
720
    CC_DST = EAX - v;
721
}
722

    
723
void OPPROTO glue(op_repz_scas, SUFFIX)(void)
724
{
725
    int v1, v2, inc;
726

    
727
    if (ECX != 0) {
728
        /* NOTE: the flags are not modified if ECX == 0 */
729
        v1 = EAX & DATA_MASK;
730
        inc = (DF << SHIFT);
731
        do {
732
            v2 = glue(ldu, SUFFIX)((void *)EDI);
733
            EDI += inc;
734
            ECX--;
735
            if (v1 != v2)
736
                break;
737
        } while (ECX != 0);
738
        CC_SRC = v1;
739
        CC_DST = v1 - v2;
740
        CC_OP = CC_OP_SUBB + SHIFT;
741
    }
742
}
743

    
744
void OPPROTO glue(op_repnz_scas, SUFFIX)(void)
745
{
746
    int v1, v2, inc;
747

    
748
    if (ECX != 0) {
749
        /* NOTE: the flags are not modified if ECX == 0 */
750
        v1 = EAX & DATA_MASK;
751
        inc = (DF << SHIFT);
752
        do {
753
            v2 = glue(ldu, SUFFIX)((void *)EDI);
754
            EDI += inc;
755
            ECX--;
756
            if (v1 == v2)
757
                break;
758
        } while (ECX != 0);
759
        CC_SRC = v1;
760
        CC_DST = v1 - v2;
761
        CC_OP = CC_OP_SUBB + SHIFT;
762
    }
763
}
764

    
765
void OPPROTO glue(op_cmps, SUFFIX)(void)
766
{
767
    int v1, v2;
768
    v1 = glue(ldu, SUFFIX)((void *)ESI);
769
    v2 = glue(ldu, SUFFIX)((void *)EDI);
770
    ESI += (DF << SHIFT);
771
    EDI += (DF << SHIFT);
772
    CC_SRC = v1;
773
    CC_DST = v1 - v2;
774
}
775

    
776
void OPPROTO glue(op_repz_cmps, SUFFIX)(void)
777
{
778
    int v1, v2, inc;
779
    if (ECX != 0) {
780
        inc = (DF << SHIFT);
781
        do {
782
            v1 = glue(ldu, SUFFIX)((void *)ESI);
783
            v2 = glue(ldu, SUFFIX)((void *)EDI);
784
            ESI += inc;
785
            EDI += inc;
786
            ECX--;
787
            if (v1 != v2)
788
                break;
789
        } while (ECX != 0);
790
        CC_SRC = v1;
791
        CC_DST = v1 - v2;
792
        CC_OP = CC_OP_SUBB + SHIFT;
793
    }
794
}
795

    
796
void OPPROTO glue(op_repnz_cmps, SUFFIX)(void)
797
{
798
    int v1, v2, inc;
799
    if (ECX != 0) {
800
        inc = (DF << SHIFT);
801
        do {
802
            v1 = glue(ldu, SUFFIX)((void *)ESI);
803
            v2 = glue(ldu, SUFFIX)((void *)EDI);
804
            ESI += inc;
805
            EDI += inc;
806
            ECX--;
807
            if (v1 == v2)
808
                break;
809
        } while (ECX != 0);
810
        CC_SRC = v1;
811
        CC_DST = v1 - v2;
812
        CC_OP = CC_OP_SUBB + SHIFT;
813
    }
814
}
815

    
816
/* port I/O */
817

    
818
void OPPROTO glue(op_outs, SUFFIX)(void)
819
{
820
    int v, dx;
821
    dx = EDX & 0xffff;
822
    v = glue(ldu, SUFFIX)((void *)ESI);
823
    glue(cpu_x86_out, SUFFIX)(dx, v);
824
    ESI += (DF << SHIFT);
825
}
826

    
827
void OPPROTO glue(op_rep_outs, SUFFIX)(void)
828
{
829
    int v, dx, inc;
830
    inc = (DF << SHIFT);
831
    dx = EDX & 0xffff;
832
    while (ECX != 0) {
833
        v = glue(ldu, SUFFIX)((void *)ESI);
834
        glue(cpu_x86_out, SUFFIX)(dx, v);
835
        ESI += inc;
836
        ECX--;
837
    }
838
}
839

    
840
void OPPROTO glue(op_ins, SUFFIX)(void)
841
{
842
    int v, dx;
843
    dx = EDX & 0xffff;
844
    v = glue(cpu_x86_in, SUFFIX)(dx);
845
    glue(st, SUFFIX)((void *)EDI, v);
846
    EDI += (DF << SHIFT);
847
}
848

    
849
void OPPROTO glue(op_rep_ins, SUFFIX)(void)
850
{
851
    int v, dx, inc;
852
    inc = (DF << SHIFT);
853
    dx = EDX & 0xffff;
854
    while (ECX != 0) {
855
        v = glue(cpu_x86_in, SUFFIX)(dx);
856
        glue(st, SUFFIX)((void *)EDI, v);
857
        EDI += (DF << SHIFT);
858
        ECX--;
859
    }
860
}
861

    
862
void OPPROTO glue(glue(op_out, SUFFIX), _T0_T1)(void)
863
{
864
    glue(cpu_x86_out, SUFFIX)(T0 & 0xffff, T1 & DATA_MASK);
865
}
866

    
867
void OPPROTO glue(glue(op_in, SUFFIX), _T0_T1)(void)
868
{
869
    T1 = glue(cpu_x86_in, SUFFIX)(T0 & 0xffff);
870
}
871

    
872
#undef DATA_BITS
873
#undef SHIFT_MASK
874
#undef SIGN_MASK
875
#undef DATA_TYPE
876
#undef DATA_STYPE
877
#undef DATA_MASK
878
#undef SUFFIX