]> Git Repo - qemu.git/blame - target-i386/ops_sse.h
NaN support in FPU comparisons
[qemu.git] / target-i386 / ops_sse.h
CommitLineData
664e0f19
FB
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
38void 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 }
0523c6b7 64 FORCE_RET();
664e0f19
FB
65}
66
67void 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
92void 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 }
0523c6b7 118 FORCE_RET();
664e0f19
FB
119}
120
121void 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 }
0523c6b7 143 FORCE_RET();
664e0f19
FB
144}
145
146void 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
167void 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 }
0523c6b7 189 FORCE_RET();
664e0f19
FB
190}
191
192void 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 }
0523c6b7 212 FORCE_RET();
664e0f19
FB
213}
214
215void 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 }
0523c6b7 235 FORCE_RET();
664e0f19
FB
236}
237
238#if SHIFT == 1
239void 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
256void 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)\
275void 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)\
301void 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)\
319void 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)\
333void 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
345static 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
355static 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
365static 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
375static 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
418SSE_OP_B(op_paddb, FADD)
419SSE_OP_W(op_paddw, FADD)
420SSE_OP_L(op_paddl, FADD)
421SSE_OP_Q(op_paddq, FADD)
422
423SSE_OP_B(op_psubb, FSUB)
424SSE_OP_W(op_psubw, FSUB)
425SSE_OP_L(op_psubl, FSUB)
426SSE_OP_Q(op_psubq, FSUB)
427
428SSE_OP_B(op_paddusb, FADDUB)
429SSE_OP_B(op_paddsb, FADDSB)
430SSE_OP_B(op_psubusb, FSUBUB)
431SSE_OP_B(op_psubsb, FSUBSB)
432
433SSE_OP_W(op_paddusw, FADDUW)
434SSE_OP_W(op_paddsw, FADDSW)
435SSE_OP_W(op_psubusw, FSUBUW)
436SSE_OP_W(op_psubsw, FSUBSW)
437
438SSE_OP_B(op_pminub, FMINUB)
439SSE_OP_B(op_pmaxub, FMAXUB)
440
441SSE_OP_W(op_pminsw, FMINSW)
442SSE_OP_W(op_pmaxsw, FMAXSW)
443
444SSE_OP_Q(op_pand, FAND)
445SSE_OP_Q(op_pandn, FANDN)
446SSE_OP_Q(op_por, FOR)
447SSE_OP_Q(op_pxor, FXOR)
448
449SSE_OP_B(op_pcmpgtb, FCMPGTB)
450SSE_OP_W(op_pcmpgtw, FCMPGTW)
451SSE_OP_L(op_pcmpgtl, FCMPGTL)
452
453SSE_OP_B(op_pcmpeqb, FCMPEQ)
454SSE_OP_W(op_pcmpeqw, FCMPEQ)
455SSE_OP_L(op_pcmpeql, FCMPEQ)
456
457SSE_OP_W(op_pmullw, FMULLW)
458SSE_OP_W(op_pmulhuw, FMULHUW)
459SSE_OP_W(op_pmulhw, FMULHW)
460
461SSE_OP_B(op_pavgb, FAVG)
462SSE_OP_W(op_pavgw, FAVG)
463
464void 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
476void 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 }
0523c6b7 487 FORCE_RET();
664e0f19
FB
488}
489
490#if SHIFT == 0
491static inline int abs1(int a)
492{
493 if (a < 0)
494 return -a;
495 else
496 return a;
497}
498#endif
499void 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
530void 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)
d52cf7a6 538 stb(A0 + i, d->B(i));
664e0f19 539 }
0523c6b7 540 FORCE_RET();
664e0f19
FB
541}
542
543void 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
554void 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
562void 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
d52cf7a6
FB
576void 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
664e0f19
FB
590void 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;
d52cf7a6 597 r.Q(0) = d->Q(order & 1);
664e0f19
FB
598 r.Q(1) = s->Q((order >> 1) & 1);
599 *d = r;
600}
601
602void 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
616void 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
631void 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)\
652void OPPROTO op_ ## name ## ps (void)\
653{\
654 Reg *d, *s;\
655 d = (Reg *)((char *)env + PARAM1);\
656 s = (Reg *)((char *)env + PARAM2);\
7a0e1f41
FB
657 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
658 d->XMM_S(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
659 d->XMM_S(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
660 d->XMM_S(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
664e0f19
FB
661}\
662\
663void OPPROTO op_ ## name ## ss (void)\
664{\
665 Reg *d, *s;\
666 d = (Reg *)((char *)env + PARAM1);\
667 s = (Reg *)((char *)env + PARAM2);\
7a0e1f41 668 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
664e0f19
FB
669}\
670void OPPROTO op_ ## name ## pd (void)\
671{\
672 Reg *d, *s;\
673 d = (Reg *)((char *)env + PARAM1);\
674 s = (Reg *)((char *)env + PARAM2);\
7a0e1f41
FB
675 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
676 d->XMM_D(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
664e0f19
FB
677}\
678\
679void OPPROTO op_ ## name ## sd (void)\
680{\
681 Reg *d, *s;\
682 d = (Reg *)((char *)env + PARAM1);\
683 s = (Reg *)((char *)env + PARAM2);\
7a0e1f41 684 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
664e0f19
FB
685}
686
7a0e1f41
FB
687#define FPU_ADD(size, a, b) float ## size ## _add(a, b, &env->sse_status)
688#define FPU_SUB(size, a, b) float ## size ## _sub(a, b, &env->sse_status)
689#define FPU_MUL(size, a, b) float ## size ## _mul(a, b, &env->sse_status)
690#define FPU_DIV(size, a, b) float ## size ## _div(a, b, &env->sse_status)
691#define FPU_MIN(size, a, b) (a) < (b) ? (a) : (b)
692#define FPU_MAX(size, a, b) (a) > (b) ? (a) : (b)
693#define FPU_SQRT(size, a, b) float ## size ## _sqrt(b, &env->sse_status)
664e0f19
FB
694
695SSE_OP_S(add, FPU_ADD)
696SSE_OP_S(sub, FPU_SUB)
697SSE_OP_S(mul, FPU_MUL)
698SSE_OP_S(div, FPU_DIV)
699SSE_OP_S(min, FPU_MIN)
700SSE_OP_S(max, FPU_MAX)
701SSE_OP_S(sqrt, FPU_SQRT)
702
703
704/* float to float conversions */
705void OPPROTO op_cvtps2pd(void)
706{
8422b113 707 float32 s0, s1;
664e0f19
FB
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);
7a0e1f41
FB
713 d->XMM_D(0) = float32_to_float64(s0, &env->sse_status);
714 d->XMM_D(1) = float32_to_float64(s1, &env->sse_status);
664e0f19
FB
715}
716
717void OPPROTO op_cvtpd2ps(void)
718{
719 Reg *d, *s;
720 d = (Reg *)((char *)env + PARAM1);
721 s = (Reg *)((char *)env + PARAM2);
7a0e1f41
FB
722 d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
723 d->XMM_S(1) = float64_to_float32(s->XMM_D(1), &env->sse_status);
664e0f19
FB
724 d->Q(1) = 0;
725}
726
727void OPPROTO op_cvtss2sd(void)
728{
729 Reg *d, *s;
730 d = (Reg *)((char *)env + PARAM1);
731 s = (Reg *)((char *)env + PARAM2);
7a0e1f41 732 d->XMM_D(0) = float32_to_float64(s->XMM_S(0), &env->sse_status);
664e0f19
FB
733}
734
735void OPPROTO op_cvtsd2ss(void)
736{
737 Reg *d, *s;
738 d = (Reg *)((char *)env + PARAM1);
739 s = (Reg *)((char *)env + PARAM2);
7a0e1f41 740 d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
664e0f19
FB
741}
742
743/* integer to float */
744void OPPROTO op_cvtdq2ps(void)
745{
746 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
747 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
748 d->XMM_S(0) = int32_to_float32(s->XMM_L(0), &env->sse_status);
749 d->XMM_S(1) = int32_to_float32(s->XMM_L(1), &env->sse_status);
750 d->XMM_S(2) = int32_to_float32(s->XMM_L(2), &env->sse_status);
751 d->XMM_S(3) = int32_to_float32(s->XMM_L(3), &env->sse_status);
664e0f19
FB
752}
753
754void 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);
7a0e1f41
FB
761 d->XMM_D(0) = int32_to_float64(l0, &env->sse_status);
762 d->XMM_D(1) = int32_to_float64(l1, &env->sse_status);
664e0f19
FB
763}
764
765void OPPROTO op_cvtpi2ps(void)
766{
767 XMMReg *d = (Reg *)((char *)env + PARAM1);
768 MMXReg *s = (MMXReg *)((char *)env + PARAM2);
7a0e1f41
FB
769 d->XMM_S(0) = int32_to_float32(s->MMX_L(0), &env->sse_status);
770 d->XMM_S(1) = int32_to_float32(s->MMX_L(1), &env->sse_status);
664e0f19
FB
771}
772
773void OPPROTO op_cvtpi2pd(void)
774{
775 XMMReg *d = (Reg *)((char *)env + PARAM1);
776 MMXReg *s = (MMXReg *)((char *)env + PARAM2);
7a0e1f41
FB
777 d->XMM_D(0) = int32_to_float64(s->MMX_L(0), &env->sse_status);
778 d->XMM_D(1) = int32_to_float64(s->MMX_L(1), &env->sse_status);
664e0f19
FB
779}
780
781void OPPROTO op_cvtsi2ss(void)
782{
783 XMMReg *d = (Reg *)((char *)env + PARAM1);
7a0e1f41 784 d->XMM_S(0) = int32_to_float32(T0, &env->sse_status);
664e0f19
FB
785}
786
787void OPPROTO op_cvtsi2sd(void)
788{
789 XMMReg *d = (Reg *)((char *)env + PARAM1);
7a0e1f41 790 d->XMM_D(0) = int32_to_float64(T0, &env->sse_status);
664e0f19
FB
791}
792
793#ifdef TARGET_X86_64
794void OPPROTO op_cvtsq2ss(void)
795{
796 XMMReg *d = (Reg *)((char *)env + PARAM1);
7a0e1f41 797 d->XMM_S(0) = int64_to_float32(T0, &env->sse_status);
664e0f19
FB
798}
799
800void OPPROTO op_cvtsq2sd(void)
801{
802 XMMReg *d = (Reg *)((char *)env + PARAM1);
7a0e1f41 803 d->XMM_D(0) = int64_to_float64(T0, &env->sse_status);
664e0f19
FB
804}
805#endif
806
807/* float to integer */
808void OPPROTO op_cvtps2dq(void)
809{
810 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
811 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
812 d->XMM_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
813 d->XMM_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
814 d->XMM_L(2) = float32_to_int32(s->XMM_S(2), &env->sse_status);
815 d->XMM_L(3) = float32_to_int32(s->XMM_S(3), &env->sse_status);
664e0f19
FB
816}
817
818void OPPROTO op_cvtpd2dq(void)
819{
820 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
821 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
822 d->XMM_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
823 d->XMM_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
664e0f19
FB
824 d->XMM_Q(1) = 0;
825}
826
827void OPPROTO op_cvtps2pi(void)
828{
829 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
830 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
831 d->MMX_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
832 d->MMX_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
664e0f19
FB
833}
834
835void OPPROTO op_cvtpd2pi(void)
836{
837 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
838 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
839 d->MMX_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
840 d->MMX_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
664e0f19
FB
841}
842
843void OPPROTO op_cvtss2si(void)
844{
845 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 846 T0 = float32_to_int32(s->XMM_S(0), &env->sse_status);
664e0f19
FB
847}
848
849void OPPROTO op_cvtsd2si(void)
850{
851 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 852 T0 = float64_to_int32(s->XMM_D(0), &env->sse_status);
664e0f19
FB
853}
854
855#ifdef TARGET_X86_64
856void OPPROTO op_cvtss2sq(void)
857{
858 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 859 T0 = float32_to_int64(s->XMM_S(0), &env->sse_status);
664e0f19
FB
860}
861
862void OPPROTO op_cvtsd2sq(void)
863{
864 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 865 T0 = float64_to_int64(s->XMM_D(0), &env->sse_status);
664e0f19
FB
866}
867#endif
868
869/* float to integer truncated */
870void OPPROTO op_cvttps2dq(void)
871{
872 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
873 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
874 d->XMM_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
875 d->XMM_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
876 d->XMM_L(2) = float32_to_int32_round_to_zero(s->XMM_S(2), &env->sse_status);
877 d->XMM_L(3) = float32_to_int32_round_to_zero(s->XMM_S(3), &env->sse_status);
664e0f19
FB
878}
879
880void OPPROTO op_cvttpd2dq(void)
881{
882 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
883 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
884 d->XMM_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
885 d->XMM_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
664e0f19
FB
886 d->XMM_Q(1) = 0;
887}
888
889void OPPROTO op_cvttps2pi(void)
890{
891 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
892 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
893 d->MMX_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
894 d->MMX_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
664e0f19
FB
895}
896
897void OPPROTO op_cvttpd2pi(void)
898{
899 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
900 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
7a0e1f41
FB
901 d->MMX_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
902 d->MMX_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
664e0f19
FB
903}
904
905void OPPROTO op_cvttss2si(void)
906{
907 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 908 T0 = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
664e0f19
FB
909}
910
911void OPPROTO op_cvttsd2si(void)
912{
913 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 914 T0 = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
664e0f19
FB
915}
916
917#ifdef TARGET_X86_64
918void OPPROTO op_cvttss2sq(void)
919{
920 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 921 T0 = float32_to_int64_round_to_zero(s->XMM_S(0), &env->sse_status);
664e0f19
FB
922}
923
924void OPPROTO op_cvttsd2sq(void)
925{
926 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
7a0e1f41 927 T0 = float64_to_int64_round_to_zero(s->XMM_D(0), &env->sse_status);
664e0f19
FB
928}
929#endif
930
931void 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
941void 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
948void 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
958void 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
965void 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
977void 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
987void 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
999void 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
1009void 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
1019void 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)\
1029void OPPROTO op_ ## name ## ps (void)\
1030{\
1031 Reg *d, *s;\
1032 d = (Reg *)((char *)env + PARAM1);\
1033 s = (Reg *)((char *)env + PARAM2);\
8422b113
FB
1034 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1035 d->XMM_L(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
1036 d->XMM_L(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
1037 d->XMM_L(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
664e0f19
FB
1038}\
1039\
1040void OPPROTO op_ ## name ## ss (void)\
1041{\
1042 Reg *d, *s;\
1043 d = (Reg *)((char *)env + PARAM1);\
1044 s = (Reg *)((char *)env + PARAM2);\
8422b113 1045 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
664e0f19
FB
1046}\
1047void OPPROTO op_ ## name ## pd (void)\
1048{\
1049 Reg *d, *s;\
1050 d = (Reg *)((char *)env + PARAM1);\
1051 s = (Reg *)((char *)env + PARAM2);\
8422b113
FB
1052 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1053 d->XMM_Q(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
664e0f19
FB
1054}\
1055\
1056void OPPROTO op_ ## name ## sd (void)\
1057{\
1058 Reg *d, *s;\
1059 d = (Reg *)((char *)env + PARAM1);\
1060 s = (Reg *)((char *)env + PARAM2);\
8422b113 1061 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
664e0f19
FB
1062}
1063
8422b113
FB
1064#define FPU_CMPEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? -1 : 0
1065#define FPU_CMPLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? -1 : 0
1066#define FPU_CMPLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? -1 : 0
1067#define FPU_CMPUNORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? - 1 : 0
1068#define FPU_CMPNEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? 0 : -1
1069#define FPU_CMPNLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? 0 : -1
1070#define FPU_CMPNLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? 0 : -1
1071#define FPU_CMPORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? 0 : -1
664e0f19
FB
1072
1073SSE_OP_CMP(cmpeq, FPU_CMPEQ)
1074SSE_OP_CMP(cmplt, FPU_CMPLT)
1075SSE_OP_CMP(cmple, FPU_CMPLE)
1076SSE_OP_CMP(cmpunord, FPU_CMPUNORD)
1077SSE_OP_CMP(cmpneq, FPU_CMPNEQ)
1078SSE_OP_CMP(cmpnlt, FPU_CMPNLT)
1079SSE_OP_CMP(cmpnle, FPU_CMPNLE)
1080SSE_OP_CMP(cmpord, FPU_CMPORD)
1081
1082void OPPROTO op_ucomiss(void)
1083{
1084 int eflags;
8422b113 1085 float32 s0, s1;
664e0f19
FB
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);
8422b113
FB
1092 switch(float32_compare_quiet(s0, s1, &env->sse_status)) {
1093 case -1:
664e0f19 1094 eflags = CC_C;
8422b113
FB
1095 break;
1096 case 0:
664e0f19 1097 eflags = CC_Z;
8422b113
FB
1098 break;
1099 case 1:
664e0f19 1100 eflags = 0;
8422b113
FB
1101 break;
1102 case 2:
1103 default:
1104 eflags = CC_Z | CC_P | CC_C;
1105 break;
1106 }
664e0f19
FB
1107 CC_SRC = eflags;
1108 FORCE_RET();
1109}
1110
1111void OPPROTO op_comiss(void)
1112{
1113 int eflags;
8422b113 1114 float32 s0, s1;
664e0f19
FB
1115 Reg *d, *s;
1116 d = (Reg *)((char *)env + PARAM1);
1117 s = (Reg *)((char *)env + PARAM2);
1118
1119 s0 = d->XMM_S(0);
1120 s1 = s->XMM_S(0);
8422b113
FB
1121 switch(float32_compare(s0, s1, &env->sse_status)) {
1122 case -1:
664e0f19 1123 eflags = CC_C;
8422b113
FB
1124 break;
1125 case 0:
664e0f19 1126 eflags = CC_Z;
8422b113
FB
1127 break;
1128 case 1:
664e0f19 1129 eflags = 0;
8422b113
FB
1130 break;
1131 case 2:
1132 default:
1133 eflags = CC_Z | CC_P | CC_C;
1134 break;
1135 }
664e0f19
FB
1136 CC_SRC = eflags;
1137 FORCE_RET();
1138}
1139
1140void OPPROTO op_ucomisd(void)
1141{
1142 int eflags;
8422b113 1143 float64 d0, d1;
664e0f19
FB
1144 Reg *d, *s;
1145 d = (Reg *)((char *)env + PARAM1);
1146 s = (Reg *)((char *)env + PARAM2);
1147
1148 d0 = d->XMM_D(0);
1149 d1 = s->XMM_D(0);
8422b113
FB
1150 switch(float64_compare_quiet(d0, d1, &env->sse_status)) {
1151 case -1:
664e0f19 1152 eflags = CC_C;
8422b113
FB
1153 break;
1154 case 0:
664e0f19 1155 eflags = CC_Z;
8422b113
FB
1156 break;
1157 case 1:
664e0f19 1158 eflags = 0;
8422b113
FB
1159 break;
1160 case 2:
1161 default:
1162 eflags = CC_Z | CC_P | CC_C;
1163 break;
1164 }
664e0f19
FB
1165 CC_SRC = eflags;
1166 FORCE_RET();
1167}
1168
1169void OPPROTO op_comisd(void)
1170{
1171 int eflags;
8422b113 1172 float64 d0, d1;
664e0f19
FB
1173 Reg *d, *s;
1174 d = (Reg *)((char *)env + PARAM1);
1175 s = (Reg *)((char *)env + PARAM2);
1176
1177 d0 = d->XMM_D(0);
1178 d1 = s->XMM_D(0);
8422b113
FB
1179 switch(float64_compare(d0, d1, &env->sse_status)) {
1180 case -1:
664e0f19 1181 eflags = CC_C;
8422b113
FB
1182 break;
1183 case 0:
664e0f19 1184 eflags = CC_Z;
8422b113
FB
1185 break;
1186 case 1:
664e0f19 1187 eflags = 0;
8422b113
FB
1188 break;
1189 case 2:
1190 default:
1191 eflags = CC_Z | CC_P | CC_C;
1192 break;
1193 }
664e0f19
FB
1194 CC_SRC = eflags;
1195 FORCE_RET();
1196}
1197
1198void OPPROTO op_movmskps(void)
1199{
1200 int b0, b1, b2, b3;
1201 Reg *s;
1202 s = (Reg *)((char *)env + PARAM1);
1203 b0 = s->XMM_L(0) >> 31;
1204 b1 = s->XMM_L(1) >> 31;
1205 b2 = s->XMM_L(2) >> 31;
1206 b3 = s->XMM_L(3) >> 31;
1207 T0 = b0 | (b1 << 1) | (b2 << 2) | (b3 << 3);
1208}
1209
1210void OPPROTO op_movmskpd(void)
1211{
1212 int b0, b1;
1213 Reg *s;
1214 s = (Reg *)((char *)env + PARAM1);
1215 b0 = s->XMM_L(1) >> 31;
1216 b1 = s->XMM_L(3) >> 31;
1217 T0 = b0 | (b1 << 1);
1218}
1219
1220#endif
1221
1222void OPPROTO glue(op_pmovmskb, SUFFIX)(void)
1223{
1224 Reg *s;
1225 s = (Reg *)((char *)env + PARAM1);
1226 T0 = 0;
1227 T0 |= (s->XMM_B(0) >> 7);
1228 T0 |= (s->XMM_B(1) >> 6) & 0x02;
1229 T0 |= (s->XMM_B(2) >> 5) & 0x04;
1230 T0 |= (s->XMM_B(3) >> 4) & 0x08;
1231 T0 |= (s->XMM_B(4) >> 3) & 0x10;
1232 T0 |= (s->XMM_B(5) >> 2) & 0x20;
1233 T0 |= (s->XMM_B(6) >> 1) & 0x40;
1234 T0 |= (s->XMM_B(7)) & 0x80;
1235#if SHIFT == 1
1236 T0 |= (s->XMM_B(8) << 1) & 0x0100;
1237 T0 |= (s->XMM_B(9) << 2) & 0x0200;
1238 T0 |= (s->XMM_B(10) << 3) & 0x0400;
1239 T0 |= (s->XMM_B(11) << 4) & 0x0800;
1240 T0 |= (s->XMM_B(12) << 5) & 0x1000;
1241 T0 |= (s->XMM_B(13) << 6) & 0x2000;
1242 T0 |= (s->XMM_B(14) << 7) & 0x4000;
1243 T0 |= (s->XMM_B(15) << 8) & 0x8000;
1244#endif
1245}
1246
1247void OPPROTO glue(op_pinsrw, SUFFIX) (void)
1248{
1249 Reg *d = (Reg *)((char *)env + PARAM1);
1250 int pos = PARAM2;
1251
1252 d->W(pos) = T0;
1253}
1254
1255void OPPROTO glue(op_pextrw, SUFFIX) (void)
1256{
1257 Reg *s = (Reg *)((char *)env + PARAM1);
1258 int pos = PARAM2;
1259
1260 T0 = s->W(pos);
1261}
1262
1263void OPPROTO glue(op_packsswb, SUFFIX) (void)
1264{
1265 Reg r, *d, *s;
1266 d = (Reg *)((char *)env + PARAM1);
1267 s = (Reg *)((char *)env + PARAM2);
1268
1269 r.B(0) = satsb((int16_t)d->W(0));
1270 r.B(1) = satsb((int16_t)d->W(1));
1271 r.B(2) = satsb((int16_t)d->W(2));
1272 r.B(3) = satsb((int16_t)d->W(3));
1273#if SHIFT == 1
1274 r.B(4) = satsb((int16_t)d->W(4));
1275 r.B(5) = satsb((int16_t)d->W(5));
1276 r.B(6) = satsb((int16_t)d->W(6));
1277 r.B(7) = satsb((int16_t)d->W(7));
1278#endif
1279 r.B((4 << SHIFT) + 0) = satsb((int16_t)s->W(0));
1280 r.B((4 << SHIFT) + 1) = satsb((int16_t)s->W(1));
1281 r.B((4 << SHIFT) + 2) = satsb((int16_t)s->W(2));
1282 r.B((4 << SHIFT) + 3) = satsb((int16_t)s->W(3));
1283#if SHIFT == 1
1284 r.B(12) = satsb((int16_t)s->W(4));
1285 r.B(13) = satsb((int16_t)s->W(5));
1286 r.B(14) = satsb((int16_t)s->W(6));
1287 r.B(15) = satsb((int16_t)s->W(7));
1288#endif
1289 *d = r;
1290}
1291
1292void OPPROTO glue(op_packuswb, SUFFIX) (void)
1293{
1294 Reg r, *d, *s;
1295 d = (Reg *)((char *)env + PARAM1);
1296 s = (Reg *)((char *)env + PARAM2);
1297
1298 r.B(0) = satub((int16_t)d->W(0));
1299 r.B(1) = satub((int16_t)d->W(1));
1300 r.B(2) = satub((int16_t)d->W(2));
1301 r.B(3) = satub((int16_t)d->W(3));
1302#if SHIFT == 1
1303 r.B(4) = satub((int16_t)d->W(4));
1304 r.B(5) = satub((int16_t)d->W(5));
1305 r.B(6) = satub((int16_t)d->W(6));
1306 r.B(7) = satub((int16_t)d->W(7));
1307#endif
1308 r.B((4 << SHIFT) + 0) = satub((int16_t)s->W(0));
1309 r.B((4 << SHIFT) + 1) = satub((int16_t)s->W(1));
1310 r.B((4 << SHIFT) + 2) = satub((int16_t)s->W(2));
1311 r.B((4 << SHIFT) + 3) = satub((int16_t)s->W(3));
1312#if SHIFT == 1
1313 r.B(12) = satub((int16_t)s->W(4));
1314 r.B(13) = satub((int16_t)s->W(5));
1315 r.B(14) = satub((int16_t)s->W(6));
1316 r.B(15) = satub((int16_t)s->W(7));
1317#endif
1318 *d = r;
1319}
1320
1321void OPPROTO glue(op_packssdw, SUFFIX) (void)
1322{
1323 Reg r, *d, *s;
1324 d = (Reg *)((char *)env + PARAM1);
1325 s = (Reg *)((char *)env + PARAM2);
1326
1327 r.W(0) = satsw(d->L(0));
1328 r.W(1) = satsw(d->L(1));
1329#if SHIFT == 1
1330 r.W(2) = satsw(d->L(2));
1331 r.W(3) = satsw(d->L(3));
1332#endif
1333 r.W((2 << SHIFT) + 0) = satsw(s->L(0));
1334 r.W((2 << SHIFT) + 1) = satsw(s->L(1));
1335#if SHIFT == 1
1336 r.W(6) = satsw(s->L(2));
1337 r.W(7) = satsw(s->L(3));
1338#endif
1339 *d = r;
1340}
1341
1342#define UNPCK_OP(base_name, base) \
1343 \
1344void OPPROTO glue(op_punpck ## base_name ## bw, SUFFIX) (void) \
1345{ \
1346 Reg r, *d, *s; \
1347 d = (Reg *)((char *)env + PARAM1); \
1348 s = (Reg *)((char *)env + PARAM2); \
1349 \
1350 r.B(0) = d->B((base << (SHIFT + 2)) + 0); \
1351 r.B(1) = s->B((base << (SHIFT + 2)) + 0); \
1352 r.B(2) = d->B((base << (SHIFT + 2)) + 1); \
1353 r.B(3) = s->B((base << (SHIFT + 2)) + 1); \
1354 r.B(4) = d->B((base << (SHIFT + 2)) + 2); \
1355 r.B(5) = s->B((base << (SHIFT + 2)) + 2); \
1356 r.B(6) = d->B((base << (SHIFT + 2)) + 3); \
1357 r.B(7) = s->B((base << (SHIFT + 2)) + 3); \
1358XMM_ONLY( \
1359 r.B(8) = d->B((base << (SHIFT + 2)) + 4); \
1360 r.B(9) = s->B((base << (SHIFT + 2)) + 4); \
1361 r.B(10) = d->B((base << (SHIFT + 2)) + 5); \
1362 r.B(11) = s->B((base << (SHIFT + 2)) + 5); \
1363 r.B(12) = d->B((base << (SHIFT + 2)) + 6); \
1364 r.B(13) = s->B((base << (SHIFT + 2)) + 6); \
1365 r.B(14) = d->B((base << (SHIFT + 2)) + 7); \
1366 r.B(15) = s->B((base << (SHIFT + 2)) + 7); \
1367) \
1368 *d = r; \
1369} \
1370 \
1371void OPPROTO glue(op_punpck ## base_name ## wd, SUFFIX) (void) \
1372{ \
1373 Reg r, *d, *s; \
1374 d = (Reg *)((char *)env + PARAM1); \
1375 s = (Reg *)((char *)env + PARAM2); \
1376 \
1377 r.W(0) = d->W((base << (SHIFT + 1)) + 0); \
1378 r.W(1) = s->W((base << (SHIFT + 1)) + 0); \
1379 r.W(2) = d->W((base << (SHIFT + 1)) + 1); \
1380 r.W(3) = s->W((base << (SHIFT + 1)) + 1); \
1381XMM_ONLY( \
1382 r.W(4) = d->W((base << (SHIFT + 1)) + 2); \
1383 r.W(5) = s->W((base << (SHIFT + 1)) + 2); \
1384 r.W(6) = d->W((base << (SHIFT + 1)) + 3); \
1385 r.W(7) = s->W((base << (SHIFT + 1)) + 3); \
1386) \
1387 *d = r; \
1388} \
1389 \
1390void OPPROTO glue(op_punpck ## base_name ## dq, SUFFIX) (void) \
1391{ \
1392 Reg r, *d, *s; \
1393 d = (Reg *)((char *)env + PARAM1); \
1394 s = (Reg *)((char *)env + PARAM2); \
1395 \
1396 r.L(0) = d->L((base << SHIFT) + 0); \
1397 r.L(1) = s->L((base << SHIFT) + 0); \
1398XMM_ONLY( \
1399 r.L(2) = d->L((base << SHIFT) + 1); \
1400 r.L(3) = s->L((base << SHIFT) + 1); \
1401) \
1402 *d = r; \
1403} \
1404 \
1405XMM_ONLY( \
1406void OPPROTO glue(op_punpck ## base_name ## qdq, SUFFIX) (void) \
1407{ \
1408 Reg r, *d, *s; \
1409 d = (Reg *)((char *)env + PARAM1); \
1410 s = (Reg *)((char *)env + PARAM2); \
1411 \
1412 r.Q(0) = d->Q(base); \
1413 r.Q(1) = s->Q(base); \
1414 *d = r; \
1415} \
1416)
1417
1418UNPCK_OP(l, 0)
1419UNPCK_OP(h, 1)
1420
1421#undef SHIFT
1422#undef XMM_ONLY
1423#undef Reg
1424#undef B
1425#undef W
1426#undef L
1427#undef Q
1428#undef SUFFIX
This page took 0.178325 seconds and 4 git commands to generate.