Statistics
| Branch: | Revision:

root / target-i386 / ops_sse.h @ 0523c6b7

History | View | Annotate | Download (35 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
    FORCE_RET();
65
}
66

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

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

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

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

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

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

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

    
126
    d = (Reg *)((char *)env + PARAM1);
127
    s = (Reg *)((char *)env + PARAM2);
128

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

    
146
void OPPROTO glue(op_psrad, SUFFIX)(void)
147
{
148
    Reg *d, *s;
149
    int shift;
150

    
151
    d = (Reg *)((char *)env + PARAM1);
152
    s = (Reg *)((char *)env + PARAM2);
153

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

    
167
void OPPROTO glue(op_pslld, SUFFIX)(void)
168
{
169
    Reg *d, *s;
170
    int shift;
171

    
172
    d = (Reg *)((char *)env + PARAM1);
173
    s = (Reg *)((char *)env + PARAM2);
174

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

    
192
void OPPROTO glue(op_psrlq, SUFFIX)(void)
193
{
194
    Reg *d, *s;
195
    int shift;
196

    
197
    d = (Reg *)((char *)env + PARAM1);
198
    s = (Reg *)((char *)env + PARAM2);
199

    
200
    if (s->Q(0) > 63) {
201
        d->Q(0) = 0;
202
#if SHIFT == 1
203
        d->Q(1) = 0;
204
#endif
205
    } else {
206
        shift = s->B(0);
207
        d->Q(0) >>= shift;
208
#if SHIFT == 1
209
        d->Q(1) >>= shift;
210
#endif
211
    }
212
    FORCE_RET();
213
}
214

    
215
void OPPROTO glue(op_psllq, SUFFIX)(void)
216
{
217
    Reg *d, *s;
218
    int shift;
219

    
220
    d = (Reg *)((char *)env + PARAM1);
221
    s = (Reg *)((char *)env + PARAM2);
222

    
223
    if (s->Q(0) > 63) {
224
        d->Q(0) = 0;
225
#if SHIFT == 1
226
        d->Q(1) = 0;
227
#endif
228
    } else {
229
        shift = s->B(0);
230
        d->Q(0) <<= shift;
231
#if SHIFT == 1
232
        d->Q(1) <<= shift;
233
#endif
234
    }
235
    FORCE_RET();
236
}
237

    
238
#if SHIFT == 1
239
void OPPROTO glue(op_psrldq, SUFFIX)(void)
240
{
241
    Reg *d, *s;
242
    int shift, i;
243

    
244
    d = (Reg *)((char *)env + PARAM1);
245
    s = (Reg *)((char *)env + PARAM2);
246
    shift = s->L(0);
247
    if (shift > 16)
248
        shift = 16;
249
    for(i = 0; i < 16 - shift; i++)
250
        d->B(i) = d->B(i + shift);
251
    for(i = 16 - shift; i < 16; i++)
252
        d->B(i) = 0;
253
    FORCE_RET();
254
}
255

    
256
void OPPROTO glue(op_pslldq, SUFFIX)(void)
257
{
258
    Reg *d, *s;
259
    int shift, i;
260

    
261
    d = (Reg *)((char *)env + PARAM1);
262
    s = (Reg *)((char *)env + PARAM2);
263
    shift = s->L(0);
264
    if (shift > 16)
265
        shift = 16;
266
    for(i = 15; i >= shift; i--)
267
        d->B(i) = d->B(i - shift);
268
    for(i = 0; i < shift; i++)
269
        d->B(i) = 0;
270
    FORCE_RET();
271
}
272
#endif
273

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

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

    
318
#define SSE_OP_L(name, F)\
319
void OPPROTO glue(name, SUFFIX) (void)\
320
{\
321
    Reg *d, *s;\
322
    d = (Reg *)((char *)env + PARAM1);\
323
    s = (Reg *)((char *)env + PARAM2);\
324
    d->L(0) = F(d->L(0), s->L(0));\
325
    d->L(1) = F(d->L(1), s->L(1));\
326
    XMM_ONLY(\
327
    d->L(2) = F(d->L(2), s->L(2));\
328
    d->L(3) = F(d->L(3), s->L(3));\
329
    )\
330
}
331

    
332
#define SSE_OP_Q(name, F)\
333
void OPPROTO glue(name, SUFFIX) (void)\
334
{\
335
    Reg *d, *s;\
336
    d = (Reg *)((char *)env + PARAM1);\
337
    s = (Reg *)((char *)env + PARAM2);\
338
    d->Q(0) = F(d->Q(0), s->Q(0));\
339
    XMM_ONLY(\
340
    d->Q(1) = F(d->Q(1), s->Q(1));\
341
    )\
342
}
343

    
344
#if SHIFT == 0
345
static inline int satub(int x)
346
{
347
    if (x < 0)
348
        return 0;
349
    else if (x > 255)
350
        return 255;
351
    else
352
        return x;
353
}
354

    
355
static inline int satuw(int x)
356
{
357
    if (x < 0)
358
        return 0;
359
    else if (x > 65535)
360
        return 65535;
361
    else
362
        return x;
363
}
364

    
365
static inline int satsb(int x)
366
{
367
    if (x < -128)
368
        return -128;
369
    else if (x > 127)
370
        return 127;
371
    else
372
        return x;
373
}
374

    
375
static inline int satsw(int x)
376
{
377
    if (x < -32768)
378
        return -32768;
379
    else if (x > 32767)
380
        return 32767;
381
    else
382
        return x;
383
}
384

    
385
#define FADD(a, b) ((a) + (b))
386
#define FADDUB(a, b) satub((a) + (b))
387
#define FADDUW(a, b) satuw((a) + (b))
388
#define FADDSB(a, b) satsb((int8_t)(a) + (int8_t)(b))
389
#define FADDSW(a, b) satsw((int16_t)(a) + (int16_t)(b))
390

    
391
#define FSUB(a, b) ((a) - (b))
392
#define FSUBUB(a, b) satub((a) - (b))
393
#define FSUBUW(a, b) satuw((a) - (b))
394
#define FSUBSB(a, b) satsb((int8_t)(a) - (int8_t)(b))
395
#define FSUBSW(a, b) satsw((int16_t)(a) - (int16_t)(b))
396
#define FMINUB(a, b) ((a) < (b)) ? (a) : (b)
397
#define FMINSW(a, b) ((int16_t)(a) < (int16_t)(b)) ? (a) : (b)
398
#define FMAXUB(a, b) ((a) > (b)) ? (a) : (b)
399
#define FMAXSW(a, b) ((int16_t)(a) > (int16_t)(b)) ? (a) : (b)
400

    
401
#define FAND(a, b) (a) & (b)
402
#define FANDN(a, b) ((~(a)) & (b))
403
#define FOR(a, b) (a) | (b)
404
#define FXOR(a, b) (a) ^ (b)
405

    
406
#define FCMPGTB(a, b) (int8_t)(a) > (int8_t)(b) ? -1 : 0
407
#define FCMPGTW(a, b) (int16_t)(a) > (int16_t)(b) ? -1 : 0
408
#define FCMPGTL(a, b) (int32_t)(a) > (int32_t)(b) ? -1 : 0
409
#define FCMPEQ(a, b) (a) == (b) ? -1 : 0
410

    
411
#define FMULLW(a, b) (a) * (b)
412
#define FMULHUW(a, b) (a) * (b) >> 16
413
#define FMULHW(a, b) (int16_t)(a) * (int16_t)(b) >> 16
414

    
415
#define FAVG(a, b) ((a) + (b) + 1) >> 1
416
#endif
417

    
418
SSE_OP_B(op_paddb, FADD)
419
SSE_OP_W(op_paddw, FADD)
420
SSE_OP_L(op_paddl, FADD)
421
SSE_OP_Q(op_paddq, FADD)
422

    
423
SSE_OP_B(op_psubb, FSUB)
424
SSE_OP_W(op_psubw, FSUB)
425
SSE_OP_L(op_psubl, FSUB)
426
SSE_OP_Q(op_psubq, FSUB)
427

    
428
SSE_OP_B(op_paddusb, FADDUB)
429
SSE_OP_B(op_paddsb, FADDSB)
430
SSE_OP_B(op_psubusb, FSUBUB)
431
SSE_OP_B(op_psubsb, FSUBSB)
432

    
433
SSE_OP_W(op_paddusw, FADDUW)
434
SSE_OP_W(op_paddsw, FADDSW)
435
SSE_OP_W(op_psubusw, FSUBUW)
436
SSE_OP_W(op_psubsw, FSUBSW)
437

    
438
SSE_OP_B(op_pminub, FMINUB)
439
SSE_OP_B(op_pmaxub, FMAXUB)
440

    
441
SSE_OP_W(op_pminsw, FMINSW)
442
SSE_OP_W(op_pmaxsw, FMAXSW)
443

    
444
SSE_OP_Q(op_pand, FAND)
445
SSE_OP_Q(op_pandn, FANDN)
446
SSE_OP_Q(op_por, FOR)
447
SSE_OP_Q(op_pxor, FXOR)
448

    
449
SSE_OP_B(op_pcmpgtb, FCMPGTB)
450
SSE_OP_W(op_pcmpgtw, FCMPGTW)
451
SSE_OP_L(op_pcmpgtl, FCMPGTL)
452

    
453
SSE_OP_B(op_pcmpeqb, FCMPEQ)
454
SSE_OP_W(op_pcmpeqw, FCMPEQ)
455
SSE_OP_L(op_pcmpeql, FCMPEQ)
456

    
457
SSE_OP_W(op_pmullw, FMULLW)
458
SSE_OP_W(op_pmulhuw, FMULHUW)
459
SSE_OP_W(op_pmulhw, FMULHW)
460

    
461
SSE_OP_B(op_pavgb, FAVG)
462
SSE_OP_W(op_pavgw, FAVG)
463

    
464
void OPPROTO glue(op_pmuludq, SUFFIX) (void)
465
{
466
    Reg *d, *s;
467
    d = (Reg *)((char *)env + PARAM1);
468
    s = (Reg *)((char *)env + PARAM2);
469

    
470
    d->Q(0) = (uint64_t)s->L(0) * (uint64_t)d->L(0);
471
#if SHIFT == 1
472
    d->Q(1) = (uint64_t)s->L(2) * (uint64_t)d->L(2);
473
#endif
474
}
475

    
476
void OPPROTO glue(op_pmaddwd, SUFFIX) (void)
477
{
478
    int i;
479
    Reg *d, *s;
480
    d = (Reg *)((char *)env + PARAM1);
481
    s = (Reg *)((char *)env + PARAM2);
482

    
483
    for(i = 0; i < (2 << SHIFT); i++) {
484
        d->L(i) = (int16_t)s->W(2*i) * (int16_t)d->W(2*i) +
485
            (int16_t)s->W(2*i+1) * (int16_t)d->W(2*i+1);
486
    }
487
    FORCE_RET();
488
}
489

    
490
#if SHIFT == 0
491
static inline int abs1(int a)
492
{
493
    if (a < 0)
494
        return -a;
495
    else
496
        return a;
497
}
498
#endif
499
void OPPROTO glue(op_psadbw, SUFFIX) (void)
500
{
501
    unsigned int val;
502
    Reg *d, *s;
503
    d = (Reg *)((char *)env + PARAM1);
504
    s = (Reg *)((char *)env + PARAM2);
505

    
506
    val = 0;
507
    val += abs1(d->B(0) - s->B(0));
508
    val += abs1(d->B(1) - s->B(1));
509
    val += abs1(d->B(2) - s->B(2));
510
    val += abs1(d->B(3) - s->B(3));
511
    val += abs1(d->B(4) - s->B(4));
512
    val += abs1(d->B(5) - s->B(5));
513
    val += abs1(d->B(6) - s->B(6));
514
    val += abs1(d->B(7) - s->B(7));
515
    d->Q(0) = val;
516
#if SHIFT == 1
517
    val = 0;
518
    val += abs1(d->B(8) - s->B(8));
519
    val += abs1(d->B(9) - s->B(9));
520
    val += abs1(d->B(10) - s->B(10));
521
    val += abs1(d->B(11) - s->B(11));
522
    val += abs1(d->B(12) - s->B(12));
523
    val += abs1(d->B(13) - s->B(13));
524
    val += abs1(d->B(14) - s->B(14));
525
    val += abs1(d->B(15) - s->B(15));
526
    d->Q(1) = val;
527
#endif
528
}
529

    
530
void OPPROTO glue(op_maskmov, SUFFIX) (void)
531
{
532
    int i;
533
    Reg *d, *s;
534
    d = (Reg *)((char *)env + PARAM1);
535
    s = (Reg *)((char *)env + PARAM2);
536
    for(i = 0; i < (8 << SHIFT); i++) {
537
        if (s->B(i) & 0x80)
538
            stb(A0 + i, d->B(i));
539
    }
540
    FORCE_RET();
541
}
542

    
543
void OPPROTO glue(op_movl_mm_T0, SUFFIX) (void)
544
{
545
    Reg *d;
546
    d = (Reg *)((char *)env + PARAM1);
547
    d->L(0) = T0;
548
    d->L(1) = 0;
549
#if SHIFT == 1
550
    d->Q(1) = 0;
551
#endif
552
}
553

    
554
void OPPROTO glue(op_movl_T0_mm, SUFFIX) (void)
555
{
556
    Reg *s;
557
    s = (Reg *)((char *)env + PARAM1);
558
    T0 = s->L(0);
559
}
560

    
561
#if SHIFT == 0
562
void OPPROTO glue(op_pshufw, SUFFIX) (void)
563
{
564
    Reg r, *d, *s;
565
    int order;
566
    d = (Reg *)((char *)env + PARAM1);
567
    s = (Reg *)((char *)env + PARAM2);
568
    order = PARAM3;
569
    r.W(0) = s->W(order & 3);
570
    r.W(1) = s->W((order >> 2) & 3);
571
    r.W(2) = s->W((order >> 4) & 3);
572
    r.W(3) = s->W((order >> 6) & 3);
573
    *d = r;
574
}
575
#else
576
void OPPROTO op_shufps(void)
577
{
578
    Reg r, *d, *s;
579
    int order;
580
    d = (Reg *)((char *)env + PARAM1);
581
    s = (Reg *)((char *)env + PARAM2);
582
    order = PARAM3;
583
    r.L(0) = d->L(order & 3);
584
    r.L(1) = d->L((order >> 2) & 3);
585
    r.L(2) = s->L((order >> 4) & 3);
586
    r.L(3) = s->L((order >> 6) & 3);
587
    *d = r;
588
}
589

    
590
void OPPROTO op_shufpd(void)
591
{
592
    Reg r, *d, *s;
593
    int order;
594
    d = (Reg *)((char *)env + PARAM1);
595
    s = (Reg *)((char *)env + PARAM2);
596
    order = PARAM3;
597
    r.Q(0) = d->Q(order & 1);
598
    r.Q(1) = s->Q((order >> 1) & 1);
599
    *d = r;
600
}
601

    
602
void OPPROTO glue(op_pshufd, SUFFIX) (void)
603
{
604
    Reg r, *d, *s;
605
    int order;
606
    d = (Reg *)((char *)env + PARAM1);
607
    s = (Reg *)((char *)env + PARAM2);
608
    order = PARAM3;
609
    r.L(0) = s->L(order & 3);
610
    r.L(1) = s->L((order >> 2) & 3);
611
    r.L(2) = s->L((order >> 4) & 3);
612
    r.L(3) = s->L((order >> 6) & 3);
613
    *d = r;
614
}
615

    
616
void OPPROTO glue(op_pshuflw, SUFFIX) (void)
617
{
618
    Reg r, *d, *s;
619
    int order;
620
    d = (Reg *)((char *)env + PARAM1);
621
    s = (Reg *)((char *)env + PARAM2);
622
    order = PARAM3;
623
    r.W(0) = s->W(order & 3);
624
    r.W(1) = s->W((order >> 2) & 3);
625
    r.W(2) = s->W((order >> 4) & 3);
626
    r.W(3) = s->W((order >> 6) & 3);
627
    r.Q(1) = s->Q(1);
628
    *d = r;
629
}
630

    
631
void OPPROTO glue(op_pshufhw, SUFFIX) (void)
632
{
633
    Reg r, *d, *s;
634
    int order;
635
    d = (Reg *)((char *)env + PARAM1);
636
    s = (Reg *)((char *)env + PARAM2);
637
    order = PARAM3;
638
    r.Q(0) = s->Q(0);
639
    r.W(4) = s->W(4 + (order & 3));
640
    r.W(5) = s->W(4 + ((order >> 2) & 3));
641
    r.W(6) = s->W(4 + ((order >> 4) & 3));
642
    r.W(7) = s->W(4 + ((order >> 6) & 3));
643
    *d = r;
644
}
645
#endif
646

    
647
#if SHIFT == 1
648
/* FPU ops */
649
/* XXX: not accurate */
650

    
651
#define SSE_OP_S(name, F)\
652
void OPPROTO op_ ## name ## ps (void)\
653
{\
654
    Reg *d, *s;\
655
    d = (Reg *)((char *)env + PARAM1);\
656
    s = (Reg *)((char *)env + PARAM2);\
657
    d->XMM_S(0) = F(d->XMM_S(0), s->XMM_S(0));\
658
    d->XMM_S(1) = F(d->XMM_S(1), s->XMM_S(1));\
659
    d->XMM_S(2) = F(d->XMM_S(2), s->XMM_S(2));\
660
    d->XMM_S(3) = F(d->XMM_S(3), s->XMM_S(3));\
661
}\
662
\
663
void OPPROTO op_ ## name ## ss (void)\
664
{\
665
    Reg *d, *s;\
666
    d = (Reg *)((char *)env + PARAM1);\
667
    s = (Reg *)((char *)env + PARAM2);\
668
    d->XMM_S(0) = F(d->XMM_S(0), s->XMM_S(0));\
669
}\
670
void OPPROTO op_ ## name ## pd (void)\
671
{\
672
    Reg *d, *s;\
673
    d = (Reg *)((char *)env + PARAM1);\
674
    s = (Reg *)((char *)env + PARAM2);\
675
    d->XMM_D(0) = F(d->XMM_D(0), s->XMM_D(0));\
676
    d->XMM_D(1) = F(d->XMM_D(1), s->XMM_D(1));\
677
}\
678
\
679
void OPPROTO op_ ## name ## sd (void)\
680
{\
681
    Reg *d, *s;\
682
    d = (Reg *)((char *)env + PARAM1);\
683
    s = (Reg *)((char *)env + PARAM2);\
684
    d->XMM_D(0) = F(d->XMM_D(0), s->XMM_D(0));\
685
}
686

    
687
#define FPU_ADD(a, b) (a) + (b)
688
#define FPU_SUB(a, b) (a) - (b)
689
#define FPU_MUL(a, b) (a) * (b)
690
#define FPU_DIV(a, b) (a) / (b)
691
#define FPU_MIN(a, b) (a) < (b) ? (a) : (b)
692
#define FPU_MAX(a, b) (a) > (b) ? (a) : (b)
693
#define FPU_SQRT(a, b) helper_sqrt(b)
694

    
695
SSE_OP_S(add, FPU_ADD)
696
SSE_OP_S(sub, FPU_SUB)
697
SSE_OP_S(mul, FPU_MUL)
698
SSE_OP_S(div, FPU_DIV)
699
SSE_OP_S(min, FPU_MIN)
700
SSE_OP_S(max, FPU_MAX)
701
SSE_OP_S(sqrt, FPU_SQRT)
702

    
703

    
704
/* float to float conversions */
705
void OPPROTO op_cvtps2pd(void)
706
{
707
    float s0, s1;
708
    Reg *d, *s;
709
    d = (Reg *)((char *)env + PARAM1);
710
    s = (Reg *)((char *)env + PARAM2);
711
    s0 = s->XMM_S(0);
712
    s1 = s->XMM_S(1);
713
    d->XMM_D(0) = float32_to_float64(s0);
714
    d->XMM_D(1) = float32_to_float64(s1);
715
}
716

    
717
void OPPROTO op_cvtpd2ps(void)
718
{
719
    Reg *d, *s;
720
    d = (Reg *)((char *)env + PARAM1);
721
    s = (Reg *)((char *)env + PARAM2);
722
    d->XMM_S(0) = float64_to_float32(s->XMM_D(0));
723
    d->XMM_S(1) = float64_to_float32(s->XMM_D(1));
724
    d->Q(1) = 0;
725
}
726

    
727
void OPPROTO op_cvtss2sd(void)
728
{
729
    Reg *d, *s;
730
    d = (Reg *)((char *)env + PARAM1);
731
    s = (Reg *)((char *)env + PARAM2);
732
    d->XMM_D(0) = float32_to_float64(s->XMM_S(0));
733
}
734

    
735
void OPPROTO op_cvtsd2ss(void)
736
{
737
    Reg *d, *s;
738
    d = (Reg *)((char *)env + PARAM1);
739
    s = (Reg *)((char *)env + PARAM2);
740
    d->XMM_S(0) = float64_to_float32(s->XMM_D(0));
741
}
742

    
743
/* integer to float */
744
void OPPROTO op_cvtdq2ps(void)
745
{
746
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
747
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
748
    d->XMM_S(0) = int32_to_float32(s->XMM_L(0));
749
    d->XMM_S(1) = int32_to_float32(s->XMM_L(1));
750
    d->XMM_S(2) = int32_to_float32(s->XMM_L(2));
751
    d->XMM_S(3) = int32_to_float32(s->XMM_L(3));
752
}
753

    
754
void OPPROTO op_cvtdq2pd(void)
755
{
756
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
757
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
758
    int32_t l0, l1;
759
    l0 = (int32_t)s->XMM_L(0);
760
    l1 = (int32_t)s->XMM_L(1);
761
    d->XMM_D(0) = int32_to_float64(l0);
762
    d->XMM_D(1) = int32_to_float64(l1);
763
}
764

    
765
void OPPROTO op_cvtpi2ps(void)
766
{
767
    XMMReg *d = (Reg *)((char *)env + PARAM1);
768
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
769
    d->XMM_S(0) = int32_to_float32(s->MMX_L(0));
770
    d->XMM_S(1) = int32_to_float32(s->MMX_L(1));
771
}
772

    
773
void OPPROTO op_cvtpi2pd(void)
774
{
775
    XMMReg *d = (Reg *)((char *)env + PARAM1);
776
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
777
    d->XMM_D(0) = int32_to_float64(s->MMX_L(0));
778
    d->XMM_D(1) = int32_to_float64(s->MMX_L(1));
779
}
780

    
781
void OPPROTO op_cvtsi2ss(void)
782
{
783
    XMMReg *d = (Reg *)((char *)env + PARAM1);
784
    d->XMM_S(0) = int32_to_float32(T0);
785
}
786

    
787
void OPPROTO op_cvtsi2sd(void)
788
{
789
    XMMReg *d = (Reg *)((char *)env + PARAM1);
790
    d->XMM_D(0) = int32_to_float64(T0);
791
}
792

    
793
#ifdef TARGET_X86_64
794
void OPPROTO op_cvtsq2ss(void)
795
{
796
    XMMReg *d = (Reg *)((char *)env + PARAM1);
797
    d->XMM_S(0) = int64_to_float32(T0);
798
}
799

    
800
void OPPROTO op_cvtsq2sd(void)
801
{
802
    XMMReg *d = (Reg *)((char *)env + PARAM1);
803
    d->XMM_D(0) = int64_to_float64(T0);
804
}
805
#endif
806

    
807
/* float to integer */
808
void OPPROTO op_cvtps2dq(void)
809
{
810
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
811
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
812
    d->XMM_L(0) = lrint(s->XMM_S(0));
813
    d->XMM_L(1) = lrint(s->XMM_S(1));
814
    d->XMM_L(2) = lrint(s->XMM_S(2));
815
    d->XMM_L(3) = lrint(s->XMM_S(3));
816
}
817

    
818
void OPPROTO op_cvtpd2dq(void)
819
{
820
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
821
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
822
    d->XMM_L(0) = lrint(s->XMM_D(0));
823
    d->XMM_L(1) = lrint(s->XMM_D(1));
824
    d->XMM_Q(1) = 0;
825
}
826

    
827
void OPPROTO op_cvtps2pi(void)
828
{
829
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
830
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
831
    d->MMX_L(0) = lrint(s->XMM_S(0));
832
    d->MMX_L(1) = lrint(s->XMM_S(1));
833
}
834

    
835
void OPPROTO op_cvtpd2pi(void)
836
{
837
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
838
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
839
    d->MMX_L(0) = lrint(s->XMM_D(0));
840
    d->MMX_L(1) = lrint(s->XMM_D(1));
841
}
842

    
843
void OPPROTO op_cvtss2si(void)
844
{
845
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
846
    T0 = (int32_t)lrint(s->XMM_S(0));
847
}
848

    
849
void OPPROTO op_cvtsd2si(void)
850
{
851
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
852
    T0 = (int32_t)lrint(s->XMM_D(0));
853
}
854

    
855
#ifdef TARGET_X86_64
856
void OPPROTO op_cvtss2sq(void)
857
{
858
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
859
    T0 = llrint(s->XMM_S(0));
860
}
861

    
862
void OPPROTO op_cvtsd2sq(void)
863
{
864
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
865
    T0 = llrint(s->XMM_D(0));
866
}
867
#endif
868

    
869
/* float to integer truncated */
870
void OPPROTO op_cvttps2dq(void)
871
{
872
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
873
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
874
    d->XMM_L(0) = (int32_t)s->XMM_S(0);
875
    d->XMM_L(1) = (int32_t)s->XMM_S(1);
876
    d->XMM_L(2) = (int32_t)s->XMM_S(2);
877
    d->XMM_L(3) = (int32_t)s->XMM_S(3);
878
}
879

    
880
void OPPROTO op_cvttpd2dq(void)
881
{
882
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
883
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
884
    d->XMM_L(0) = (int32_t)s->XMM_D(0);
885
    d->XMM_L(1) = (int32_t)s->XMM_D(1);
886
    d->XMM_Q(1) = 0;
887
}
888

    
889
void OPPROTO op_cvttps2pi(void)
890
{
891
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
892
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
893
    d->MMX_L(0) = (int32_t)(s->XMM_S(0));
894
    d->MMX_L(1) = (int32_t)(s->XMM_S(1));
895
}
896

    
897
void OPPROTO op_cvttpd2pi(void)
898
{
899
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
900
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
901
    d->MMX_L(0) = (int32_t)(s->XMM_D(0));
902
    d->MMX_L(1) = (int32_t)(s->XMM_D(1));
903
}
904

    
905
void OPPROTO op_cvttss2si(void)
906
{
907
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
908
    T0 = (int32_t)(s->XMM_S(0));
909
}
910

    
911
void OPPROTO op_cvttsd2si(void)
912
{
913
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
914
    T0 = (int32_t)(s->XMM_D(0));
915
}
916

    
917
#ifdef TARGET_X86_64
918
void OPPROTO op_cvttss2sq(void)
919
{
920
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
921
    T0 = (int64_t)(s->XMM_S(0));
922
}
923

    
924
void OPPROTO op_cvttsd2sq(void)
925
{
926
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
927
    T0 = (int64_t)(s->XMM_D(0));
928
}
929
#endif
930

    
931
void OPPROTO op_rsqrtps(void)
932
{
933
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
934
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
935
    d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
936
    d->XMM_S(1) = approx_rsqrt(s->XMM_S(1));
937
    d->XMM_S(2) = approx_rsqrt(s->XMM_S(2));
938
    d->XMM_S(3) = approx_rsqrt(s->XMM_S(3));
939
}
940

    
941
void OPPROTO op_rsqrtss(void)
942
{
943
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
944
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
945
    d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
946
}
947

    
948
void OPPROTO op_rcpps(void)
949
{
950
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
951
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
952
    d->XMM_S(0) = approx_rcp(s->XMM_S(0));
953
    d->XMM_S(1) = approx_rcp(s->XMM_S(1));
954
    d->XMM_S(2) = approx_rcp(s->XMM_S(2));
955
    d->XMM_S(3) = approx_rcp(s->XMM_S(3));
956
}
957

    
958
void OPPROTO op_rcpss(void)
959
{
960
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
961
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
962
    d->XMM_S(0) = approx_rcp(s->XMM_S(0));
963
}
964

    
965
void OPPROTO op_haddps(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_haddpd(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_hsubps(void)
988
{
989
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
990
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
991
    XMMReg r;
992
    r.XMM_S(0) = d->XMM_S(0) - d->XMM_S(1);
993
    r.XMM_S(1) = d->XMM_S(2) - d->XMM_S(3);
994
    r.XMM_S(2) = s->XMM_S(0) - s->XMM_S(1);
995
    r.XMM_S(3) = s->XMM_S(2) - s->XMM_S(3);
996
    *d = r;
997
}
998

    
999
void OPPROTO op_hsubpd(void)
1000
{
1001
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1002
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1003
    XMMReg r;
1004
    r.XMM_D(0) = d->XMM_D(0) - d->XMM_D(1);
1005
    r.XMM_D(1) = s->XMM_D(0) - s->XMM_D(1);
1006
    *d = r;
1007
}
1008

    
1009
void OPPROTO op_addsubps(void)
1010
{
1011
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1012
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1013
    d->XMM_S(0) = d->XMM_S(0) - s->XMM_S(0);
1014
    d->XMM_S(1) = d->XMM_S(1) + s->XMM_S(1);
1015
    d->XMM_S(2) = d->XMM_S(2) - s->XMM_S(2);
1016
    d->XMM_S(3) = d->XMM_S(3) + s->XMM_S(3);
1017
}
1018

    
1019
void OPPROTO op_addsubpd(void)
1020
{
1021
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1022
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1023
    d->XMM_D(0) = d->XMM_D(0) - s->XMM_D(0);
1024
    d->XMM_D(1) = d->XMM_D(1) + s->XMM_D(1);
1025
}
1026

    
1027
/* XXX: unordered */
1028
#define SSE_OP_CMP(name, F)\
1029
void OPPROTO op_ ## name ## ps (void)\
1030
{\
1031
    Reg *d, *s;\
1032
    d = (Reg *)((char *)env + PARAM1);\
1033
    s = (Reg *)((char *)env + PARAM2);\
1034
    d->XMM_L(0) = F(d->XMM_S(0), s->XMM_S(0));\
1035
    d->XMM_L(1) = F(d->XMM_S(1), s->XMM_S(1));\
1036
    d->XMM_L(2) = F(d->XMM_S(2), s->XMM_S(2));\
1037
    d->XMM_L(3) = F(d->XMM_S(3), s->XMM_S(3));\
1038
}\
1039
\
1040
void OPPROTO op_ ## name ## ss (void)\
1041
{\
1042
    Reg *d, *s;\
1043
    d = (Reg *)((char *)env + PARAM1);\
1044
    s = (Reg *)((char *)env + PARAM2);\
1045
    d->XMM_L(0) = F(d->XMM_S(0), s->XMM_S(0));\
1046
}\
1047
void OPPROTO op_ ## name ## pd (void)\
1048
{\
1049
    Reg *d, *s;\
1050
    d = (Reg *)((char *)env + PARAM1);\
1051
    s = (Reg *)((char *)env + PARAM2);\
1052
    d->XMM_Q(0) = F(d->XMM_D(0), s->XMM_D(0));\
1053
    d->XMM_Q(1) = F(d->XMM_D(1), s->XMM_D(1));\
1054
}\
1055
\
1056
void OPPROTO op_ ## name ## sd (void)\
1057
{\
1058
    Reg *d, *s;\
1059
    d = (Reg *)((char *)env + PARAM1);\
1060
    s = (Reg *)((char *)env + PARAM2);\
1061
    d->XMM_Q(0) = F(d->XMM_D(0), s->XMM_D(0));\
1062
}
1063

    
1064
#define FPU_CMPEQ(a, b) (a) == (b) ? -1 : 0
1065
#define FPU_CMPLT(a, b) (a) < (b) ? -1 : 0
1066
#define FPU_CMPLE(a, b) (a) <= (b) ? -1 : 0
1067
#define FPU_CMPUNORD(a, b) (fpu_isnan(a) || fpu_isnan(b)) ? - 1 : 0
1068
#define FPU_CMPNEQ(a, b) (a) == (b) ? 0 : -1
1069
#define FPU_CMPNLT(a, b) (a) < (b) ? 0 : -1
1070
#define FPU_CMPNLE(a, b) (a) <= (b) ? 0 : -1
1071
#define FPU_CMPORD(a, b) (!fpu_isnan(a) && !fpu_isnan(b)) ? - 1 : 0
1072

    
1073
SSE_OP_CMP(cmpeq, FPU_CMPEQ)
1074
SSE_OP_CMP(cmplt, FPU_CMPLT)
1075
SSE_OP_CMP(cmple, FPU_CMPLE)
1076
SSE_OP_CMP(cmpunord, FPU_CMPUNORD)
1077
SSE_OP_CMP(cmpneq, FPU_CMPNEQ)
1078
SSE_OP_CMP(cmpnlt, FPU_CMPNLT)
1079
SSE_OP_CMP(cmpnle, FPU_CMPNLE)
1080
SSE_OP_CMP(cmpord, FPU_CMPORD)
1081

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

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

    
1102
void OPPROTO op_comiss(void)
1103
{
1104
    int eflags;
1105
    float s0, s1;
1106
    Reg *d, *s;
1107
    d = (Reg *)((char *)env + PARAM1);
1108
    s = (Reg *)((char *)env + PARAM2);
1109

    
1110
    s0 = d->XMM_S(0);
1111
    s1 = s->XMM_S(0);
1112
    if (s0 < s1)
1113
        eflags = CC_C;
1114
    else if (s0 == s1)
1115
        eflags = CC_Z;
1116
    else
1117
        eflags = 0;
1118
    CC_SRC = eflags;
1119
    FORCE_RET();
1120
}
1121

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

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

    
1142
void OPPROTO op_comisd(void)
1143
{
1144
    int eflags;
1145
    double d0, d1;
1146
    Reg *d, *s;
1147
    d = (Reg *)((char *)env + PARAM1);
1148
    s = (Reg *)((char *)env + PARAM2);
1149

    
1150
    d0 = d->XMM_D(0);
1151
    d1 = s->XMM_D(0);
1152
    if (d0 < d1)
1153
        eflags = CC_C;
1154
    else if (d0 == d1)
1155
        eflags = CC_Z;
1156
    else
1157
        eflags = 0;
1158
    CC_SRC = eflags;
1159
    FORCE_RET();
1160
}
1161

    
1162
void OPPROTO op_movmskps(void)
1163
{
1164
    int b0, b1, b2, b3;
1165
    Reg *s;
1166
    s = (Reg *)((char *)env + PARAM1);
1167
    b0 = s->XMM_L(0) >> 31;
1168
    b1 = s->XMM_L(1) >> 31;
1169
    b2 = s->XMM_L(2) >> 31;
1170
    b3 = s->XMM_L(3) >> 31;
1171
    T0 = b0 | (b1 << 1) | (b2 << 2) | (b3 << 3);
1172
}
1173

    
1174
void OPPROTO op_movmskpd(void)
1175
{
1176
    int b0, b1;
1177
    Reg *s;
1178
    s = (Reg *)((char *)env + PARAM1);
1179
    b0 = s->XMM_L(1) >> 31;
1180
    b1 = s->XMM_L(3) >> 31;
1181
    T0 = b0 | (b1 << 1);
1182
}
1183

    
1184
#endif
1185

    
1186
void OPPROTO glue(op_pmovmskb, SUFFIX)(void)
1187
{
1188
    Reg *s;
1189
    s = (Reg *)((char *)env + PARAM1);
1190
    T0 = 0;
1191
    T0 |= (s->XMM_B(0) >> 7);
1192
    T0 |= (s->XMM_B(1) >> 6) & 0x02;
1193
    T0 |= (s->XMM_B(2) >> 5) & 0x04;
1194
    T0 |= (s->XMM_B(3) >> 4) & 0x08;
1195
    T0 |= (s->XMM_B(4) >> 3) & 0x10;
1196
    T0 |= (s->XMM_B(5) >> 2) & 0x20;
1197
    T0 |= (s->XMM_B(6) >> 1) & 0x40;
1198
    T0 |= (s->XMM_B(7)) & 0x80;
1199
#if SHIFT == 1
1200
    T0 |= (s->XMM_B(8) << 1) & 0x0100;
1201
    T0 |= (s->XMM_B(9) << 2) & 0x0200;
1202
    T0 |= (s->XMM_B(10) << 3) & 0x0400;
1203
    T0 |= (s->XMM_B(11) << 4) & 0x0800;
1204
    T0 |= (s->XMM_B(12) << 5) & 0x1000;
1205
    T0 |= (s->XMM_B(13) << 6) & 0x2000;
1206
    T0 |= (s->XMM_B(14) << 7) & 0x4000;
1207
    T0 |= (s->XMM_B(15) << 8) & 0x8000;
1208
#endif
1209
}
1210

    
1211
void OPPROTO glue(op_pinsrw, SUFFIX) (void)
1212
{
1213
    Reg *d = (Reg *)((char *)env + PARAM1);
1214
    int pos = PARAM2;
1215
    
1216
    d->W(pos) = T0;
1217
}
1218

    
1219
void OPPROTO glue(op_pextrw, SUFFIX) (void)
1220
{
1221
    Reg *s = (Reg *)((char *)env + PARAM1);
1222
    int pos = PARAM2;
1223
    
1224
    T0 = s->W(pos);
1225
}
1226

    
1227
void OPPROTO glue(op_packsswb, SUFFIX) (void)
1228
{
1229
    Reg r, *d, *s;
1230
    d = (Reg *)((char *)env + PARAM1);
1231
    s = (Reg *)((char *)env + PARAM2);
1232

    
1233
    r.B(0) = satsb((int16_t)d->W(0));
1234
    r.B(1) = satsb((int16_t)d->W(1));
1235
    r.B(2) = satsb((int16_t)d->W(2));
1236
    r.B(3) = satsb((int16_t)d->W(3));
1237
#if SHIFT == 1
1238
    r.B(4) = satsb((int16_t)d->W(4));
1239
    r.B(5) = satsb((int16_t)d->W(5));
1240
    r.B(6) = satsb((int16_t)d->W(6));
1241
    r.B(7) = satsb((int16_t)d->W(7));
1242
#endif
1243
    r.B((4 << SHIFT) + 0) = satsb((int16_t)s->W(0));
1244
    r.B((4 << SHIFT) + 1) = satsb((int16_t)s->W(1));
1245
    r.B((4 << SHIFT) + 2) = satsb((int16_t)s->W(2));
1246
    r.B((4 << SHIFT) + 3) = satsb((int16_t)s->W(3));
1247
#if SHIFT == 1
1248
    r.B(12) = satsb((int16_t)s->W(4));
1249
    r.B(13) = satsb((int16_t)s->W(5));
1250
    r.B(14) = satsb((int16_t)s->W(6));
1251
    r.B(15) = satsb((int16_t)s->W(7));
1252
#endif
1253
    *d = r;
1254
}
1255

    
1256
void OPPROTO glue(op_packuswb, SUFFIX) (void)
1257
{
1258
    Reg r, *d, *s;
1259
    d = (Reg *)((char *)env + PARAM1);
1260
    s = (Reg *)((char *)env + PARAM2);
1261

    
1262
    r.B(0) = satub((int16_t)d->W(0));
1263
    r.B(1) = satub((int16_t)d->W(1));
1264
    r.B(2) = satub((int16_t)d->W(2));
1265
    r.B(3) = satub((int16_t)d->W(3));
1266
#if SHIFT == 1
1267
    r.B(4) = satub((int16_t)d->W(4));
1268
    r.B(5) = satub((int16_t)d->W(5));
1269
    r.B(6) = satub((int16_t)d->W(6));
1270
    r.B(7) = satub((int16_t)d->W(7));
1271
#endif
1272
    r.B((4 << SHIFT) + 0) = satub((int16_t)s->W(0));
1273
    r.B((4 << SHIFT) + 1) = satub((int16_t)s->W(1));
1274
    r.B((4 << SHIFT) + 2) = satub((int16_t)s->W(2));
1275
    r.B((4 << SHIFT) + 3) = satub((int16_t)s->W(3));
1276
#if SHIFT == 1
1277
    r.B(12) = satub((int16_t)s->W(4));
1278
    r.B(13) = satub((int16_t)s->W(5));
1279
    r.B(14) = satub((int16_t)s->W(6));
1280
    r.B(15) = satub((int16_t)s->W(7));
1281
#endif
1282
    *d = r;
1283
}
1284

    
1285
void OPPROTO glue(op_packssdw, SUFFIX) (void)
1286
{
1287
    Reg r, *d, *s;
1288
    d = (Reg *)((char *)env + PARAM1);
1289
    s = (Reg *)((char *)env + PARAM2);
1290

    
1291
    r.W(0) = satsw(d->L(0));
1292
    r.W(1) = satsw(d->L(1));
1293
#if SHIFT == 1
1294
    r.W(2) = satsw(d->L(2));
1295
    r.W(3) = satsw(d->L(3));
1296
#endif
1297
    r.W((2 << SHIFT) + 0) = satsw(s->L(0));
1298
    r.W((2 << SHIFT) + 1) = satsw(s->L(1));
1299
#if SHIFT == 1
1300
    r.W(6) = satsw(s->L(2));
1301
    r.W(7) = satsw(s->L(3));
1302
#endif
1303
    *d = r;
1304
}
1305

    
1306
#define UNPCK_OP(base_name, base)                               \
1307
                                                                \
1308
void OPPROTO glue(op_punpck ## base_name ## bw, SUFFIX) (void)   \
1309
{                                                               \
1310
    Reg r, *d, *s;                                              \
1311
    d = (Reg *)((char *)env + PARAM1);                          \
1312
    s = (Reg *)((char *)env + PARAM2);                          \
1313
                                                                \
1314
    r.B(0) = d->B((base << (SHIFT + 2)) + 0);                   \
1315
    r.B(1) = s->B((base << (SHIFT + 2)) + 0);                   \
1316
    r.B(2) = d->B((base << (SHIFT + 2)) + 1);                   \
1317
    r.B(3) = s->B((base << (SHIFT + 2)) + 1);                   \
1318
    r.B(4) = d->B((base << (SHIFT + 2)) + 2);                   \
1319
    r.B(5) = s->B((base << (SHIFT + 2)) + 2);                   \
1320
    r.B(6) = d->B((base << (SHIFT + 2)) + 3);                   \
1321
    r.B(7) = s->B((base << (SHIFT + 2)) + 3);                   \
1322
XMM_ONLY(                                                       \
1323
    r.B(8) = d->B((base << (SHIFT + 2)) + 4);                   \
1324
    r.B(9) = s->B((base << (SHIFT + 2)) + 4);                   \
1325
    r.B(10) = d->B((base << (SHIFT + 2)) + 5);                  \
1326
    r.B(11) = s->B((base << (SHIFT + 2)) + 5);                  \
1327
    r.B(12) = d->B((base << (SHIFT + 2)) + 6);                  \
1328
    r.B(13) = s->B((base << (SHIFT + 2)) + 6);                  \
1329
    r.B(14) = d->B((base << (SHIFT + 2)) + 7);                  \
1330
    r.B(15) = s->B((base << (SHIFT + 2)) + 7);                  \
1331
)                                                               \
1332
    *d = r;                                                     \
1333
}                                                               \
1334
                                                                \
1335
void OPPROTO glue(op_punpck ## base_name ## wd, SUFFIX) (void)   \
1336
{                                                               \
1337
    Reg r, *d, *s;                                              \
1338
    d = (Reg *)((char *)env + PARAM1);                          \
1339
    s = (Reg *)((char *)env + PARAM2);                          \
1340
                                                                \
1341
    r.W(0) = d->W((base << (SHIFT + 1)) + 0);                   \
1342
    r.W(1) = s->W((base << (SHIFT + 1)) + 0);                   \
1343
    r.W(2) = d->W((base << (SHIFT + 1)) + 1);                   \
1344
    r.W(3) = s->W((base << (SHIFT + 1)) + 1);                   \
1345
XMM_ONLY(                                                       \
1346
    r.W(4) = d->W((base << (SHIFT + 1)) + 2);                   \
1347
    r.W(5) = s->W((base << (SHIFT + 1)) + 2);                   \
1348
    r.W(6) = d->W((base << (SHIFT + 1)) + 3);                   \
1349
    r.W(7) = s->W((base << (SHIFT + 1)) + 3);                   \
1350
)                                                               \
1351
    *d = r;                                                     \
1352
}                                                               \
1353
                                                                \
1354
void OPPROTO glue(op_punpck ## base_name ## dq, SUFFIX) (void)   \
1355
{                                                               \
1356
    Reg r, *d, *s;                                              \
1357
    d = (Reg *)((char *)env + PARAM1);                          \
1358
    s = (Reg *)((char *)env + PARAM2);                          \
1359
                                                                \
1360
    r.L(0) = d->L((base << SHIFT) + 0);                         \
1361
    r.L(1) = s->L((base << SHIFT) + 0);                         \
1362
XMM_ONLY(                                                       \
1363
    r.L(2) = d->L((base << SHIFT) + 1);                         \
1364
    r.L(3) = s->L((base << SHIFT) + 1);                         \
1365
)                                                               \
1366
    *d = r;                                                     \
1367
}                                                               \
1368
                                                                \
1369
XMM_ONLY(                                                       \
1370
void OPPROTO glue(op_punpck ## base_name ## qdq, SUFFIX) (void)  \
1371
{                                                               \
1372
    Reg r, *d, *s;                                              \
1373
    d = (Reg *)((char *)env + PARAM1);                          \
1374
    s = (Reg *)((char *)env + PARAM2);                          \
1375
                                                                \
1376
    r.Q(0) = d->Q(base);                                        \
1377
    r.Q(1) = s->Q(base);                                        \
1378
    *d = r;                                                     \
1379
}                                                               \
1380
)
1381

    
1382
UNPCK_OP(l, 0)
1383
UNPCK_OP(h, 1)
1384

    
1385
#undef SHIFT
1386
#undef XMM_ONLY
1387
#undef Reg
1388
#undef B
1389
#undef W
1390
#undef L
1391
#undef Q
1392
#undef SUFFIX