Statistics
| Branch: | Revision:

root / target-i386 / ops_sse.h @ a35f3ec7

History | View | Annotate | Download (42.6 kB)

1
/*
2
 *  MMX/3DNow!/SSE/SSE2/SSE3/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 FMULHRW(a, b) ((int16_t)(a) * (int16_t)(b) + 0x8000) >> 16
413
#define FMULHUW(a, b) (a) * (b) >> 16
414
#define FMULHW(a, b) (int16_t)(a) * (int16_t)(b) >> 16
415

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

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

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

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

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

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

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

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

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

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

    
458
SSE_OP_W(op_pmullw, FMULLW)
459
#if SHIFT == 0
460
SSE_OP_W(op_pmulhrw, FMULHRW)
461
#endif
462
SSE_OP_W(op_pmulhuw, FMULHUW)
463
SSE_OP_W(op_pmulhw, FMULHW)
464

    
465
SSE_OP_B(op_pavgb, FAVG)
466
SSE_OP_W(op_pavgw, FAVG)
467

    
468
void OPPROTO glue(op_pmuludq, SUFFIX) (void)
469
{
470
    Reg *d, *s;
471
    d = (Reg *)((char *)env + PARAM1);
472
    s = (Reg *)((char *)env + PARAM2);
473

    
474
    d->Q(0) = (uint64_t)s->L(0) * (uint64_t)d->L(0);
475
#if SHIFT == 1
476
    d->Q(1) = (uint64_t)s->L(2) * (uint64_t)d->L(2);
477
#endif
478
}
479

    
480
void OPPROTO glue(op_pmaddwd, SUFFIX) (void)
481
{
482
    int i;
483
    Reg *d, *s;
484
    d = (Reg *)((char *)env + PARAM1);
485
    s = (Reg *)((char *)env + PARAM2);
486

    
487
    for(i = 0; i < (2 << SHIFT); i++) {
488
        d->L(i) = (int16_t)s->W(2*i) * (int16_t)d->W(2*i) +
489
            (int16_t)s->W(2*i+1) * (int16_t)d->W(2*i+1);
490
    }
491
    FORCE_RET();
492
}
493

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

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

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

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

    
558
void OPPROTO glue(op_movl_T0_mm, SUFFIX) (void)
559
{
560
    Reg *s;
561
    s = (Reg *)((char *)env + PARAM1);
562
    T0 = s->L(0);
563
}
564

    
565
#ifdef TARGET_X86_64
566
void OPPROTO glue(op_movq_mm_T0, SUFFIX) (void)
567
{
568
    Reg *d;
569
    d = (Reg *)((char *)env + PARAM1);
570
    d->Q(0) = T0;
571
#if SHIFT == 1
572
    d->Q(1) = 0;
573
#endif
574
}
575

    
576
void OPPROTO glue(op_movq_T0_mm, SUFFIX) (void)
577
{
578
    Reg *s;
579
    s = (Reg *)((char *)env + PARAM1);
580
    T0 = s->Q(0);
581
}
582
#endif
583

    
584
#if SHIFT == 0
585
void OPPROTO glue(op_pshufw, SUFFIX) (void)
586
{
587
    Reg r, *d, *s;
588
    int order;
589
    d = (Reg *)((char *)env + PARAM1);
590
    s = (Reg *)((char *)env + PARAM2);
591
    order = PARAM3;
592
    r.W(0) = s->W(order & 3);
593
    r.W(1) = s->W((order >> 2) & 3);
594
    r.W(2) = s->W((order >> 4) & 3);
595
    r.W(3) = s->W((order >> 6) & 3);
596
    *d = r;
597
}
598
#else
599
void OPPROTO op_shufps(void)
600
{
601
    Reg r, *d, *s;
602
    int order;
603
    d = (Reg *)((char *)env + PARAM1);
604
    s = (Reg *)((char *)env + PARAM2);
605
    order = PARAM3;
606
    r.L(0) = d->L(order & 3);
607
    r.L(1) = d->L((order >> 2) & 3);
608
    r.L(2) = s->L((order >> 4) & 3);
609
    r.L(3) = s->L((order >> 6) & 3);
610
    *d = r;
611
}
612

    
613
void OPPROTO op_shufpd(void)
614
{
615
    Reg r, *d, *s;
616
    int order;
617
    d = (Reg *)((char *)env + PARAM1);
618
    s = (Reg *)((char *)env + PARAM2);
619
    order = PARAM3;
620
    r.Q(0) = d->Q(order & 1);
621
    r.Q(1) = s->Q((order >> 1) & 1);
622
    *d = r;
623
}
624

    
625
void OPPROTO glue(op_pshufd, SUFFIX) (void)
626
{
627
    Reg r, *d, *s;
628
    int order;
629
    d = (Reg *)((char *)env + PARAM1);
630
    s = (Reg *)((char *)env + PARAM2);
631
    order = PARAM3;
632
    r.L(0) = s->L(order & 3);
633
    r.L(1) = s->L((order >> 2) & 3);
634
    r.L(2) = s->L((order >> 4) & 3);
635
    r.L(3) = s->L((order >> 6) & 3);
636
    *d = r;
637
}
638

    
639
void OPPROTO glue(op_pshuflw, SUFFIX) (void)
640
{
641
    Reg r, *d, *s;
642
    int order;
643
    d = (Reg *)((char *)env + PARAM1);
644
    s = (Reg *)((char *)env + PARAM2);
645
    order = PARAM3;
646
    r.W(0) = s->W(order & 3);
647
    r.W(1) = s->W((order >> 2) & 3);
648
    r.W(2) = s->W((order >> 4) & 3);
649
    r.W(3) = s->W((order >> 6) & 3);
650
    r.Q(1) = s->Q(1);
651
    *d = r;
652
}
653

    
654
void OPPROTO glue(op_pshufhw, SUFFIX) (void)
655
{
656
    Reg r, *d, *s;
657
    int order;
658
    d = (Reg *)((char *)env + PARAM1);
659
    s = (Reg *)((char *)env + PARAM2);
660
    order = PARAM3;
661
    r.Q(0) = s->Q(0);
662
    r.W(4) = s->W(4 + (order & 3));
663
    r.W(5) = s->W(4 + ((order >> 2) & 3));
664
    r.W(6) = s->W(4 + ((order >> 4) & 3));
665
    r.W(7) = s->W(4 + ((order >> 6) & 3));
666
    *d = r;
667
}
668
#endif
669

    
670
#if SHIFT == 1
671
/* FPU ops */
672
/* XXX: not accurate */
673

    
674
#define SSE_OP_S(name, F)\
675
void OPPROTO op_ ## name ## ps (void)\
676
{\
677
    Reg *d, *s;\
678
    d = (Reg *)((char *)env + PARAM1);\
679
    s = (Reg *)((char *)env + PARAM2);\
680
    d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
681
    d->XMM_S(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
682
    d->XMM_S(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
683
    d->XMM_S(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
684
}\
685
\
686
void OPPROTO op_ ## name ## ss (void)\
687
{\
688
    Reg *d, *s;\
689
    d = (Reg *)((char *)env + PARAM1);\
690
    s = (Reg *)((char *)env + PARAM2);\
691
    d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
692
}\
693
void OPPROTO op_ ## name ## pd (void)\
694
{\
695
    Reg *d, *s;\
696
    d = (Reg *)((char *)env + PARAM1);\
697
    s = (Reg *)((char *)env + PARAM2);\
698
    d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
699
    d->XMM_D(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
700
}\
701
\
702
void OPPROTO op_ ## name ## sd (void)\
703
{\
704
    Reg *d, *s;\
705
    d = (Reg *)((char *)env + PARAM1);\
706
    s = (Reg *)((char *)env + PARAM2);\
707
    d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
708
}
709

    
710
#define FPU_ADD(size, a, b) float ## size ## _add(a, b, &env->sse_status)
711
#define FPU_SUB(size, a, b) float ## size ## _sub(a, b, &env->sse_status)
712
#define FPU_MUL(size, a, b) float ## size ## _mul(a, b, &env->sse_status)
713
#define FPU_DIV(size, a, b) float ## size ## _div(a, b, &env->sse_status)
714
#define FPU_MIN(size, a, b) (a) < (b) ? (a) : (b)
715
#define FPU_MAX(size, a, b) (a) > (b) ? (a) : (b)
716
#define FPU_SQRT(size, a, b) float ## size ## _sqrt(b, &env->sse_status)
717

    
718
SSE_OP_S(add, FPU_ADD)
719
SSE_OP_S(sub, FPU_SUB)
720
SSE_OP_S(mul, FPU_MUL)
721
SSE_OP_S(div, FPU_DIV)
722
SSE_OP_S(min, FPU_MIN)
723
SSE_OP_S(max, FPU_MAX)
724
SSE_OP_S(sqrt, FPU_SQRT)
725

    
726

    
727
/* float to float conversions */
728
void OPPROTO op_cvtps2pd(void)
729
{
730
    float32 s0, s1;
731
    Reg *d, *s;
732
    d = (Reg *)((char *)env + PARAM1);
733
    s = (Reg *)((char *)env + PARAM2);
734
    s0 = s->XMM_S(0);
735
    s1 = s->XMM_S(1);
736
    d->XMM_D(0) = float32_to_float64(s0, &env->sse_status);
737
    d->XMM_D(1) = float32_to_float64(s1, &env->sse_status);
738
}
739

    
740
void OPPROTO op_cvtpd2ps(void)
741
{
742
    Reg *d, *s;
743
    d = (Reg *)((char *)env + PARAM1);
744
    s = (Reg *)((char *)env + PARAM2);
745
    d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
746
    d->XMM_S(1) = float64_to_float32(s->XMM_D(1), &env->sse_status);
747
    d->Q(1) = 0;
748
}
749

    
750
void OPPROTO op_cvtss2sd(void)
751
{
752
    Reg *d, *s;
753
    d = (Reg *)((char *)env + PARAM1);
754
    s = (Reg *)((char *)env + PARAM2);
755
    d->XMM_D(0) = float32_to_float64(s->XMM_S(0), &env->sse_status);
756
}
757

    
758
void OPPROTO op_cvtsd2ss(void)
759
{
760
    Reg *d, *s;
761
    d = (Reg *)((char *)env + PARAM1);
762
    s = (Reg *)((char *)env + PARAM2);
763
    d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
764
}
765

    
766
/* integer to float */
767
void OPPROTO op_cvtdq2ps(void)
768
{
769
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
770
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
771
    d->XMM_S(0) = int32_to_float32(s->XMM_L(0), &env->sse_status);
772
    d->XMM_S(1) = int32_to_float32(s->XMM_L(1), &env->sse_status);
773
    d->XMM_S(2) = int32_to_float32(s->XMM_L(2), &env->sse_status);
774
    d->XMM_S(3) = int32_to_float32(s->XMM_L(3), &env->sse_status);
775
}
776

    
777
void OPPROTO op_cvtdq2pd(void)
778
{
779
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
780
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
781
    int32_t l0, l1;
782
    l0 = (int32_t)s->XMM_L(0);
783
    l1 = (int32_t)s->XMM_L(1);
784
    d->XMM_D(0) = int32_to_float64(l0, &env->sse_status);
785
    d->XMM_D(1) = int32_to_float64(l1, &env->sse_status);
786
}
787

    
788
void OPPROTO op_cvtpi2ps(void)
789
{
790
    XMMReg *d = (Reg *)((char *)env + PARAM1);
791
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
792
    d->XMM_S(0) = int32_to_float32(s->MMX_L(0), &env->sse_status);
793
    d->XMM_S(1) = int32_to_float32(s->MMX_L(1), &env->sse_status);
794
}
795

    
796
void OPPROTO op_cvtpi2pd(void)
797
{
798
    XMMReg *d = (Reg *)((char *)env + PARAM1);
799
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
800
    d->XMM_D(0) = int32_to_float64(s->MMX_L(0), &env->sse_status);
801
    d->XMM_D(1) = int32_to_float64(s->MMX_L(1), &env->sse_status);
802
}
803

    
804
void OPPROTO op_cvtsi2ss(void)
805
{
806
    XMMReg *d = (Reg *)((char *)env + PARAM1);
807
    d->XMM_S(0) = int32_to_float32(T0, &env->sse_status);
808
}
809

    
810
void OPPROTO op_cvtsi2sd(void)
811
{
812
    XMMReg *d = (Reg *)((char *)env + PARAM1);
813
    d->XMM_D(0) = int32_to_float64(T0, &env->sse_status);
814
}
815

    
816
#ifdef TARGET_X86_64
817
void OPPROTO op_cvtsq2ss(void)
818
{
819
    XMMReg *d = (Reg *)((char *)env + PARAM1);
820
    d->XMM_S(0) = int64_to_float32(T0, &env->sse_status);
821
}
822

    
823
void OPPROTO op_cvtsq2sd(void)
824
{
825
    XMMReg *d = (Reg *)((char *)env + PARAM1);
826
    d->XMM_D(0) = int64_to_float64(T0, &env->sse_status);
827
}
828
#endif
829

    
830
/* float to integer */
831
void OPPROTO op_cvtps2dq(void)
832
{
833
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
834
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
835
    d->XMM_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
836
    d->XMM_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
837
    d->XMM_L(2) = float32_to_int32(s->XMM_S(2), &env->sse_status);
838
    d->XMM_L(3) = float32_to_int32(s->XMM_S(3), &env->sse_status);
839
}
840

    
841
void OPPROTO op_cvtpd2dq(void)
842
{
843
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
844
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
845
    d->XMM_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
846
    d->XMM_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
847
    d->XMM_Q(1) = 0;
848
}
849

    
850
void OPPROTO op_cvtps2pi(void)
851
{
852
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
853
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
854
    d->MMX_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
855
    d->MMX_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
856
}
857

    
858
void OPPROTO op_cvtpd2pi(void)
859
{
860
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
861
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
862
    d->MMX_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
863
    d->MMX_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
864
}
865

    
866
void OPPROTO op_cvtss2si(void)
867
{
868
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
869
    T0 = float32_to_int32(s->XMM_S(0), &env->sse_status);
870
}
871

    
872
void OPPROTO op_cvtsd2si(void)
873
{
874
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
875
    T0 = float64_to_int32(s->XMM_D(0), &env->sse_status);
876
}
877

    
878
#ifdef TARGET_X86_64
879
void OPPROTO op_cvtss2sq(void)
880
{
881
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
882
    T0 = float32_to_int64(s->XMM_S(0), &env->sse_status);
883
}
884

    
885
void OPPROTO op_cvtsd2sq(void)
886
{
887
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
888
    T0 = float64_to_int64(s->XMM_D(0), &env->sse_status);
889
}
890
#endif
891

    
892
/* float to integer truncated */
893
void OPPROTO op_cvttps2dq(void)
894
{
895
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
896
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
897
    d->XMM_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
898
    d->XMM_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
899
    d->XMM_L(2) = float32_to_int32_round_to_zero(s->XMM_S(2), &env->sse_status);
900
    d->XMM_L(3) = float32_to_int32_round_to_zero(s->XMM_S(3), &env->sse_status);
901
}
902

    
903
void OPPROTO op_cvttpd2dq(void)
904
{
905
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
906
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
907
    d->XMM_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
908
    d->XMM_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
909
    d->XMM_Q(1) = 0;
910
}
911

    
912
void OPPROTO op_cvttps2pi(void)
913
{
914
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
915
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
916
    d->MMX_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
917
    d->MMX_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
918
}
919

    
920
void OPPROTO op_cvttpd2pi(void)
921
{
922
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
923
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
924
    d->MMX_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
925
    d->MMX_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
926
}
927

    
928
void OPPROTO op_cvttss2si(void)
929
{
930
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
931
    T0 = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
932
}
933

    
934
void OPPROTO op_cvttsd2si(void)
935
{
936
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
937
    T0 = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
938
}
939

    
940
#ifdef TARGET_X86_64
941
void OPPROTO op_cvttss2sq(void)
942
{
943
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
944
    T0 = float32_to_int64_round_to_zero(s->XMM_S(0), &env->sse_status);
945
}
946

    
947
void OPPROTO op_cvttsd2sq(void)
948
{
949
    XMMReg *s = (XMMReg *)((char *)env + PARAM1);
950
    T0 = float64_to_int64_round_to_zero(s->XMM_D(0), &env->sse_status);
951
}
952
#endif
953

    
954
void OPPROTO op_rsqrtps(void)
955
{
956
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
957
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
958
    d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
959
    d->XMM_S(1) = approx_rsqrt(s->XMM_S(1));
960
    d->XMM_S(2) = approx_rsqrt(s->XMM_S(2));
961
    d->XMM_S(3) = approx_rsqrt(s->XMM_S(3));
962
}
963

    
964
void OPPROTO op_rsqrtss(void)
965
{
966
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
967
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
968
    d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
969
}
970

    
971
void OPPROTO op_rcpps(void)
972
{
973
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
974
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
975
    d->XMM_S(0) = approx_rcp(s->XMM_S(0));
976
    d->XMM_S(1) = approx_rcp(s->XMM_S(1));
977
    d->XMM_S(2) = approx_rcp(s->XMM_S(2));
978
    d->XMM_S(3) = approx_rcp(s->XMM_S(3));
979
}
980

    
981
void OPPROTO op_rcpss(void)
982
{
983
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
984
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
985
    d->XMM_S(0) = approx_rcp(s->XMM_S(0));
986
}
987

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

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

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

    
1022
void OPPROTO op_hsubpd(void)
1023
{
1024
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1025
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1026
    XMMReg r;
1027
    r.XMM_D(0) = d->XMM_D(0) - d->XMM_D(1);
1028
    r.XMM_D(1) = s->XMM_D(0) - s->XMM_D(1);
1029
    *d = r;
1030
}
1031

    
1032
void OPPROTO op_addsubps(void)
1033
{
1034
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1035
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1036
    d->XMM_S(0) = d->XMM_S(0) - s->XMM_S(0);
1037
    d->XMM_S(1) = d->XMM_S(1) + s->XMM_S(1);
1038
    d->XMM_S(2) = d->XMM_S(2) - s->XMM_S(2);
1039
    d->XMM_S(3) = d->XMM_S(3) + s->XMM_S(3);
1040
}
1041

    
1042
void OPPROTO op_addsubpd(void)
1043
{
1044
    XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1045
    XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1046
    d->XMM_D(0) = d->XMM_D(0) - s->XMM_D(0);
1047
    d->XMM_D(1) = d->XMM_D(1) + s->XMM_D(1);
1048
}
1049

    
1050
/* XXX: unordered */
1051
#define SSE_OP_CMP(name, F)\
1052
void OPPROTO op_ ## name ## ps (void)\
1053
{\
1054
    Reg *d, *s;\
1055
    d = (Reg *)((char *)env + PARAM1);\
1056
    s = (Reg *)((char *)env + PARAM2);\
1057
    d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1058
    d->XMM_L(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
1059
    d->XMM_L(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
1060
    d->XMM_L(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
1061
}\
1062
\
1063
void OPPROTO op_ ## name ## ss (void)\
1064
{\
1065
    Reg *d, *s;\
1066
    d = (Reg *)((char *)env + PARAM1);\
1067
    s = (Reg *)((char *)env + PARAM2);\
1068
    d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1069
}\
1070
void OPPROTO op_ ## name ## pd (void)\
1071
{\
1072
    Reg *d, *s;\
1073
    d = (Reg *)((char *)env + PARAM1);\
1074
    s = (Reg *)((char *)env + PARAM2);\
1075
    d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1076
    d->XMM_Q(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
1077
}\
1078
\
1079
void OPPROTO op_ ## name ## sd (void)\
1080
{\
1081
    Reg *d, *s;\
1082
    d = (Reg *)((char *)env + PARAM1);\
1083
    s = (Reg *)((char *)env + PARAM2);\
1084
    d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1085
}
1086

    
1087
#define FPU_CMPEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? -1 : 0
1088
#define FPU_CMPLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? -1 : 0
1089
#define FPU_CMPLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? -1 : 0
1090
#define FPU_CMPUNORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? - 1 : 0
1091
#define FPU_CMPNEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? 0 : -1
1092
#define FPU_CMPNLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? 0 : -1
1093
#define FPU_CMPNLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? 0 : -1
1094
#define FPU_CMPORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? 0 : -1
1095

    
1096
SSE_OP_CMP(cmpeq, FPU_CMPEQ)
1097
SSE_OP_CMP(cmplt, FPU_CMPLT)
1098
SSE_OP_CMP(cmple, FPU_CMPLE)
1099
SSE_OP_CMP(cmpunord, FPU_CMPUNORD)
1100
SSE_OP_CMP(cmpneq, FPU_CMPNEQ)
1101
SSE_OP_CMP(cmpnlt, FPU_CMPNLT)
1102
SSE_OP_CMP(cmpnle, FPU_CMPNLE)
1103
SSE_OP_CMP(cmpord, FPU_CMPORD)
1104

    
1105
const int comis_eflags[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
1106

    
1107
void OPPROTO op_ucomiss(void)
1108
{
1109
    int ret;
1110
    float32 s0, s1;
1111
    Reg *d, *s;
1112
    d = (Reg *)((char *)env + PARAM1);
1113
    s = (Reg *)((char *)env + PARAM2);
1114

    
1115
    s0 = d->XMM_S(0);
1116
    s1 = s->XMM_S(0);
1117
    ret = float32_compare_quiet(s0, s1, &env->sse_status);
1118
    CC_SRC = comis_eflags[ret + 1];
1119
    FORCE_RET();
1120
}
1121

    
1122
void OPPROTO op_comiss(void)
1123
{
1124
    int ret;
1125
    float32 s0, s1;
1126
    Reg *d, *s;
1127
    d = (Reg *)((char *)env + PARAM1);
1128
    s = (Reg *)((char *)env + PARAM2);
1129

    
1130
    s0 = d->XMM_S(0);
1131
    s1 = s->XMM_S(0);
1132
    ret = float32_compare(s0, s1, &env->sse_status);
1133
    CC_SRC = comis_eflags[ret + 1];
1134
    FORCE_RET();
1135
}
1136

    
1137
void OPPROTO op_ucomisd(void)
1138
{
1139
    int ret;
1140
    float64 d0, d1;
1141
    Reg *d, *s;
1142
    d = (Reg *)((char *)env + PARAM1);
1143
    s = (Reg *)((char *)env + PARAM2);
1144

    
1145
    d0 = d->XMM_D(0);
1146
    d1 = s->XMM_D(0);
1147
    ret = float64_compare_quiet(d0, d1, &env->sse_status);
1148
    CC_SRC = comis_eflags[ret + 1];
1149
    FORCE_RET();
1150
}
1151

    
1152
void OPPROTO op_comisd(void)
1153
{
1154
    int ret;
1155
    float64 d0, d1;
1156
    Reg *d, *s;
1157
    d = (Reg *)((char *)env + PARAM1);
1158
    s = (Reg *)((char *)env + PARAM2);
1159

    
1160
    d0 = d->XMM_D(0);
1161
    d1 = s->XMM_D(0);
1162
    ret = float64_compare(d0, d1, &env->sse_status);
1163
    CC_SRC = comis_eflags[ret + 1];
1164
    FORCE_RET();
1165
}
1166

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

    
1179
void OPPROTO op_movmskpd(void)
1180
{
1181
    int b0, b1;
1182
    Reg *s;
1183
    s = (Reg *)((char *)env + PARAM1);
1184
    b0 = s->XMM_L(1) >> 31;
1185
    b1 = s->XMM_L(3) >> 31;
1186
    T0 = b0 | (b1 << 1);
1187
}
1188

    
1189
#endif
1190

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

    
1216
void OPPROTO glue(op_pinsrw, SUFFIX) (void)
1217
{
1218
    Reg *d = (Reg *)((char *)env + PARAM1);
1219
    int pos = PARAM2;
1220

    
1221
    d->W(pos) = T0;
1222
}
1223

    
1224
void OPPROTO glue(op_pextrw, SUFFIX) (void)
1225
{
1226
    Reg *s = (Reg *)((char *)env + PARAM1);
1227
    int pos = PARAM2;
1228

    
1229
    T0 = s->W(pos);
1230
}
1231

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

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

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

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

    
1290
void OPPROTO glue(op_packssdw, SUFFIX) (void)
1291
{
1292
    Reg r, *d, *s;
1293
    d = (Reg *)((char *)env + PARAM1);
1294
    s = (Reg *)((char *)env + PARAM2);
1295

    
1296
    r.W(0) = satsw(d->L(0));
1297
    r.W(1) = satsw(d->L(1));
1298
#if SHIFT == 1
1299
    r.W(2) = satsw(d->L(2));
1300
    r.W(3) = satsw(d->L(3));
1301
#endif
1302
    r.W((2 << SHIFT) + 0) = satsw(s->L(0));
1303
    r.W((2 << SHIFT) + 1) = satsw(s->L(1));
1304
#if SHIFT == 1
1305
    r.W(6) = satsw(s->L(2));
1306
    r.W(7) = satsw(s->L(3));
1307
#endif
1308
    *d = r;
1309
}
1310

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

    
1387
UNPCK_OP(l, 0)
1388
UNPCK_OP(h, 1)
1389

    
1390
/* 3DNow! float ops */
1391
#if SHIFT == 0
1392
void OPPROTO op_pi2fd(void)
1393
{
1394
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1395
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1396
    d->MMX_S(0) = int32_to_float32(s->MMX_L(0), &env->mmx_status);
1397
    d->MMX_S(1) = int32_to_float32(s->MMX_L(1), &env->mmx_status);
1398
}
1399

    
1400
void OPPROTO op_pi2fw(void)
1401
{
1402
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1403
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1404
    d->MMX_S(0) = int32_to_float32((int16_t)s->MMX_W(0), &env->mmx_status);
1405
    d->MMX_S(1) = int32_to_float32((int16_t)s->MMX_W(2), &env->mmx_status);
1406
}
1407

    
1408
void OPPROTO op_pf2id(void)
1409
{
1410
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1411
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1412
    d->MMX_L(0) = float32_to_int32_round_to_zero(s->MMX_S(0), &env->mmx_status);
1413
    d->MMX_L(1) = float32_to_int32_round_to_zero(s->MMX_S(1), &env->mmx_status);
1414
}
1415

    
1416
void OPPROTO op_pf2iw(void)
1417
{
1418
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1419
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1420
    d->MMX_L(0) = satsw(float32_to_int32_round_to_zero(s->MMX_S(0), &env->mmx_status));
1421
    d->MMX_L(1) = satsw(float32_to_int32_round_to_zero(s->MMX_S(1), &env->mmx_status));
1422
}
1423

    
1424
void OPPROTO op_pfacc(void)
1425
{
1426
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1427
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1428
    MMXReg r;
1429
    r.MMX_S(0) = float32_add(d->MMX_S(0), d->MMX_S(1), &env->mmx_status);
1430
    r.MMX_S(1) = float32_add(s->MMX_S(0), s->MMX_S(1), &env->mmx_status);
1431
    *d = r;
1432
}
1433

    
1434
void OPPROTO op_pfadd(void)
1435
{
1436
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1437
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1438
    d->MMX_S(0) = float32_add(d->MMX_S(0), s->MMX_S(0), &env->mmx_status);
1439
    d->MMX_S(1) = float32_add(d->MMX_S(1), s->MMX_S(1), &env->mmx_status);
1440
}
1441

    
1442
void OPPROTO op_pfcmpeq(void)
1443
{
1444
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1445
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1446
    d->MMX_L(0) = float32_eq(d->MMX_S(0), s->MMX_S(0), &env->mmx_status) ? -1 : 0;
1447
    d->MMX_L(1) = float32_eq(d->MMX_S(1), s->MMX_S(1), &env->mmx_status) ? -1 : 0;
1448
}
1449

    
1450
void OPPROTO op_pfcmpge(void)
1451
{
1452
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1453
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1454
    d->MMX_L(0) = float32_le(s->MMX_S(0), d->MMX_S(0), &env->mmx_status) ? -1 : 0;
1455
    d->MMX_L(1) = float32_le(s->MMX_S(1), d->MMX_S(1), &env->mmx_status) ? -1 : 0;
1456
}
1457

    
1458
void OPPROTO op_pfcmpgt(void)
1459
{
1460
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1461
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1462
    d->MMX_L(0) = float32_lt(s->MMX_S(0), d->MMX_S(0), &env->mmx_status) ? -1 : 0;
1463
    d->MMX_L(1) = float32_lt(s->MMX_S(1), d->MMX_S(1), &env->mmx_status) ? -1 : 0;
1464
}
1465

    
1466
void OPPROTO op_pfmax(void)
1467
{
1468
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1469
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1470
    if (float32_lt(d->MMX_S(0), s->MMX_S(0), &env->mmx_status))
1471
        d->MMX_S(0) = s->MMX_S(0);
1472
    if (float32_lt(d->MMX_S(1), s->MMX_S(1), &env->mmx_status))
1473
        d->MMX_S(1) = s->MMX_S(1);
1474
}
1475

    
1476
void OPPROTO op_pfmin(void)
1477
{
1478
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1479
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1480
    if (float32_lt(s->MMX_S(0), d->MMX_S(0), &env->mmx_status))
1481
        d->MMX_S(0) = s->MMX_S(0);
1482
    if (float32_lt(s->MMX_S(1), d->MMX_S(1), &env->mmx_status))
1483
        d->MMX_S(1) = s->MMX_S(1);
1484
}
1485

    
1486
void OPPROTO op_pfmul(void)
1487
{
1488
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1489
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1490
    d->MMX_S(0) = float32_mul(d->MMX_S(0), s->MMX_S(0), &env->mmx_status);
1491
    d->MMX_S(1) = float32_mul(d->MMX_S(1), s->MMX_S(1), &env->mmx_status);
1492
}
1493

    
1494
void OPPROTO op_pfnacc(void)
1495
{
1496
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1497
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1498
    MMXReg r;
1499
    r.MMX_S(0) = float32_sub(d->MMX_S(0), d->MMX_S(1), &env->mmx_status);
1500
    r.MMX_S(1) = float32_sub(s->MMX_S(0), s->MMX_S(1), &env->mmx_status);
1501
    *d = r;
1502
}
1503

    
1504
void OPPROTO op_pfpnacc(void)
1505
{
1506
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1507
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1508
    MMXReg r;
1509
    r.MMX_S(0) = float32_sub(d->MMX_S(0), d->MMX_S(1), &env->mmx_status);
1510
    r.MMX_S(1) = float32_add(s->MMX_S(0), s->MMX_S(1), &env->mmx_status);
1511
    *d = r;
1512
}
1513

    
1514
void OPPROTO op_pfrcp(void)
1515
{
1516
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1517
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1518
    d->MMX_S(0) = approx_rcp(s->MMX_S(0));
1519
    d->MMX_S(1) = d->MMX_S(0);
1520
}
1521

    
1522
void OPPROTO op_pfrsqrt(void)
1523
{
1524
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1525
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1526
    d->MMX_L(1) = s->MMX_L(0) & 0x7fffffff;
1527
    d->MMX_S(1) = approx_rsqrt(d->MMX_S(1));
1528
    d->MMX_L(1) |= s->MMX_L(0) & 0x80000000;
1529
    d->MMX_L(0) = d->MMX_L(1);
1530
}
1531

    
1532
void OPPROTO op_pfsub(void)
1533
{
1534
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1535
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1536
    d->MMX_S(0) = float32_sub(d->MMX_S(0), s->MMX_S(0), &env->mmx_status);
1537
    d->MMX_S(1) = float32_sub(d->MMX_S(1), s->MMX_S(1), &env->mmx_status);
1538
}
1539

    
1540
void OPPROTO op_pfsubr(void)
1541
{
1542
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1543
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1544
    d->MMX_S(0) = float32_sub(s->MMX_S(0), d->MMX_S(0), &env->mmx_status);
1545
    d->MMX_S(1) = float32_sub(s->MMX_S(1), d->MMX_S(1), &env->mmx_status);
1546
}
1547

    
1548
void OPPROTO op_pswapd(void)
1549
{
1550
    MMXReg *d = (MMXReg *)((char *)env + PARAM1);
1551
    MMXReg *s = (MMXReg *)((char *)env + PARAM2);
1552
    MMXReg r;
1553
    r.MMX_L(0) = s->MMX_L(1);
1554
    r.MMX_L(1) = s->MMX_L(0);
1555
    *d = r;
1556
}
1557
#endif
1558

    
1559
#undef SHIFT
1560
#undef XMM_ONLY
1561
#undef Reg
1562
#undef B
1563
#undef W
1564
#undef L
1565
#undef Q
1566
#undef SUFFIX