Statistics
| Branch: | Revision:

root / target-i386 / ops_sse.h @ 664e0f19

History | View | Annotate | Download (34.3 kB)

1
/*
2
 *  MMX/SSE/SSE2/PNI support
3
 * 
4
 *  Copyright (c) 2005 Fabrice Bellard
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
#if SHIFT == 0
21
#define Reg MMXReg
22
#define XMM_ONLY(x...)
23
#define B(n) MMX_B(n)
24
#define W(n) MMX_W(n)
25
#define L(n) MMX_L(n)
26
#define Q(n) q
27
#define SUFFIX _mmx
28
#else
29
#define Reg XMMReg
30
#define XMM_ONLY(x...) x
31
#define B(n) XMM_B(n)
32
#define W(n) XMM_W(n)
33
#define L(n) XMM_L(n)
34
#define Q(n) XMM_Q(n)
35
#define SUFFIX _xmm
36
#endif
37

    
38
void OPPROTO glue(op_psrlw, SUFFIX)(void)
39
{
40
    Reg *d, *s;
41
    int shift;
42

    
43
    d = (Reg *)((char *)env + PARAM1);
44
    s = (Reg *)((char *)env + PARAM2);
45

    
46
    if (s->Q(0) > 15) {
47
        d->Q(0) = 0;
48
#if SHIFT == 1
49
        d->Q(1) = 0;
50
#endif
51
    } else {
52
        shift = s->B(0);
53
        d->W(0) >>= shift;
54
        d->W(1) >>= shift;
55
        d->W(2) >>= shift;
56
        d->W(3) >>= shift;
57
#if SHIFT == 1
58
        d->W(4) >>= shift;
59
        d->W(5) >>= shift;
60
        d->W(6) >>= shift;
61
        d->W(7) >>= shift;
62
#endif
63
    }
64
}
65

    
66
void OPPROTO glue(op_psraw, SUFFIX)(void)
67
{
68
    Reg *d, *s;
69
    int shift;
70

    
71
    d = (Reg *)((char *)env + PARAM1);
72
    s = (Reg *)((char *)env + PARAM2);
73

    
74
    if (s->Q(0) > 15) {
75
        shift = 15;
76
    } else {
77
        shift = s->B(0);
78
    }
79
    d->W(0) = (int16_t)d->W(0) >> shift;
80
    d->W(1) = (int16_t)d->W(1) >> shift;
81
    d->W(2) = (int16_t)d->W(2) >> shift;
82
    d->W(3) = (int16_t)d->W(3) >> shift;
83
#if SHIFT == 1
84
    d->W(4) = (int16_t)d->W(4) >> shift;
85
    d->W(5) = (int16_t)d->W(5) >> shift;
86
    d->W(6) = (int16_t)d->W(6) >> shift;
87
    d->W(7) = (int16_t)d->W(7) >> shift;
88
#endif
89
}
90

    
91
void OPPROTO glue(op_psllw, SUFFIX)(void)
92
{
93
    Reg *d, *s;
94
    int shift;
95

    
96
    d = (Reg *)((char *)env + PARAM1);
97
    s = (Reg *)((char *)env + PARAM2);
98

    
99
    if (s->Q(0) > 15) {
100
        d->Q(0) = 0;
101
#if SHIFT == 1
102
        d->Q(1) = 0;
103
#endif
104
    } else {
105
        shift = s->B(0);
106
        d->W(0) <<= shift;
107
        d->W(1) <<= shift;
108
        d->W(2) <<= shift;
109
        d->W(3) <<= shift;
110
#if SHIFT == 1
111
        d->W(4) <<= shift;
112
        d->W(5) <<= shift;
113
        d->W(6) <<= shift;
114
        d->W(7) <<= shift;
115
#endif
116
    }
117
}
118

    
119
void OPPROTO glue(op_psrld, SUFFIX)(void)
120
{
121
    Reg *d, *s;
122
    int shift;
123

    
124
    d = (Reg *)((char *)env + PARAM1);
125
    s = (Reg *)((char *)env + PARAM2);
126

    
127
    if (s->Q(0) > 31) {
128
        d->Q(0) = 0;
129
#if SHIFT == 1
130
        d->Q(1) = 0;
131
#endif
132
    } else {
133
        shift = s->B(0);
134
        d->L(0) >>= shift;
135
        d->L(1) >>= shift;
136
#if SHIFT == 1
137
        d->L(2) >>= shift;
138
        d->L(3) >>= shift;
139
#endif
140
    }
141
}
142

    
143
void OPPROTO glue(op_psrad, SUFFIX)(void)
144
{
145
    Reg *d, *s;
146
    int shift;
147

    
148
    d = (Reg *)((char *)env + PARAM1);
149
    s = (Reg *)((char *)env + PARAM2);
150

    
151
    if (s->Q(0) > 31) {
152
        shift = 31;
153
    } else {
154
        shift = s->B(0);
155
    }
156
    d->L(0) = (int32_t)d->L(0) >> shift;
157
    d->L(1) = (int32_t)d->L(1) >> shift;
158
#if SHIFT == 1
159
    d->L(2) = (int32_t)d->L(2) >> shift;
160
    d->L(3) = (int32_t)d->L(3) >> shift;
161
#endif
162
}
163

    
164
void OPPROTO glue(op_pslld, SUFFIX)(void)
165
{
166
    Reg *d, *s;
167
    int shift;
168

    
169
    d = (Reg *)((char *)env + PARAM1);
170
    s = (Reg *)((char *)env + PARAM2);
171

    
172
    if (s->Q(0) > 31) {
173
        d->Q(0) = 0;
174
#if SHIFT == 1
175
        d->Q(1) = 0;
176
#endif
177
    } else {
178
        shift = s->B(0);
179
        d->L(0) <<= shift;
180
        d->L(1) <<= shift;
181
#if SHIFT == 1
182
        d->L(2) <<= shift;
183
        d->L(3) <<= shift;
184
#endif
185
    }
186
}
187

    
188
void OPPROTO glue(op_psrlq, SUFFIX)(void)
189
{
190
    Reg *d, *s;
191
    int shift;
192

    
193
    d = (Reg *)((char *)env + PARAM1);
194
    s = (Reg *)((char *)env + PARAM2);
195

    
196
    if (s->Q(0) > 63) {
197
        d->Q(0) = 0;
198
#if SHIFT == 1
199
        d->Q(1) = 0;
200
#endif
201
    } else {
202
        shift = s->B(0);
203
        d->Q(0) >>= shift;
204
#if SHIFT == 1
205
        d->Q(1) >>= shift;
206
#endif
207
    }
208
}
209

    
210
void OPPROTO glue(op_psllq, SUFFIX)(void)
211
{
212
    Reg *d, *s;
213
    int shift;
214

    
215
    d = (Reg *)((char *)env + PARAM1);
216
    s = (Reg *)((char *)env + PARAM2);
217

    
218
    if (s->Q(0) > 63) {
219
        d->Q(0) = 0;
220
#if SHIFT == 1
221
        d->Q(1) = 0;
222
#endif
223
    } else {
224
        shift = s->B(0);
225
        d->Q(0) <<= shift;
226
#if SHIFT == 1
227
        d->Q(1) <<= shift;
228
#endif
229
    }
230
}
231

    
232
#if SHIFT == 1
233
void OPPROTO glue(op_psrldq, SUFFIX)(void)
234
{
235
    Reg *d, *s;
236
    int shift, i;
237

    
238
    d = (Reg *)((char *)env + PARAM1);
239
    s = (Reg *)((char *)env + PARAM2);
240
    shift = s->L(0);
241
    if (shift > 16)
242
        shift = 16;
243
    for(i = 0; i < 16 - shift; i++)
244
        d->B(i) = d->B(i + shift);
245
    for(i = 16 - shift; i < 16; i++)
246
        d->B(i) = 0;
247
    FORCE_RET();
248
}
249

    
250
void OPPROTO glue(op_pslldq, SUFFIX)(void)
251
{
252
    Reg *d, *s;
253
    int shift, i;
254

    
255
    d = (Reg *)((char *)env + PARAM1);
256
    s = (Reg *)((char *)env + PARAM2);
257
    shift = s->L(0);
258
    if (shift > 16)
259
        shift = 16;
260
    for(i = 15; i >= shift; i--)
261
        d->B(i) = d->B(i - shift);
262
    for(i = 0; i < shift; i++)
263
        d->B(i) = 0;
264
    FORCE_RET();
265
}
266
#endif
267

    
268
#define SSE_OP_B(name, F)\
269
void OPPROTO glue(name, SUFFIX) (void)\
270
{\
271
    Reg *d, *s;\
272
    d = (Reg *)((char *)env + PARAM1);\
273
    s = (Reg *)((char *)env + PARAM2);\
274
    d->B(0) = F(d->B(0), s->B(0));\
275
    d->B(1) = F(d->B(1), s->B(1));\
276
    d->B(2) = F(d->B(2), s->B(2));\
277
    d->B(3) = F(d->B(3), s->B(3));\
278
    d->B(4) = F(d->B(4), s->B(4));\
279
    d->B(5) = F(d->B(5), s->B(5));\
280
    d->B(6) = F(d->B(6), s->B(6));\
281
    d->B(7) = F(d->B(7), s->B(7));\
282
    XMM_ONLY(\
283
    d->B(8) = F(d->B(8), s->B(8));\
284
    d->B(9) = F(d->B(9), s->B(9));\
285
    d->B(10) = F(d->B(10), s->B(10));\
286
    d->B(11) = F(d->B(11), s->B(11));\
287
    d->B(12) = F(d->B(12), s->B(12));\
288
    d->B(13) = F(d->B(13), s->B(13));\
289
    d->B(14) = F(d->B(14), s->B(14));\
290
    d->B(15) = F(d->B(15), s->B(15));\
291
    )\
292
}
293

    
294
#define SSE_OP_W(name, F)\
295
void OPPROTO glue(name, SUFFIX) (void)\
296
{\
297
    Reg *d, *s;\
298
    d = (Reg *)((char *)env + PARAM1);\
299
    s = (Reg *)((char *)env + PARAM2);\
300
    d->W(0) = F(d->W(0), s->W(0));\
301
    d->W(1) = F(d->W(1), s->W(1));\
302
    d->W(2) = F(d->W(2), s->W(2));\
303
    d->W(3) = F(d->W(3), s->W(3));\
304
    XMM_ONLY(\
305
    d->W(4) = F(d->W(4), s->W(4));\
306
    d->W(5) = F(d->W(5), s->W(5));\
307
    d->W(6) = F(d->W(6), s->W(6));\
308
    d->W(7) = F(d->W(7), s->W(7));\
309
    )\
310
}
311

    
312
#define SSE_OP_L(name, F)\
313
void OPPROTO glue(name, SUFFIX) (void)\
314
{\
315
    Reg *d, *s;\
316
    d = (Reg *)((char *)env + PARAM1);\
317
    s = (Reg *)((char *)env + PARAM2);\
318
    d->L(0) = F(d->L(0), s->L(0));\
319
    d->L(1) = F(d->L(1), s->L(1));\
320
    XMM_ONLY(\
321
    d->L(2) = F(d->L(2), s->L(2));\
322
    d->L(3) = F(d->L(3), s->L(3));\
323
    )\
324
}
325

    
326
#define SSE_OP_Q(name, F)\
327
void OPPROTO glue(name, SUFFIX) (void)\
328
{\
329
    Reg *d, *s;\
330
    d = (Reg *)((char *)env + PARAM1);\
331
    s = (Reg *)((char *)env + PARAM2);\
332
    d->Q(0) = F(d->Q(0), s->Q(0));\
333
    XMM_ONLY(\
334
    d->Q(1) = F(d->Q(1), s->Q(1));\
335
    )\
336
}
337

    
338
#if SHIFT == 0
339
static inline int satub(int x)
340
{
341
    if (x < 0)
342
        return 0;
343
    else if (x > 255)
344
        return 255;
345
    else
346
        return x;
347
}
348

    
349
static inline int satuw(int x)
350
{
351
    if (x < 0)
352
        return 0;
353
    else if (x > 65535)
354
        return 65535;
355
    else
356
        return x;
357
}
358

    
359
static inline int satsb(int x)
360
{
361
    if (x < -128)
362
        return -128;
363
    else if (x > 127)
364
        return 127;
365
    else
366
        return x;
367
}
368

    
369
static inline int satsw(int x)
370
{
371
    if (x < -32768)
372
        return -32768;
373
    else if (x > 32767)
374
        return 32767;
375
    else
376
        return x;
377
}
378

    
379
#define FADD(a, b) ((a) + (b))
380
#define FADDUB(a, b) satub((a) + (b))
381
#define FADDUW(a, b) satuw((a) + (b))
382
#define FADDSB(a, b) satsb((int8_t)(a) + (int8_t)(b))
383
#define FADDSW(a, b) satsw((int16_t)(a) + (int16_t)(b))
384

    
385
#define FSUB(a, b) ((a) - (b))
386
#define FSUBUB(a, b) satub((a) - (b))
387
#define FSUBUW(a, b) satuw((a) - (b))
388
#define FSUBSB(a, b) satsb((int8_t)(a) - (int8_t)(b))
389
#define FSUBSW(a, b) satsw((int16_t)(a) - (int16_t)(b))
390
#define FMINUB(a, b) ((a) < (b)) ? (a) : (b)
391
#define FMINSW(a, b) ((int16_t)(a) < (int16_t)(b)) ? (a) : (b)
392
#define FMAXUB(a, b) ((a) > (b)) ? (a) : (b)
393
#define FMAXSW(a, b) ((int16_t)(a) > (int16_t)(b)) ? (a) : (b)
394

    
395
#define FAND(a, b) (a) & (b)
396
#define FANDN(a, b) ((~(a)) & (b))
397
#define FOR(a, b) (a) | (b)
398
#define FXOR(a, b) (a) ^ (b)
399

    
400
#define FCMPGTB(a, b) (int8_t)(a) > (int8_t)(b) ? -1 : 0
401
#define FCMPGTW(a, b) (int16_t)(a) > (int16_t)(b) ? -1 : 0
402
#define FCMPGTL(a, b) (int32_t)(a) > (int32_t)(b) ? -1 : 0
403
#define FCMPEQ(a, b) (a) == (b) ? -1 : 0
404

    
405
#define FMULLW(a, b) (a) * (b)
406
#define FMULHUW(a, b) (a) * (b) >> 16
407
#define FMULHW(a, b) (int16_t)(a) * (int16_t)(b) >> 16
408

    
409
#define FAVG(a, b) ((a) + (b) + 1) >> 1
410
#endif
411

    
412
SSE_OP_B(op_paddb, FADD)
413
SSE_OP_W(op_paddw, FADD)
414
SSE_OP_L(op_paddl, FADD)
415
SSE_OP_Q(op_paddq, FADD)
416

    
417
SSE_OP_B(op_psubb, FSUB)
418
SSE_OP_W(op_psubw, FSUB)
419
SSE_OP_L(op_psubl, FSUB)
420
SSE_OP_Q(op_psubq, FSUB)
421

    
422
SSE_OP_B(op_paddusb, FADDUB)
423
SSE_OP_B(op_paddsb, FADDSB)
424
SSE_OP_B(op_psubusb, FSUBUB)
425
SSE_OP_B(op_psubsb, FSUBSB)
426

    
427
SSE_OP_W(op_paddusw, FADDUW)
428
SSE_OP_W(op_paddsw, FADDSW)
429
SSE_OP_W(op_psubusw, FSUBUW)
430
SSE_OP_W(op_psubsw, FSUBSW)
431

    
432
SSE_OP_B(op_pminub, FMINUB)
433
SSE_OP_B(op_pmaxub, FMAXUB)
434

    
435
SSE_OP_W(op_pminsw, FMINSW)
436
SSE_OP_W(op_pmaxsw, FMAXSW)
437

    
438
SSE_OP_Q(op_pand, FAND)
439
SSE_OP_Q(op_pandn, FANDN)
440
SSE_OP_Q(op_por, FOR)
441
SSE_OP_Q(op_pxor, FXOR)
442

    
443
SSE_OP_B(op_pcmpgtb, FCMPGTB)
444
SSE_OP_W(op_pcmpgtw, FCMPGTW)
445
SSE_OP_L(op_pcmpgtl, FCMPGTL)
446

    
447
SSE_OP_B(op_pcmpeqb, FCMPEQ)
448
SSE_OP_W(op_pcmpeqw, FCMPEQ)
449
SSE_OP_L(op_pcmpeql, FCMPEQ)
450

    
451
SSE_OP_W(op_pmullw, FMULLW)
452
SSE_OP_W(op_pmulhuw, FMULHUW)
453
SSE_OP_W(op_pmulhw, FMULHW)
454

    
455
SSE_OP_B(op_pavgb, FAVG)
456
SSE_OP_W(op_pavgw, FAVG)
457

    
458
void OPPROTO glue(op_pmuludq, SUFFIX) (void)
459
{
460
    Reg *d, *s;
461
    d = (Reg *)((char *)env + PARAM1);
462
    s = (Reg *)((char *)env + PARAM2);
463

    
464
    d->Q(0) = (uint64_t)s->L(0) * (uint64_t)d->L(0);
465
#if SHIFT == 1
466
    d->Q(1) = (uint64_t)s->L(2) * (uint64_t)d->L(2);
467
#endif
468
}
469

    
470
void OPPROTO glue(op_pmaddwd, SUFFIX) (void)
471
{
472
    int i;
473
    Reg *d, *s;
474
    d = (Reg *)((char *)env + PARAM1);
475
    s = (Reg *)((char *)env + PARAM2);
476

    
477
    for(i = 0; i < (2 << SHIFT); i++) {
478
        d->L(i) = (int16_t)s->W(2*i) * (int16_t)d->W(2*i) +
479
            (int16_t)s->W(2*i+1) * (int16_t)d->W(2*i+1);
480
    }
481
}
482

    
483
#if SHIFT == 0
484
static inline int abs1(int a)
485
{
486
    if (a < 0)
487
        return -a;
488
    else
489
        return a;
490
}
491
#endif
492
void OPPROTO glue(op_psadbw, SUFFIX) (void)
493
{
494
    unsigned int val;
495
    Reg *d, *s;
496
    d = (Reg *)((char *)env + PARAM1);
497
    s = (Reg *)((char *)env + PARAM2);
498

    
499
    val = 0;
500
    val += abs1(d->B(0) - s->B(0));
501
    val += abs1(d->B(1) - s->B(1));
502
    val += abs1(d->B(2) - s->B(2));
503
    val += abs1(d->B(3) - s->B(3));
504
    val += abs1(d->B(4) - s->B(4));
505
    val += abs1(d->B(5) - s->B(5));
506
    val += abs1(d->B(6) - s->B(6));
507
    val += abs1(d->B(7) - s->B(7));
508
    d->Q(0) = val;
509
#if SHIFT == 1
510
    val = 0;
511
    val += abs1(d->B(8) - s->B(8));
512
    val += abs1(d->B(9) - s->B(9));
513
    val += abs1(d->B(10) - s->B(10));
514
    val += abs1(d->B(11) - s->B(11));
515
    val += abs1(d->B(12) - s->B(12));
516
    val += abs1(d->B(13) - s->B(13));
517
    val += abs1(d->B(14) - s->B(14));
518
    val += abs1(d->B(15) - s->B(15));
519
    d->Q(1) = val;
520
#endif
521
}
522

    
523
void OPPROTO glue(op_maskmov, SUFFIX) (void)
524
{
525
    int i;
526
    Reg *d, *s;
527
    d = (Reg *)((char *)env + PARAM1);
528
    s = (Reg *)((char *)env + PARAM2);
529
    for(i = 0; i < (8 << SHIFT); i++) {
530
        if (s->B(i) & 0x80)
531
            stb(A0, d->B(i));
532
    }
533
}
534

    
535
void OPPROTO glue(op_movl_mm_T0, SUFFIX) (void)
536
{
537
    Reg *d;
538
    d = (Reg *)((char *)env + PARAM1);
539
    d->L(0) = T0;
540
    d->L(1) = 0;
541
#if SHIFT == 1
542
    d->Q(1) = 0;
543
#endif
544
}
545

    
546
void OPPROTO glue(op_movl_T0_mm, SUFFIX) (void)
547
{
548
    Reg *s;
549
    s = (Reg *)((char *)env + PARAM1);
550
    T0 = s->L(0);
551
}
552

    
553
#if SHIFT == 0
554
void OPPROTO glue(op_pshufw, SUFFIX) (void)
555
{
556
    Reg r, *d, *s;
557
    int order;
558
    d = (Reg *)((char *)env + PARAM1);
559
    s = (Reg *)((char *)env + PARAM2);
560
    order = PARAM3;
561
    r.W(0) = s->W(order & 3);
562
    r.W(1) = s->W((order >> 2) & 3);
563
    r.W(2) = s->W((order >> 4) & 3);
564
    r.W(3) = s->W((order >> 6) & 3);
565
    *d = r;
566
}
567
#else
568
void OPPROTO op_shufpd(void)
569
{
570
    Reg r, *d, *s;
571
    int order;
572
    d = (Reg *)((char *)env + PARAM1);
573
    s = (Reg *)((char *)env + PARAM2);
574
    order = PARAM3;
575
    r.Q(0) = s->Q(order & 1);
576
    r.Q(1) = s->Q((order >> 1) & 1);
577
    *d = r;
578
}
579

    
580
void OPPROTO glue(op_pshufd, SUFFIX) (void)
581
{
582
    Reg r, *d, *s;
583
    int order;
584
    d = (Reg *)((char *)env + PARAM1);
585
    s = (Reg *)((char *)env + PARAM2);
586
    order = PARAM3;
587
    r.L(0) = s->L(order & 3);
588
    r.L(1) = s->L((order >> 2) & 3);
589
    r.L(2) = s->L((order >> 4) & 3);
590
    r.L(3) = s->L((order >> 6) & 3);
591
    *d = r;
592
}
593

    
594
void OPPROTO glue(op_pshuflw, SUFFIX) (void)
595
{
596
    Reg r, *d, *s;
597
    int order;
598
    d = (Reg *)((char *)env + PARAM1);
599
    s = (Reg *)((char *)env + PARAM2);
600
    order = PARAM3;
601
    r.W(0) = s->W(order & 3);
602
    r.W(1) = s->W((order >> 2) & 3);
603
    r.W(2) = s->W((order >> 4) & 3);
604
    r.W(3) = s->W((order >> 6) & 3);
605
    r.Q(1) = s->Q(1);
606
    *d = r;
607
}
608

    
609
void OPPROTO glue(op_pshufhw, SUFFIX) (void)
610
{
611
    Reg r, *d, *s;
612
    int order;
613
    d = (Reg *)((char *)env + PARAM1);
614
    s = (Reg *)((char *)env + PARAM2);
615
    order = PARAM3;
616
    r.Q(0) = s->Q(0);
617
    r.W(4) = s->W(4 + (order & 3));
618
    r.W(5) = s->W(4 + ((order >> 2) & 3));
619
    r.W(6) = s->W(4 + ((order >> 4) & 3));
620
    r.W(7) = s->W(4 + ((order >> 6) & 3));
621
    *d = r;
622
}
623
#endif
624

    
625
#if SHIFT == 1
626
/* FPU ops */
627
/* XXX: not accurate */
628

    
629
#define SSE_OP_S(name, F)\
630
void OPPROTO op_ ## name ## ps (void)\
631
{\
632
    Reg *d, *s;\
633
    d = (Reg *)((char *)env + PARAM1);\
634
    s = (Reg *)((char *)env + PARAM2);\
635
    d->XMM_S(0) = F(d->XMM_S(0), s->XMM_S(0));\
636
    d->XMM_S(1) = F(d->XMM_S(1), s->XMM_S(1));\
637
    d->XMM_S(2) = F(d->XMM_S(2), s->XMM_S(2));\
638
    d->XMM_S(3) = F(d->XMM_S(3), s->XMM_S(3));\
639
}\
640
\
641
void OPPROTO op_ ## name ## ss (void)\
642
{\
643
    Reg *d, *s;\
644
    d = (Reg *)((char *)env + PARAM1);\
645
    s = (Reg *)((char *)env + PARAM2);\
646
    d->XMM_S(0) = F(d->XMM_S(0), s->XMM_S(0));\
647
}\
648
void OPPROTO op_ ## name ## pd (void)\
649
{\
650
    Reg *d, *s;\
651
    d = (Reg *)((char *)env + PARAM1);\
652
    s = (Reg *)((char *)env + PARAM2);\
653
    d->XMM_D(0) = F(d->XMM_D(0), s->XMM_D(0));\
654
    d->XMM_D(1) = F(d->XMM_D(1), s->XMM_D(1));\
655
}\
656
\
657
void OPPROTO op_ ## name ## sd (void)\
658
{\
659
    Reg *d, *s;\
660
    d = (Reg *)((char *)env + PARAM1);\
661
    s = (Reg *)((char *)env + PARAM2);\
662
    d->XMM_D(0) = F(d->XMM_D(0), s->XMM_D(0));\
663
}
664

    
665
#define FPU_ADD(a, b) (a) + (b)
666
#define FPU_SUB(a, b) (a) - (b)
667
#define FPU_MUL(a, b) (a) * (b)
668
#define FPU_DIV(a, b) (a) / (b)
669
#define FPU_MIN(a, b) (a) < (b) ? (a) : (b)
670
#define FPU_MAX(a, b) (a) > (b) ? (a) : (b)
671
#define FPU_SQRT(a, b) sqrt(b)
672

    
673
SSE_OP_S(add, FPU_ADD)
674
SSE_OP_S(sub, FPU_SUB)
675
SSE_OP_S(mul, FPU_MUL)
676
SSE_OP_S(div, FPU_DIV)
677
SSE_OP_S(min, FPU_MIN)
678
SSE_OP_S(max, FPU_MAX)
679
SSE_OP_S(sqrt, FPU_SQRT)
680

    
681

    
682
/* float to float conversions */
683
void OPPROTO op_cvtps2pd(void)
684
{
685
    float s0, s1;
686
    Reg *d, *s;
687
    d = (Reg *)((char *)env + PARAM1);
688
    s = (Reg *)((char *)env + PARAM2);
689
    s0 = s->XMM_S(0);
690
    s1 = s->XMM_S(1);
691
    d->XMM_D(0) = s0;
692
    d->XMM_D(1) = s1;
693
}
694

    
695
void OPPROTO op_cvtpd2ps(void)
696
{
697
    Reg *d, *s;
698
    d = (Reg *)((char *)env + PARAM1);
699
    s = (Reg *)((char *)env + PARAM2);
700
    d->XMM_S(0) = s->XMM_D(0);
701
    d->XMM_S(1) = s->XMM_D(1);
702
    d->Q(1) = 0;
703
}
704

    
705
void OPPROTO op_cvtss2sd(void)
706
{
707
    Reg *d, *s;
708
    d = (Reg *)((char *)env + PARAM1);
709
    s = (Reg *)((char *)env + PARAM2);
710
    d->XMM_D(0) = s->XMM_S(0);
711
}
712

    
713
void OPPROTO op_cvtsd2ss(void)
714
{
715
    Reg *d, *s;
716
    d = (Reg *)((char *)env + PARAM1);
717
    s = (Reg *)((char *)env + PARAM2);
718
    d->XMM_S(0) = s->XMM_D(0);
719
}
720

    
721
/* integer to float */
722
void OPPROTO op_cvtdq2ps(void)
723
{
724
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
725
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
726
    d->XMM_S(0) = (int32_t)s->XMM_L(0);
727
    d->XMM_S(1) = (int32_t)s->XMM_L(1);
728
    d->XMM_S(2) = (int32_t)s->XMM_L(2);
729
    d->XMM_S(3) = (int32_t)s->XMM_L(3);
730
}
731

    
732
void OPPROTO op_cvtdq2pd(void)
733
{
734
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
735
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
736
    int32_t l0, l1;
737
    l0 = (int32_t)s->XMM_L(0);
738
    l1 = (int32_t)s->XMM_L(1);
739
    d->XMM_D(0) = l0;
740
    d->XMM_D(1) = l1;
741
}
742

    
743
void OPPROTO op_cvtpi2ps(void)
744
{
745
    XMMReg *d = (Reg *)((char *)env + PARAM1);
746
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
747
    d->XMM_S(0) = (int32_t)s->MMX_L(0);
748
    d->XMM_S(1) = (int32_t)s->MMX_L(1);
749
}
750

    
751
void OPPROTO op_cvtpi2pd(void)
752
{
753
    XMMReg *d = (Reg *)((char *)env + PARAM1);
754
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
755
    d->XMM_D(0) = (int32_t)s->MMX_L(0);
756
    d->XMM_D(1) = (int32_t)s->MMX_L(1);
757
}
758

    
759
void OPPROTO op_cvtsi2ss(void)
760
{
761
    XMMReg *d = (Reg *)((char *)env + PARAM1);
762
    d->XMM_S(0) = (int32_t)T0;
763
}
764

    
765
void OPPROTO op_cvtsi2sd(void)
766
{
767
    XMMReg *d = (Reg *)((char *)env + PARAM1);
768
    d->XMM_D(0) = (int32_t)T0;
769
}
770

    
771
#ifdef TARGET_X86_64
772
void OPPROTO op_cvtsq2ss(void)
773
{
774
    XMMReg *d = (Reg *)((char *)env + PARAM1);
775
    d->XMM_S(0) = (int64_t)T0;
776
}
777

    
778
void OPPROTO op_cvtsq2sd(void)
779
{
780
    XMMReg *d = (Reg *)((char *)env + PARAM1);
781
    d->XMM_D(0) = (int64_t)T0;
782
}
783
#endif
784

    
785
/* float to integer */
786
void OPPROTO op_cvtps2dq(void)
787
{
788
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
789
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
790
    d->XMM_L(0) = lrint(s->XMM_S(0));
791
    d->XMM_L(1) = lrint(s->XMM_S(1));
792
    d->XMM_L(2) = lrint(s->XMM_S(2));
793
    d->XMM_L(3) = lrint(s->XMM_S(3));
794
}
795

    
796
void OPPROTO op_cvtpd2dq(void)
797
{
798
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
799
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
800
    d->XMM_L(0) = lrint(s->XMM_D(0));
801
    d->XMM_L(1) = lrint(s->XMM_D(1));
802
    d->XMM_Q(1) = 0;
803
}
804

    
805
void OPPROTO op_cvtps2pi(void)
806
{
807
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
808
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
809
    d->MMX_L(0) = lrint(s->XMM_S(0));
810
    d->MMX_L(1) = lrint(s->XMM_S(1));
811
}
812

    
813
void OPPROTO op_cvtpd2pi(void)
814
{
815
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
816
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
817
    d->MMX_L(0) = lrint(s->XMM_D(0));
818
    d->MMX_L(1) = lrint(s->XMM_D(1));
819
}
820

    
821
void OPPROTO op_cvtss2si(void)
822
{
823
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
824
    T0 = (int32_t)lrint(s->XMM_S(0));
825
}
826

    
827
void OPPROTO op_cvtsd2si(void)
828
{
829
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
830
    T0 = (int32_t)lrint(s->XMM_D(0));
831
}
832

    
833
#ifdef TARGET_X86_64
834
void OPPROTO op_cvtss2sq(void)
835
{
836
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
837
    T0 = llrint(s->XMM_S(0));
838
}
839

    
840
void OPPROTO op_cvtsd2sq(void)
841
{
842
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
843
    T0 = llrint(s->XMM_D(0));
844
}
845
#endif
846

    
847
/* float to integer truncated */
848
void OPPROTO op_cvttps2dq(void)
849
{
850
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
851
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
852
    d->XMM_L(0) = (int32_t)s->XMM_S(0);
853
    d->XMM_L(1) = (int32_t)s->XMM_S(1);
854
    d->XMM_L(2) = (int32_t)s->XMM_S(2);
855
    d->XMM_L(3) = (int32_t)s->XMM_S(3);
856
}
857

    
858
void OPPROTO op_cvttpd2dq(void)
859
{
860
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
861
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
862
    d->XMM_L(0) = (int32_t)s->XMM_D(0);
863
    d->XMM_L(1) = (int32_t)s->XMM_D(1);
864
    d->XMM_Q(1) = 0;
865
}
866

    
867
void OPPROTO op_cvttps2pi(void)
868
{
869
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
870
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
871
    d->MMX_L(0) = (int32_t)(s->XMM_S(0));
872
    d->MMX_L(1) = (int32_t)(s->XMM_S(1));
873
}
874

    
875
void OPPROTO op_cvttpd2pi(void)
876
{
877
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
878
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
879
    d->MMX_L(0) = (int32_t)(s->XMM_D(0));
880
    d->MMX_L(1) = (int32_t)(s->XMM_D(1));
881
}
882

    
883
void OPPROTO op_cvttss2si(void)
884
{
885
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
886
    T0 = (int32_t)(s->XMM_S(0));
887
}
888

    
889
void OPPROTO op_cvttsd2si(void)
890
{
891
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
892
    T0 = (int32_t)(s->XMM_D(0));
893
}
894

    
895
#ifdef TARGET_X86_64
896
void OPPROTO op_cvttss2sq(void)
897
{
898
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
899
    T0 = (int64_t)(s->XMM_S(0));
900
}
901

    
902
void OPPROTO op_cvttsd2sq(void)
903
{
904
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
905
    T0 = (int64_t)(s->XMM_D(0));
906
}
907
#endif
908

    
909
void OPPROTO op_rsqrtps(void)
910
{
911
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
912
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
913
    d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
914
    d->XMM_S(1) = approx_rsqrt(s->XMM_S(1));
915
    d->XMM_S(2) = approx_rsqrt(s->XMM_S(2));
916
    d->XMM_S(3) = approx_rsqrt(s->XMM_S(3));
917
}
918

    
919
void OPPROTO op_rsqrtss(void)
920
{
921
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
922
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
923
    d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
924
}
925

    
926
void OPPROTO op_rcpps(void)
927
{
928
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
929
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
930
    d->XMM_S(0) = approx_rcp(s->XMM_S(0));
931
    d->XMM_S(1) = approx_rcp(s->XMM_S(1));
932
    d->XMM_S(2) = approx_rcp(s->XMM_S(2));
933
    d->XMM_S(3) = approx_rcp(s->XMM_S(3));
934
}
935

    
936
void OPPROTO op_rcpss(void)
937
{
938
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
939
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
940
    d->XMM_S(0) = approx_rcp(s->XMM_S(0));
941
}
942

    
943
void OPPROTO op_haddps(void)
944
{
945
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
946
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
947
    XMMReg r;
948
    r.XMM_S(0) = d->XMM_S(0) + d->XMM_S(1);
949
    r.XMM_S(1) = d->XMM_S(2) + d->XMM_S(3);
950
    r.XMM_S(2) = s->XMM_S(0) + s->XMM_S(1);
951
    r.XMM_S(3) = s->XMM_S(2) + s->XMM_S(3);
952
    *d = r;
953
}
954

    
955
void OPPROTO op_haddpd(void)
956
{
957
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
958
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
959
    XMMReg r;
960
    r.XMM_D(0) = d->XMM_D(0) + d->XMM_D(1);
961
    r.XMM_D(1) = s->XMM_D(0) + s->XMM_D(1);
962
    *d = r;
963
}
964

    
965
void OPPROTO op_hsubps(void)
966
{
967
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
968
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
969
    XMMReg r;
970
    r.XMM_S(0) = d->XMM_S(0) - d->XMM_S(1);
971
    r.XMM_S(1) = d->XMM_S(2) - d->XMM_S(3);
972
    r.XMM_S(2) = s->XMM_S(0) - s->XMM_S(1);
973
    r.XMM_S(3) = s->XMM_S(2) - s->XMM_S(3);
974
    *d = r;
975
}
976

    
977
void OPPROTO op_hsubpd(void)
978
{
979
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
980
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
981
    XMMReg r;
982
    r.XMM_D(0) = d->XMM_D(0) - d->XMM_D(1);
983
    r.XMM_D(1) = s->XMM_D(0) - s->XMM_D(1);
984
    *d = r;
985
}
986

    
987
void OPPROTO op_addsubps(void)
988
{
989
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
990
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
991
    d->XMM_S(0) = d->XMM_S(0) - s->XMM_S(0);
992
    d->XMM_S(1) = d->XMM_S(1) + s->XMM_S(1);
993
    d->XMM_S(2) = d->XMM_S(2) - s->XMM_S(2);
994
    d->XMM_S(3) = d->XMM_S(3) + s->XMM_S(3);
995
}
996

    
997
void OPPROTO op_addsubpd(void)
998
{
999
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1000
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1001
    d->XMM_D(0) = d->XMM_D(0) - s->XMM_D(0);
1002
    d->XMM_D(1) = d->XMM_D(1) + s->XMM_D(1);
1003
}
1004

    
1005
/* XXX: unordered */
1006
#define SSE_OP_CMP(name, F)\
1007
void OPPROTO op_ ## name ## ps (void)\
1008
{\
1009
    Reg *d, *s;\
1010
    d = (Reg *)((char *)env + PARAM1);\
1011
    s = (Reg *)((char *)env + PARAM2);\
1012
    d->XMM_L(0) = F(d->XMM_S(0), s->XMM_S(0));\
1013
    d->XMM_L(1) = F(d->XMM_S(1), s->XMM_S(1));\
1014
    d->XMM_L(2) = F(d->XMM_S(2), s->XMM_S(2));\
1015
    d->XMM_L(3) = F(d->XMM_S(3), s->XMM_S(3));\
1016
}\
1017
\
1018
void OPPROTO op_ ## name ## ss (void)\
1019
{\
1020
    Reg *d, *s;\
1021
    d = (Reg *)((char *)env + PARAM1);\
1022
    s = (Reg *)((char *)env + PARAM2);\
1023
    d->XMM_L(0) = F(d->XMM_S(0), s->XMM_S(0));\
1024
}\
1025
void OPPROTO op_ ## name ## pd (void)\
1026
{\
1027
    Reg *d, *s;\
1028
    d = (Reg *)((char *)env + PARAM1);\
1029
    s = (Reg *)((char *)env + PARAM2);\
1030
    d->XMM_Q(0) = F(d->XMM_D(0), s->XMM_D(0));\
1031
    d->XMM_Q(1) = F(d->XMM_D(1), s->XMM_D(1));\
1032
}\
1033
\
1034
void OPPROTO op_ ## name ## sd (void)\
1035
{\
1036
    Reg *d, *s;\
1037
    d = (Reg *)((char *)env + PARAM1);\
1038
    s = (Reg *)((char *)env + PARAM2);\
1039
    d->XMM_Q(0) = F(d->XMM_D(0), s->XMM_D(0));\
1040
}
1041

    
1042
#define FPU_CMPEQ(a, b) (a) == (b) ? -1 : 0
1043
#define FPU_CMPLT(a, b) (a) < (b) ? -1 : 0
1044
#define FPU_CMPLE(a, b) (a) <= (b) ? -1 : 0
1045
#define FPU_CMPUNORD(a, b) (fpu_isnan(a) || fpu_isnan(b)) ? - 1 : 0
1046
#define FPU_CMPNEQ(a, b) (a) == (b) ? 0 : -1
1047
#define FPU_CMPNLT(a, b) (a) < (b) ? 0 : -1
1048
#define FPU_CMPNLE(a, b) (a) <= (b) ? 0 : -1
1049
#define FPU_CMPORD(a, b) (!fpu_isnan(a) && !fpu_isnan(b)) ? - 1 : 0
1050

    
1051
SSE_OP_CMP(cmpeq, FPU_CMPEQ)
1052
SSE_OP_CMP(cmplt, FPU_CMPLT)
1053
SSE_OP_CMP(cmple, FPU_CMPLE)
1054
SSE_OP_CMP(cmpunord, FPU_CMPUNORD)
1055
SSE_OP_CMP(cmpneq, FPU_CMPNEQ)
1056
SSE_OP_CMP(cmpnlt, FPU_CMPNLT)
1057
SSE_OP_CMP(cmpnle, FPU_CMPNLE)
1058
SSE_OP_CMP(cmpord, FPU_CMPORD)
1059

    
1060
void OPPROTO op_ucomiss(void)
1061
{
1062
    int eflags;
1063
    float s0, s1;
1064
    Reg *d, *s;
1065
    d = (Reg *)((char *)env + PARAM1);
1066
    s = (Reg *)((char *)env + PARAM2);
1067

    
1068
    s0 = d->XMM_S(0);
1069
    s1 = s->XMM_S(0);
1070
    if (s0 < s1)
1071
        eflags = CC_C;
1072
    else if (s0 == s1)
1073
        eflags = CC_Z;
1074
    else
1075
        eflags = 0;
1076
    CC_SRC = eflags;
1077
    FORCE_RET();
1078
}
1079

    
1080
void OPPROTO op_comiss(void)
1081
{
1082
    int eflags;
1083
    float s0, s1;
1084
    Reg *d, *s;
1085
    d = (Reg *)((char *)env + PARAM1);
1086
    s = (Reg *)((char *)env + PARAM2);
1087

    
1088
    s0 = d->XMM_S(0);
1089
    s1 = s->XMM_S(0);
1090
    if (s0 < s1)
1091
        eflags = CC_C;
1092
    else if (s0 == s1)
1093
        eflags = CC_Z;
1094
    else
1095
        eflags = 0;
1096
    CC_SRC = eflags;
1097
    FORCE_RET();
1098
}
1099

    
1100
void OPPROTO op_ucomisd(void)
1101
{
1102
    int eflags;
1103
    double d0, d1;
1104
    Reg *d, *s;
1105
    d = (Reg *)((char *)env + PARAM1);
1106
    s = (Reg *)((char *)env + PARAM2);
1107

    
1108
    d0 = d->XMM_D(0);
1109
    d1 = s->XMM_D(0);
1110
    if (d0 < d1)
1111
        eflags = CC_C;
1112
    else if (d0 == d1)
1113
        eflags = CC_Z;
1114
    else
1115
        eflags = 0;
1116
    CC_SRC = eflags;
1117
    FORCE_RET();
1118
}
1119

    
1120
void OPPROTO op_comisd(void)
1121
{
1122
    int eflags;
1123
    double d0, d1;
1124
    Reg *d, *s;
1125
    d = (Reg *)((char *)env + PARAM1);
1126
    s = (Reg *)((char *)env + PARAM2);
1127

    
1128
    d0 = d->XMM_D(0);
1129
    d1 = s->XMM_D(0);
1130
    if (d0 < d1)
1131
        eflags = CC_C;
1132
    else if (d0 == d1)
1133
        eflags = CC_Z;
1134
    else
1135
        eflags = 0;
1136
    CC_SRC = eflags;
1137
    FORCE_RET();
1138
}
1139

    
1140
void OPPROTO op_movmskps(void)
1141
{
1142
    int b0, b1, b2, b3;
1143
    Reg *s;
1144
    s = (Reg *)((char *)env + PARAM1);
1145
    b0 = s->XMM_L(0) >> 31;
1146
    b1 = s->XMM_L(1) >> 31;
1147
    b2 = s->XMM_L(2) >> 31;
1148
    b3 = s->XMM_L(3) >> 31;
1149
    T0 = b0 | (b1 << 1) | (b2 << 2) | (b3 << 3);
1150
}
1151

    
1152
void OPPROTO op_movmskpd(void)
1153
{
1154
    int b0, b1;
1155
    Reg *s;
1156
    s = (Reg *)((char *)env + PARAM1);
1157
    b0 = s->XMM_L(1) >> 31;
1158
    b1 = s->XMM_L(3) >> 31;
1159
    T0 = b0 | (b1 << 1);
1160
}
1161

    
1162
#endif
1163

    
1164
void OPPROTO glue(op_pmovmskb, SUFFIX)(void)
1165
{
1166
    Reg *s;
1167
    s = (Reg *)((char *)env + PARAM1);
1168
    T0 = 0;
1169
    T0 |= (s->XMM_B(0) >> 7);
1170
    T0 |= (s->XMM_B(1) >> 6) & 0x02;
1171
    T0 |= (s->XMM_B(2) >> 5) & 0x04;
1172
    T0 |= (s->XMM_B(3) >> 4) & 0x08;
1173
    T0 |= (s->XMM_B(4) >> 3) & 0x10;
1174
    T0 |= (s->XMM_B(5) >> 2) & 0x20;
1175
    T0 |= (s->XMM_B(6) >> 1) & 0x40;
1176
    T0 |= (s->XMM_B(7)) & 0x80;
1177
#if SHIFT == 1
1178
    T0 |= (s->XMM_B(8) << 1) & 0x0100;
1179
    T0 |= (s->XMM_B(9) << 2) & 0x0200;
1180
    T0 |= (s->XMM_B(10) << 3) & 0x0400;
1181
    T0 |= (s->XMM_B(11) << 4) & 0x0800;
1182
    T0 |= (s->XMM_B(12) << 5) & 0x1000;
1183
    T0 |= (s->XMM_B(13) << 6) & 0x2000;
1184
    T0 |= (s->XMM_B(14) << 7) & 0x4000;
1185
    T0 |= (s->XMM_B(15) << 8) & 0x8000;
1186
#endif
1187
}
1188

    
1189
void OPPROTO glue(op_pinsrw, SUFFIX) (void)
1190
{
1191
    Reg *d = (Reg *)((char *)env + PARAM1);
1192
    int pos = PARAM2;
1193
    
1194
    d->W(pos) = T0;
1195
}
1196

    
1197
void OPPROTO glue(op_pextrw, SUFFIX) (void)
1198
{
1199
    Reg *s = (Reg *)((char *)env + PARAM1);
1200
    int pos = PARAM2;
1201
    
1202
    T0 = s->W(pos);
1203
}
1204

    
1205
void OPPROTO glue(op_packsswb, SUFFIX) (void)
1206
{
1207
    Reg r, *d, *s;
1208
    d = (Reg *)((char *)env + PARAM1);
1209
    s = (Reg *)((char *)env + PARAM2);
1210

    
1211
    r.B(0) = satsb((int16_t)d->W(0));
1212
    r.B(1) = satsb((int16_t)d->W(1));
1213
    r.B(2) = satsb((int16_t)d->W(2));
1214
    r.B(3) = satsb((int16_t)d->W(3));
1215
#if SHIFT == 1
1216
    r.B(4) = satsb((int16_t)d->W(4));
1217
    r.B(5) = satsb((int16_t)d->W(5));
1218
    r.B(6) = satsb((int16_t)d->W(6));
1219
    r.B(7) = satsb((int16_t)d->W(7));
1220
#endif
1221
    r.B((4 << SHIFT) + 0) = satsb((int16_t)s->W(0));
1222
    r.B((4 << SHIFT) + 1) = satsb((int16_t)s->W(1));
1223
    r.B((4 << SHIFT) + 2) = satsb((int16_t)s->W(2));
1224
    r.B((4 << SHIFT) + 3) = satsb((int16_t)s->W(3));
1225
#if SHIFT == 1
1226
    r.B(12) = satsb((int16_t)s->W(4));
1227
    r.B(13) = satsb((int16_t)s->W(5));
1228
    r.B(14) = satsb((int16_t)s->W(6));
1229
    r.B(15) = satsb((int16_t)s->W(7));
1230
#endif
1231
    *d = r;
1232
}
1233

    
1234
void OPPROTO glue(op_packuswb, SUFFIX) (void)
1235
{
1236
    Reg r, *d, *s;
1237
    d = (Reg *)((char *)env + PARAM1);
1238
    s = (Reg *)((char *)env + PARAM2);
1239

    
1240
    r.B(0) = satub((int16_t)d->W(0));
1241
    r.B(1) = satub((int16_t)d->W(1));
1242
    r.B(2) = satub((int16_t)d->W(2));
1243
    r.B(3) = satub((int16_t)d->W(3));
1244
#if SHIFT == 1
1245
    r.B(4) = satub((int16_t)d->W(4));
1246
    r.B(5) = satub((int16_t)d->W(5));
1247
    r.B(6) = satub((int16_t)d->W(6));
1248
    r.B(7) = satub((int16_t)d->W(7));
1249
#endif
1250
    r.B((4 << SHIFT) + 0) = satub((int16_t)s->W(0));
1251
    r.B((4 << SHIFT) + 1) = satub((int16_t)s->W(1));
1252
    r.B((4 << SHIFT) + 2) = satub((int16_t)s->W(2));
1253
    r.B((4 << SHIFT) + 3) = satub((int16_t)s->W(3));
1254
#if SHIFT == 1
1255
    r.B(12) = satub((int16_t)s->W(4));
1256
    r.B(13) = satub((int16_t)s->W(5));
1257
    r.B(14) = satub((int16_t)s->W(6));
1258
    r.B(15) = satub((int16_t)s->W(7));
1259
#endif
1260
    *d = r;
1261
}
1262

    
1263
void OPPROTO glue(op_packssdw, SUFFIX) (void)
1264
{
1265
    Reg r, *d, *s;
1266
    d = (Reg *)((char *)env + PARAM1);
1267
    s = (Reg *)((char *)env + PARAM2);
1268

    
1269
    r.W(0) = satsw(d->L(0));
1270
    r.W(1) = satsw(d->L(1));
1271
#if SHIFT == 1
1272
    r.W(2) = satsw(d->L(2));
1273
    r.W(3) = satsw(d->L(3));
1274
#endif
1275
    r.W((2 << SHIFT) + 0) = satsw(s->L(0));
1276
    r.W((2 << SHIFT) + 1) = satsw(s->L(1));
1277
#if SHIFT == 1
1278
    r.W(6) = satsw(s->L(2));
1279
    r.W(7) = satsw(s->L(3));
1280
#endif
1281
    *d = r;
1282
}
1283

    
1284
#define UNPCK_OP(base_name, base)                               \
1285
                                                                \
1286
void OPPROTO glue(op_punpck ## base_name ## bw, SUFFIX) (void)   \
1287
{                                                               \
1288
    Reg r, *d, *s;                                              \
1289
    d = (Reg *)((char *)env + PARAM1);                          \
1290
    s = (Reg *)((char *)env + PARAM2);                          \
1291
                                                                \
1292
    r.B(0) = d->B((base << (SHIFT + 2)) + 0);                   \
1293
    r.B(1) = s->B((base << (SHIFT + 2)) + 0);                   \
1294
    r.B(2) = d->B((base << (SHIFT + 2)) + 1);                   \
1295
    r.B(3) = s->B((base << (SHIFT + 2)) + 1);                   \
1296
    r.B(4) = d->B((base << (SHIFT + 2)) + 2);                   \
1297
    r.B(5) = s->B((base << (SHIFT + 2)) + 2);                   \
1298
    r.B(6) = d->B((base << (SHIFT + 2)) + 3);                   \
1299
    r.B(7) = s->B((base << (SHIFT + 2)) + 3);                   \
1300
XMM_ONLY(                                                       \
1301
    r.B(8) = d->B((base << (SHIFT + 2)) + 4);                   \
1302
    r.B(9) = s->B((base << (SHIFT + 2)) + 4);                   \
1303
    r.B(10) = d->B((base << (SHIFT + 2)) + 5);                  \
1304
    r.B(11) = s->B((base << (SHIFT + 2)) + 5);                  \
1305
    r.B(12) = d->B((base << (SHIFT + 2)) + 6);                  \
1306
    r.B(13) = s->B((base << (SHIFT + 2)) + 6);                  \
1307
    r.B(14) = d->B((base << (SHIFT + 2)) + 7);                  \
1308
    r.B(15) = s->B((base << (SHIFT + 2)) + 7);                  \
1309
)                                                               \
1310
    *d = r;                                                     \
1311
}                                                               \
1312
                                                                \
1313
void OPPROTO glue(op_punpck ## base_name ## wd, SUFFIX) (void)   \
1314
{                                                               \
1315
    Reg r, *d, *s;                                              \
1316
    d = (Reg *)((char *)env + PARAM1);                          \
1317
    s = (Reg *)((char *)env + PARAM2);                          \
1318
                                                                \
1319
    r.W(0) = d->W((base << (SHIFT + 1)) + 0);                   \
1320
    r.W(1) = s->W((base << (SHIFT + 1)) + 0);                   \
1321
    r.W(2) = d->W((base << (SHIFT + 1)) + 1);                   \
1322
    r.W(3) = s->W((base << (SHIFT + 1)) + 1);                   \
1323
XMM_ONLY(                                                       \
1324
    r.W(4) = d->W((base << (SHIFT + 1)) + 2);                   \
1325
    r.W(5) = s->W((base << (SHIFT + 1)) + 2);                   \
1326
    r.W(6) = d->W((base << (SHIFT + 1)) + 3);                   \
1327
    r.W(7) = s->W((base << (SHIFT + 1)) + 3);                   \
1328
)                                                               \
1329
    *d = r;                                                     \
1330
}                                                               \
1331
                                                                \
1332
void OPPROTO glue(op_punpck ## base_name ## dq, SUFFIX) (void)   \
1333
{                                                               \
1334
    Reg r, *d, *s;                                              \
1335
    d = (Reg *)((char *)env + PARAM1);                          \
1336
    s = (Reg *)((char *)env + PARAM2);                          \
1337
                                                                \
1338
    r.L(0) = d->L((base << SHIFT) + 0);                         \
1339
    r.L(1) = s->L((base << SHIFT) + 0);                         \
1340
XMM_ONLY(                                                       \
1341
    r.L(2) = d->L((base << SHIFT) + 1);                         \
1342
    r.L(3) = s->L((base << SHIFT) + 1);                         \
1343
)                                                               \
1344
    *d = r;                                                     \
1345
}                                                               \
1346
                                                                \
1347
XMM_ONLY(                                                       \
1348
void OPPROTO glue(op_punpck ## base_name ## qdq, SUFFIX) (void)  \
1349
{                                                               \
1350
    Reg r, *d, *s;                                              \
1351
    d = (Reg *)((char *)env + PARAM1);                          \
1352
    s = (Reg *)((char *)env + PARAM2);                          \
1353
                                                                \
1354
    r.Q(0) = d->Q(base);                                        \
1355
    r.Q(1) = s->Q(base);                                        \
1356
    *d = r;                                                     \
1357
}                                                               \
1358
)
1359

    
1360
UNPCK_OP(l, 0)
1361
UNPCK_OP(h, 1)
1362

    
1363
#undef SHIFT
1364
#undef XMM_ONLY
1365
#undef Reg
1366
#undef B
1367
#undef W
1368
#undef L
1369
#undef Q
1370
#undef SUFFIX