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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
|
// stop compiling if NORECBUILD build (only for Visual Studio)
#if !(defined(_MSC_VER) && defined(PCSX2_NORECBUILD))
#include "ix86-64.h"
#include <assert.h>
/********************/
/* MMX instructions */
/********************/
// r64 = mm
/* movq m64 to r64 */
void MOVQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x6F), true, to, from, 0);
}
/* movq r64 to m64 */
void MOVQRtoM( uptr to, x86MMXRegType from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x7F), true, from, to, 0);
}
/* pand r64 to r64 */
void PANDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xDB0F );
ModRM( 3, to, from );
}
void PANDNRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xDF0F );
ModRM( 3, to, from );
}
/* por r64 to r64 */
void PORRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xEB0F );
ModRM( 3, to, from );
}
/* pxor r64 to r64 */
void PXORRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xEF0F );
ModRM( 3, to, from );
}
/* psllq r64 to r64 */
void PSLLQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xF30F );
ModRM( 3, to, from );
}
/* psllq m64 to r64 */
void PSLLQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xF3), true, to, from, 0);
}
/* psllq imm8 to r64 */
void PSLLQItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x730F );
ModRM( 3, 6, to);
write8( from );
}
/* psrlq r64 to r64 */
void PSRLQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xD30F );
ModRM( 3, to, from );
}
/* psrlq m64 to r64 */
void PSRLQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xD3), true, to, from, 0);
}
/* psrlq imm8 to r64 */
void PSRLQItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x730F );
ModRM( 3, 2, to);
write8( from );
}
/* paddusb r64 to r64 */
void PADDUSBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xDC0F );
ModRM( 3, to, from );
}
/* paddusb m64 to r64 */
void PADDUSBMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xDC), true, to, from, 0);
}
/* paddusw r64 to r64 */
void PADDUSWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xDD0F );
ModRM( 3, to, from );
}
/* paddusw m64 to r64 */
void PADDUSWMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xDD), true, to, from, 0);
}
/* paddb r64 to r64 */
void PADDBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xFC0F );
ModRM( 3, to, from );
}
/* paddb m64 to r64 */
void PADDBMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xFC), true, to, from, 0);
}
/* paddw r64 to r64 */
void PADDWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xFD0F );
ModRM( 3, to, from );
}
/* paddw m64 to r64 */
void PADDWMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xFD), true, to, from, 0);
}
/* paddd r64 to r64 */
void PADDDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xFE0F );
ModRM( 3, to, from );
}
/* paddd m64 to r64 */
void PADDDMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xFE), true, to, from, 0);
}
/* emms */
void EMMS( void )
{
write16( 0x770F );
}
void PADDSBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xEC0F );
ModRM( 3, to, from );
}
void PADDSWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xED0F );
ModRM( 3, to, from );
}
// paddq m64 to r64 (sse2 only?)
void PADDQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xD4), true, to, from, 0);
}
// paddq r64 to r64 (sse2 only?)
void PADDQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xD40F );
ModRM( 3, to, from );
}
void PSUBSBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xE80F );
ModRM( 3, to, from );
}
void PSUBSWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xE90F );
ModRM( 3, to, from );
}
void PSUBBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xF80F );
ModRM( 3, to, from );
}
void PSUBWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xF90F );
ModRM( 3, to, from );
}
void PSUBDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xFA0F );
ModRM( 3, to, from );
}
void PSUBDMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xFA), true, to, from, 0);
}
void PSUBUSBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xD80F );
ModRM( 3, to, from );
}
void PSUBUSWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xD90F );
ModRM( 3, to, from );
}
// psubq m64 to r64 (sse2 only?)
void PSUBQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xFB), true, to, from, 0);
}
// psubq r64 to r64 (sse2 only?)
void PSUBQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xFB0F );
ModRM( 3, to, from );
}
// pmuludq m64 to r64 (sse2 only?)
void PMULUDQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xF4), true, to, from, 0);
}
// pmuludq r64 to r64 (sse2 only?)
void PMULUDQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xF40F );
ModRM( 3, to, from );
}
void PCMPEQBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x740F );
ModRM( 3, to, from );
}
void PCMPEQWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x750F );
ModRM( 3, to, from );
}
void PCMPEQDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x760F );
ModRM( 3, to, from );
}
void PCMPEQDMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x76), true, to, from, 0);
}
void PCMPGTBRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x640F );
ModRM( 3, to, from );
}
void PCMPGTWRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x650F );
ModRM( 3, to, from );
}
void PCMPGTDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x660F );
ModRM( 3, to, from );
}
void PCMPGTDMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x66), true, to, from, 0);
}
void PSRLWItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x710F );
ModRM( 3, 2 , to );
write8( from );
}
void PSRLDItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x720F );
ModRM( 3, 2 , to );
write8( from );
}
void PSRLDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xD20F );
ModRM( 3, to, from );
}
void PSLLWItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x710F );
ModRM( 3, 6 , to );
write8( from );
}
void PSLLDItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x720F );
ModRM( 3, 6 , to );
write8( from );
}
void PSLLDRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xF20F );
ModRM( 3, to, from );
}
void PSRAWItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x710F );
ModRM( 3, 4 , to );
write8( from );
}
void PSRADItoR( x86MMXRegType to, u8 from )
{
RexB(0, to);
write16( 0x720F );
ModRM( 3, 4 , to );
write8( from );
}
void PSRADRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0xE20F );
ModRM( 3, to, from );
}
/* por m64 to r64 */
void PORMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xEB), true, to, from, 0);
}
/* pxor m64 to r64 */
void PXORMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xEF), true, to, from, 0);
}
/* pand m64 to r64 */
void PANDMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xDB), true, to, from, 0);
}
void PANDNMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0xDF), true, to, from, 0);
}
void PUNPCKHDQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x6A0F );
ModRM( 3, to, from );
}
void PUNPCKHDQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x6A), true, to, from, 0);
}
void PUNPCKLDQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x620F );
ModRM( 3, to, from );
}
void PUNPCKLDQMtoR( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x62), true, to, from, 0);
}
void MOVQ64ItoR( x86MMXRegType reg, u64 i )
{
RexR(0, reg);
write16(0x6F0F);
ModRM(0, reg, DISP32);
write32(2);
JMP8( 8 );
write64( i );
}
void MOVQRtoR( x86MMXRegType to, x86MMXRegType from )
{
RexRB(0, to, from);
write16( 0x6F0F );
ModRM( 3, to, from );
}
void MOVQRmtoROffset( x86MMXRegType to, x86IntRegType from, u32 offset )
{
RexRB(0, to, from);
write16( 0x6F0F );
if( offset < 128 ) {
ModRM( 1, to, from );
write8(offset);
}
else {
ModRM( 2, to, from );
write32(offset);
}
}
void MOVQRtoRmOffset( x86IntRegType to, x86MMXRegType from, u32 offset )
{
RexRB(0, from, to);
write16( 0x7F0F );
if( offset < 128 ) {
ModRM( 1, from , to );
write8(offset);
}
else {
ModRM( 2, from, to );
write32(offset);
}
}
/* movd m32 to r64 */
void MOVDMtoMMX( x86MMXRegType to, uptr from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x6E), true, to, from, 0);
}
/* movd r64 to m32 */
void MOVDMMXtoM( uptr to, x86MMXRegType from )
{
MEMADDR_OP(0, VAROP2(0x0F, 0x7E), true, from, to, 0);
}
void MOVD32RtoMMX( x86MMXRegType to, x86IntRegType from )
{
RexRB(0, to, from);
write16( 0x6E0F );
ModRM( 3, to, from );
}
void MOVD32RmtoMMX( x86MMXRegType to, x86IntRegType from )
{
RexRB(0, to, from);
write16( 0x6E0F );
ModRM( 0, to, from );
}
void MOVD32RmOffsettoMMX( x86MMXRegType to, x86IntRegType from, u32 offset )
{
RexRB(0, to, from);
write16( 0x6E0F );
if( offset < 128 ) {
ModRM( 1, to, from );
write8(offset);
}
else {
ModRM( 2, to, from );
write32(offset);
}
}
void MOVD32MMXtoR( x86IntRegType to, x86MMXRegType from )
{
RexRB(0, from, to);
write16( 0x7E0F );
ModRM( 3, from, to );
}
void MOVD32MMXtoRm( x86IntRegType to, x86MMXRegType from )
{
RexRB(0, from, to);
write16( 0x7E0F );
ModRM( 0, from, to );
if( to >= 4 ) {
// no idea why
assert( to == ESP );
write8(0x24);
}
}
void MOVD32MMXtoRmOffset( x86IntRegType to, x86MMXRegType from, u32 offset )
{
RexRB(0, from, to);
write16( 0x7E0F );
if( offset < 128 ) {
ModRM( 1, from, to );
write8(offset);
}
else {
ModRM( 2, from, to );
write32(offset);
}
}
///* movd r32 to r64 */
//void MOVD32MMXtoMMX( x86MMXRegType to, x86MMXRegType from )
//{
// write16( 0x6E0F );
// ModRM( 3, to, from );
//}
//
///* movq r64 to r32 */
//void MOVD64MMXtoMMX( x86MMXRegType to, x86MMXRegType from )
//{
// write16( 0x7E0F );
// ModRM( 3, from, to );
//}
// untested
void PACKSSWBMMXtoMMX(x86MMXRegType to, x86MMXRegType from)
{
RexRB(0, to, from);
write16( 0x630F );
ModRM( 3, to, from );
}
void PACKSSDWMMXtoMMX(x86MMXRegType to, x86MMXRegType from)
{
RexRB(0, to, from);
write16( 0x6B0F );
ModRM( 3, to, from );
}
void PMOVMSKBMMXtoR(x86IntRegType to, x86MMXRegType from)
{
RexRB(0, to, from);
write16( 0xD70F );
ModRM( 3, to, from );
}
void PINSRWRtoMMX( x86MMXRegType to, x86SSERegType from, u8 imm8 )
{
RexRB(0, to, from);
write16( 0xc40f );
ModRM( 3, to, from );
write8( imm8 );
}
void PSHUFWRtoR(x86MMXRegType to, x86MMXRegType from, u8 imm8)
{
RexRB(0, to, from);
write16(0x700f);
ModRM( 3, to, from );
write8(imm8);
}
void PSHUFWMtoR(x86MMXRegType to, uptr from, u8 imm8)
{
MEMADDR_OP(0, VAROP2(0x0F, 0x70), true, to, from, 1 /* XXX was 0? */);
write8(imm8);
}
void MASKMOVQRtoR(x86MMXRegType to, x86MMXRegType from)
{
RexRB(0, to, from);
write16(0xf70f);
ModRM( 3, to, from );
}
#endif
|