VirtualBox

source: vbox/trunk/src/recompiler/target-i386/ops_sse.h@ 4672

Last change on this file since 4672 was 3727, checked in by vboxsync, 17 years ago

Double underscore cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.5 KB
Line 
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 }
64 FORCE_RET();
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 }
118 FORCE_RET();
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 }
143 FORCE_RET();
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 }
189 FORCE_RET();
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 }
212 FORCE_RET();
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 }
235 FORCE_RET();
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 }
487 FORCE_RET();
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)
538 stb(A0 + i, d->B(i));
539 }
540 FORCE_RET();
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#ifdef TARGET_X86_64
562void OPPROTO glue(op_movq_mm_T0, SUFFIX) (void)
563{
564 Reg *d;
565 d = (Reg *)((char *)env + PARAM1);
566 d->Q(0) = T0;
567#if SHIFT == 1
568 d->Q(1) = 0;
569#endif
570}
571
572void OPPROTO glue(op_movq_T0_mm, SUFFIX) (void)
573{
574 Reg *s;
575 s = (Reg *)((char *)env + PARAM1);
576 T0 = s->Q(0);
577}
578#endif
579
580#if SHIFT == 0
581void OPPROTO glue(op_pshufw, SUFFIX) (void)
582{
583#if __GCC__ == 3 || defined(RT_ARCH_AMD64) /* VBOX hack in #else */
584 Reg r, *d, *s;
585 int order;
586 d = (Reg *)((char *)env + PARAM1);
587 s = (Reg *)((char *)env + PARAM2);
588 order = PARAM3;
589 r.W(0) = s->W(order & 3);
590 r.W(1) = s->W((order >> 2) & 3);
591 r.W(2) = s->W((order >> 4) & 3);
592 r.W(3) = s->W((order >> 6) & 3);
593 *d = r;
594#else
595 Reg *s;
596 int order;
597 uint32_t l0, l1;
598 s = (Reg *)((char *)env + PARAM2);
599 order = PARAM3;
600 l0 = s->W(order & 3);
601 l0 |= (uint32_t)s->W((order >> 2) & 3) << 16;
602 l1 = s->W((order >> 4) & 3);
603 l1 |= (uint32_t)s->W((order >> 6) & 3) << 16;
604
605 s = (Reg *)((char *)env + PARAM1);
606 s->_l[0] = l0;
607 s->_l[1] = l1;
608#endif
609}
610#else
611void OPPROTO op_shufps(void)
612{
613 Reg r, *d, *s;
614 int order;
615 d = (Reg *)((char *)env + PARAM1);
616 s = (Reg *)((char *)env + PARAM2);
617 order = PARAM3;
618 r.L(0) = d->L(order & 3);
619 r.L(1) = d->L((order >> 2) & 3);
620 r.L(2) = s->L((order >> 4) & 3);
621 r.L(3) = s->L((order >> 6) & 3);
622 *d = r;
623}
624
625void OPPROTO op_shufpd(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.Q(0) = d->Q(order & 1);
633 r.Q(1) = s->Q((order >> 1) & 1);
634 *d = r;
635}
636
637void OPPROTO glue(op_pshufd, SUFFIX) (void)
638{
639 Reg r, *d, *s;
640 int order;
641 d = (Reg *)((char *)env + PARAM1);
642 s = (Reg *)((char *)env + PARAM2);
643 order = PARAM3;
644 r.L(0) = s->L(order & 3);
645 r.L(1) = s->L((order >> 2) & 3);
646 r.L(2) = s->L((order >> 4) & 3);
647 r.L(3) = s->L((order >> 6) & 3);
648 *d = r;
649}
650
651void OPPROTO glue(op_pshuflw, SUFFIX) (void)
652{
653 Reg r, *d, *s;
654 int order;
655 d = (Reg *)((char *)env + PARAM1);
656 s = (Reg *)((char *)env + PARAM2);
657 order = PARAM3;
658 r.W(0) = s->W(order & 3);
659 r.W(1) = s->W((order >> 2) & 3);
660 r.W(2) = s->W((order >> 4) & 3);
661 r.W(3) = s->W((order >> 6) & 3);
662 r.Q(1) = s->Q(1);
663 *d = r;
664}
665
666void OPPROTO glue(op_pshufhw, SUFFIX) (void)
667{
668 Reg r, *d, *s;
669 int order;
670 d = (Reg *)((char *)env + PARAM1);
671 s = (Reg *)((char *)env + PARAM2);
672 order = PARAM3;
673 r.Q(0) = s->Q(0);
674 r.W(4) = s->W(4 + (order & 3));
675 r.W(5) = s->W(4 + ((order >> 2) & 3));
676 r.W(6) = s->W(4 + ((order >> 4) & 3));
677 r.W(7) = s->W(4 + ((order >> 6) & 3));
678 *d = r;
679}
680#endif
681
682#if SHIFT == 1
683/* FPU ops */
684/* XXX: not accurate */
685
686#define SSE_OP_S(name, F)\
687void OPPROTO op_ ## name ## ps (void)\
688{\
689 Reg *d, *s;\
690 d = (Reg *)((char *)env + PARAM1);\
691 s = (Reg *)((char *)env + PARAM2);\
692 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
693 d->XMM_S(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
694 d->XMM_S(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
695 d->XMM_S(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
696}\
697\
698void OPPROTO op_ ## name ## ss (void)\
699{\
700 Reg *d, *s;\
701 d = (Reg *)((char *)env + PARAM1);\
702 s = (Reg *)((char *)env + PARAM2);\
703 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
704}\
705void OPPROTO op_ ## name ## pd (void)\
706{\
707 Reg *d, *s;\
708 d = (Reg *)((char *)env + PARAM1);\
709 s = (Reg *)((char *)env + PARAM2);\
710 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
711 d->XMM_D(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
712}\
713\
714void OPPROTO op_ ## name ## sd (void)\
715{\
716 Reg *d, *s;\
717 d = (Reg *)((char *)env + PARAM1);\
718 s = (Reg *)((char *)env + PARAM2);\
719 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
720}
721
722#define FPU_ADD(size, a, b) float ## size ## _add(a, b, &env->sse_status)
723#define FPU_SUB(size, a, b) float ## size ## _sub(a, b, &env->sse_status)
724#define FPU_MUL(size, a, b) float ## size ## _mul(a, b, &env->sse_status)
725#define FPU_DIV(size, a, b) float ## size ## _div(a, b, &env->sse_status)
726#define FPU_MIN(size, a, b) (a) < (b) ? (a) : (b)
727#define FPU_MAX(size, a, b) (a) > (b) ? (a) : (b)
728#define FPU_SQRT(size, a, b) float ## size ## _sqrt(b, &env->sse_status)
729
730SSE_OP_S(add, FPU_ADD)
731SSE_OP_S(sub, FPU_SUB)
732SSE_OP_S(mul, FPU_MUL)
733SSE_OP_S(div, FPU_DIV)
734SSE_OP_S(min, FPU_MIN)
735SSE_OP_S(max, FPU_MAX)
736SSE_OP_S(sqrt, FPU_SQRT)
737
738
739/* float to float conversions */
740void OPPROTO op_cvtps2pd(void)
741{
742 float32 s0, s1;
743 Reg *d, *s;
744 d = (Reg *)((char *)env + PARAM1);
745 s = (Reg *)((char *)env + PARAM2);
746 s0 = s->XMM_S(0);
747 s1 = s->XMM_S(1);
748 d->XMM_D(0) = float32_to_float64(s0, &env->sse_status);
749 d->XMM_D(1) = float32_to_float64(s1, &env->sse_status);
750}
751
752void OPPROTO op_cvtpd2ps(void)
753{
754 Reg *d, *s;
755 d = (Reg *)((char *)env + PARAM1);
756 s = (Reg *)((char *)env + PARAM2);
757 d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
758 d->XMM_S(1) = float64_to_float32(s->XMM_D(1), &env->sse_status);
759 d->Q(1) = 0;
760}
761
762void OPPROTO op_cvtss2sd(void)
763{
764 Reg *d, *s;
765 d = (Reg *)((char *)env + PARAM1);
766 s = (Reg *)((char *)env + PARAM2);
767 d->XMM_D(0) = float32_to_float64(s->XMM_S(0), &env->sse_status);
768}
769
770void OPPROTO op_cvtsd2ss(void)
771{
772 Reg *d, *s;
773 d = (Reg *)((char *)env + PARAM1);
774 s = (Reg *)((char *)env + PARAM2);
775 d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
776}
777
778/* integer to float */
779void OPPROTO op_cvtdq2ps(void)
780{
781 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
782 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
783 d->XMM_S(0) = int32_to_float32(s->XMM_L(0), &env->sse_status);
784 d->XMM_S(1) = int32_to_float32(s->XMM_L(1), &env->sse_status);
785 d->XMM_S(2) = int32_to_float32(s->XMM_L(2), &env->sse_status);
786 d->XMM_S(3) = int32_to_float32(s->XMM_L(3), &env->sse_status);
787}
788
789void OPPROTO op_cvtdq2pd(void)
790{
791 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
792 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
793 int32_t l0, l1;
794 l0 = (int32_t)s->XMM_L(0);
795 l1 = (int32_t)s->XMM_L(1);
796 d->XMM_D(0) = int32_to_float64(l0, &env->sse_status);
797 d->XMM_D(1) = int32_to_float64(l1, &env->sse_status);
798}
799
800void OPPROTO op_cvtpi2ps(void)
801{
802 XMMReg *d = (Reg *)((char *)env + PARAM1);
803 MMXReg *s = (MMXReg *)((char *)env + PARAM2);
804 d->XMM_S(0) = int32_to_float32(s->MMX_L(0), &env->sse_status);
805 d->XMM_S(1) = int32_to_float32(s->MMX_L(1), &env->sse_status);
806}
807
808void OPPROTO op_cvtpi2pd(void)
809{
810 XMMReg *d = (Reg *)((char *)env + PARAM1);
811 MMXReg *s = (MMXReg *)((char *)env + PARAM2);
812 d->XMM_D(0) = int32_to_float64(s->MMX_L(0), &env->sse_status);
813 d->XMM_D(1) = int32_to_float64(s->MMX_L(1), &env->sse_status);
814}
815
816void OPPROTO op_cvtsi2ss(void)
817{
818 XMMReg *d = (Reg *)((char *)env + PARAM1);
819 d->XMM_S(0) = int32_to_float32(T0, &env->sse_status);
820}
821
822void OPPROTO op_cvtsi2sd(void)
823{
824 XMMReg *d = (Reg *)((char *)env + PARAM1);
825 d->XMM_D(0) = int32_to_float64(T0, &env->sse_status);
826}
827
828#ifdef TARGET_X86_64
829void OPPROTO op_cvtsq2ss(void)
830{
831 XMMReg *d = (Reg *)((char *)env + PARAM1);
832 d->XMM_S(0) = int64_to_float32(T0, &env->sse_status);
833}
834
835void OPPROTO op_cvtsq2sd(void)
836{
837 XMMReg *d = (Reg *)((char *)env + PARAM1);
838 d->XMM_D(0) = int64_to_float64(T0, &env->sse_status);
839}
840#endif
841
842/* float to integer */
843void OPPROTO op_cvtps2dq(void)
844{
845 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
846 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
847 d->XMM_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
848 d->XMM_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
849 d->XMM_L(2) = float32_to_int32(s->XMM_S(2), &env->sse_status);
850 d->XMM_L(3) = float32_to_int32(s->XMM_S(3), &env->sse_status);
851}
852
853void OPPROTO op_cvtpd2dq(void)
854{
855 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
856 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
857 d->XMM_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
858 d->XMM_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
859 d->XMM_Q(1) = 0;
860}
861
862void OPPROTO op_cvtps2pi(void)
863{
864 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
865 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
866 d->MMX_L(0) = float32_to_int32(s->XMM_S(0), &env->sse_status);
867 d->MMX_L(1) = float32_to_int32(s->XMM_S(1), &env->sse_status);
868}
869
870void OPPROTO op_cvtpd2pi(void)
871{
872 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
873 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
874 d->MMX_L(0) = float64_to_int32(s->XMM_D(0), &env->sse_status);
875 d->MMX_L(1) = float64_to_int32(s->XMM_D(1), &env->sse_status);
876}
877
878void OPPROTO op_cvtss2si(void)
879{
880 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
881 T0 = float32_to_int32(s->XMM_S(0), &env->sse_status);
882}
883
884void OPPROTO op_cvtsd2si(void)
885{
886 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
887 T0 = float64_to_int32(s->XMM_D(0), &env->sse_status);
888}
889
890#ifdef TARGET_X86_64
891void OPPROTO op_cvtss2sq(void)
892{
893 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
894 T0 = float32_to_int64(s->XMM_S(0), &env->sse_status);
895}
896
897void OPPROTO op_cvtsd2sq(void)
898{
899 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
900 T0 = float64_to_int64(s->XMM_D(0), &env->sse_status);
901}
902#endif
903
904/* float to integer truncated */
905void OPPROTO op_cvttps2dq(void)
906{
907 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
908 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
909 d->XMM_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
910 d->XMM_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
911 d->XMM_L(2) = float32_to_int32_round_to_zero(s->XMM_S(2), &env->sse_status);
912 d->XMM_L(3) = float32_to_int32_round_to_zero(s->XMM_S(3), &env->sse_status);
913}
914
915void OPPROTO op_cvttpd2dq(void)
916{
917 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
918 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
919 d->XMM_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
920 d->XMM_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
921 d->XMM_Q(1) = 0;
922}
923
924void OPPROTO op_cvttps2pi(void)
925{
926 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
927 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
928 d->MMX_L(0) = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
929 d->MMX_L(1) = float32_to_int32_round_to_zero(s->XMM_S(1), &env->sse_status);
930}
931
932void OPPROTO op_cvttpd2pi(void)
933{
934 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
935 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
936 d->MMX_L(0) = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
937 d->MMX_L(1) = float64_to_int32_round_to_zero(s->XMM_D(1), &env->sse_status);
938}
939
940void OPPROTO op_cvttss2si(void)
941{
942 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
943 T0 = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
944}
945
946void OPPROTO op_cvttsd2si(void)
947{
948 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
949 T0 = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
950}
951
952#ifdef TARGET_X86_64
953void OPPROTO op_cvttss2sq(void)
954{
955 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
956 T0 = float32_to_int64_round_to_zero(s->XMM_S(0), &env->sse_status);
957}
958
959void OPPROTO op_cvttsd2sq(void)
960{
961 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
962 T0 = float64_to_int64_round_to_zero(s->XMM_D(0), &env->sse_status);
963}
964#endif
965
966void OPPROTO op_rsqrtps(void)
967{
968 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
969 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
970 d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
971 d->XMM_S(1) = approx_rsqrt(s->XMM_S(1));
972 d->XMM_S(2) = approx_rsqrt(s->XMM_S(2));
973 d->XMM_S(3) = approx_rsqrt(s->XMM_S(3));
974}
975
976void OPPROTO op_rsqrtss(void)
977{
978 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
979 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
980 d->XMM_S(0) = approx_rsqrt(s->XMM_S(0));
981}
982
983void OPPROTO op_rcpps(void)
984{
985 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
986 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
987 d->XMM_S(0) = approx_rcp(s->XMM_S(0));
988 d->XMM_S(1) = approx_rcp(s->XMM_S(1));
989 d->XMM_S(2) = approx_rcp(s->XMM_S(2));
990 d->XMM_S(3) = approx_rcp(s->XMM_S(3));
991}
992
993void OPPROTO op_rcpss(void)
994{
995 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
996 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
997 d->XMM_S(0) = approx_rcp(s->XMM_S(0));
998}
999
1000void OPPROTO op_haddps(void)
1001{
1002 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1003 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1004 XMMReg r;
1005 r.XMM_S(0) = d->XMM_S(0) + d->XMM_S(1);
1006 r.XMM_S(1) = d->XMM_S(2) + d->XMM_S(3);
1007 r.XMM_S(2) = s->XMM_S(0) + s->XMM_S(1);
1008 r.XMM_S(3) = s->XMM_S(2) + s->XMM_S(3);
1009 *d = r;
1010}
1011
1012void OPPROTO op_haddpd(void)
1013{
1014 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1015 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1016 XMMReg r;
1017 r.XMM_D(0) = d->XMM_D(0) + d->XMM_D(1);
1018 r.XMM_D(1) = s->XMM_D(0) + s->XMM_D(1);
1019 *d = r;
1020}
1021
1022void OPPROTO op_hsubps(void)
1023{
1024 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1025 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1026 XMMReg r;
1027 r.XMM_S(0) = d->XMM_S(0) - d->XMM_S(1);
1028 r.XMM_S(1) = d->XMM_S(2) - d->XMM_S(3);
1029 r.XMM_S(2) = s->XMM_S(0) - s->XMM_S(1);
1030 r.XMM_S(3) = s->XMM_S(2) - s->XMM_S(3);
1031 *d = r;
1032}
1033
1034void OPPROTO op_hsubpd(void)
1035{
1036 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1037 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1038 XMMReg r;
1039 r.XMM_D(0) = d->XMM_D(0) - d->XMM_D(1);
1040 r.XMM_D(1) = s->XMM_D(0) - s->XMM_D(1);
1041 *d = r;
1042}
1043
1044void OPPROTO op_addsubps(void)
1045{
1046 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1047 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1048 d->XMM_S(0) = d->XMM_S(0) - s->XMM_S(0);
1049 d->XMM_S(1) = d->XMM_S(1) + s->XMM_S(1);
1050 d->XMM_S(2) = d->XMM_S(2) - s->XMM_S(2);
1051 d->XMM_S(3) = d->XMM_S(3) + s->XMM_S(3);
1052}
1053
1054void OPPROTO op_addsubpd(void)
1055{
1056 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
1057 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
1058 d->XMM_D(0) = d->XMM_D(0) - s->XMM_D(0);
1059 d->XMM_D(1) = d->XMM_D(1) + s->XMM_D(1);
1060}
1061
1062/* XXX: unordered */
1063#define SSE_OP_CMP(name, F)\
1064void OPPROTO op_ ## name ## ps (void)\
1065{\
1066 Reg *d, *s;\
1067 d = (Reg *)((char *)env + PARAM1);\
1068 s = (Reg *)((char *)env + PARAM2);\
1069 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1070 d->XMM_L(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
1071 d->XMM_L(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
1072 d->XMM_L(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
1073}\
1074\
1075void OPPROTO op_ ## name ## ss (void)\
1076{\
1077 Reg *d, *s;\
1078 d = (Reg *)((char *)env + PARAM1);\
1079 s = (Reg *)((char *)env + PARAM2);\
1080 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1081}\
1082void OPPROTO op_ ## name ## pd (void)\
1083{\
1084 Reg *d, *s;\
1085 d = (Reg *)((char *)env + PARAM1);\
1086 s = (Reg *)((char *)env + PARAM2);\
1087 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1088 d->XMM_Q(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
1089}\
1090\
1091void OPPROTO op_ ## name ## sd (void)\
1092{\
1093 Reg *d, *s;\
1094 d = (Reg *)((char *)env + PARAM1);\
1095 s = (Reg *)((char *)env + PARAM2);\
1096 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1097}
1098
1099#define FPU_CMPEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? -1 : 0
1100#define FPU_CMPLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? -1 : 0
1101#define FPU_CMPLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? -1 : 0
1102#define FPU_CMPUNORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? - 1 : 0
1103#define FPU_CMPNEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? 0 : -1
1104#define FPU_CMPNLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? 0 : -1
1105#define FPU_CMPNLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? 0 : -1
1106#define FPU_CMPORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? 0 : -1
1107
1108SSE_OP_CMP(cmpeq, FPU_CMPEQ)
1109SSE_OP_CMP(cmplt, FPU_CMPLT)
1110SSE_OP_CMP(cmple, FPU_CMPLE)
1111SSE_OP_CMP(cmpunord, FPU_CMPUNORD)
1112SSE_OP_CMP(cmpneq, FPU_CMPNEQ)
1113SSE_OP_CMP(cmpnlt, FPU_CMPNLT)
1114SSE_OP_CMP(cmpnle, FPU_CMPNLE)
1115SSE_OP_CMP(cmpord, FPU_CMPORD)
1116
1117const int comis_eflags[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
1118
1119void OPPROTO op_ucomiss(void)
1120{
1121 int ret;
1122 float32 s0, s1;
1123 Reg *d, *s;
1124 d = (Reg *)((char *)env + PARAM1);
1125 s = (Reg *)((char *)env + PARAM2);
1126
1127 s0 = d->XMM_S(0);
1128 s1 = s->XMM_S(0);
1129 ret = float32_compare_quiet(s0, s1, &env->sse_status);
1130 CC_SRC = comis_eflags[ret + 1];
1131 FORCE_RET();
1132}
1133
1134void OPPROTO op_comiss(void)
1135{
1136 int ret;
1137 float32 s0, s1;
1138 Reg *d, *s;
1139 d = (Reg *)((char *)env + PARAM1);
1140 s = (Reg *)((char *)env + PARAM2);
1141
1142 s0 = d->XMM_S(0);
1143 s1 = s->XMM_S(0);
1144 ret = float32_compare(s0, s1, &env->sse_status);
1145 CC_SRC = comis_eflags[ret + 1];
1146 FORCE_RET();
1147}
1148
1149void OPPROTO op_ucomisd(void)
1150{
1151 int ret;
1152 float64 d0, d1;
1153 Reg *d, *s;
1154 d = (Reg *)((char *)env + PARAM1);
1155 s = (Reg *)((char *)env + PARAM2);
1156
1157 d0 = d->XMM_D(0);
1158 d1 = s->XMM_D(0);
1159 ret = float64_compare_quiet(d0, d1, &env->sse_status);
1160 CC_SRC = comis_eflags[ret + 1];
1161 FORCE_RET();
1162}
1163
1164void OPPROTO op_comisd(void)
1165{
1166 int ret;
1167 float64 d0, d1;
1168 Reg *d, *s;
1169 d = (Reg *)((char *)env + PARAM1);
1170 s = (Reg *)((char *)env + PARAM2);
1171
1172 d0 = d->XMM_D(0);
1173 d1 = s->XMM_D(0);
1174 ret = float64_compare(d0, d1, &env->sse_status);
1175 CC_SRC = comis_eflags[ret + 1];
1176 FORCE_RET();
1177}
1178
1179void OPPROTO op_movmskps(void)
1180{
1181 int b0, b1, b2, b3;
1182 Reg *s;
1183 s = (Reg *)((char *)env + PARAM1);
1184 b0 = s->XMM_L(0) >> 31;
1185 b1 = s->XMM_L(1) >> 31;
1186 b2 = s->XMM_L(2) >> 31;
1187 b3 = s->XMM_L(3) >> 31;
1188 T0 = b0 | (b1 << 1) | (b2 << 2) | (b3 << 3);
1189}
1190
1191void OPPROTO op_movmskpd(void)
1192{
1193 int b0, b1;
1194 Reg *s;
1195 s = (Reg *)((char *)env + PARAM1);
1196 b0 = s->XMM_L(1) >> 31;
1197 b1 = s->XMM_L(3) >> 31;
1198 T0 = b0 | (b1 << 1);
1199}
1200
1201#endif
1202
1203void OPPROTO glue(op_pmovmskb, SUFFIX)(void)
1204{
1205 Reg *s;
1206 s = (Reg *)((char *)env + PARAM1);
1207 T0 = 0;
1208 T0 |= (s->XMM_B(0) >> 7);
1209 T0 |= (s->XMM_B(1) >> 6) & 0x02;
1210 T0 |= (s->XMM_B(2) >> 5) & 0x04;
1211 T0 |= (s->XMM_B(3) >> 4) & 0x08;
1212 T0 |= (s->XMM_B(4) >> 3) & 0x10;
1213 T0 |= (s->XMM_B(5) >> 2) & 0x20;
1214 T0 |= (s->XMM_B(6) >> 1) & 0x40;
1215 T0 |= (s->XMM_B(7)) & 0x80;
1216#if SHIFT == 1
1217 T0 |= (s->XMM_B(8) << 1) & 0x0100;
1218 T0 |= (s->XMM_B(9) << 2) & 0x0200;
1219 T0 |= (s->XMM_B(10) << 3) & 0x0400;
1220 T0 |= (s->XMM_B(11) << 4) & 0x0800;
1221 T0 |= (s->XMM_B(12) << 5) & 0x1000;
1222 T0 |= (s->XMM_B(13) << 6) & 0x2000;
1223 T0 |= (s->XMM_B(14) << 7) & 0x4000;
1224 T0 |= (s->XMM_B(15) << 8) & 0x8000;
1225#endif
1226}
1227
1228void OPPROTO glue(op_pinsrw, SUFFIX) (void)
1229{
1230 Reg *d = (Reg *)((char *)env + PARAM1);
1231 int pos = PARAM2;
1232
1233 d->W(pos) = T0;
1234}
1235
1236void OPPROTO glue(op_pextrw, SUFFIX) (void)
1237{
1238 Reg *s = (Reg *)((char *)env + PARAM1);
1239 int pos = PARAM2;
1240
1241 T0 = s->W(pos);
1242}
1243
1244void OPPROTO glue(op_packsswb, SUFFIX) (void)
1245{
1246 Reg r, *d, *s;
1247 d = (Reg *)((char *)env + PARAM1);
1248 s = (Reg *)((char *)env + PARAM2);
1249
1250 r.B(0) = satsb((int16_t)d->W(0));
1251 r.B(1) = satsb((int16_t)d->W(1));
1252 r.B(2) = satsb((int16_t)d->W(2));
1253 r.B(3) = satsb((int16_t)d->W(3));
1254#if SHIFT == 1
1255 r.B(4) = satsb((int16_t)d->W(4));
1256 r.B(5) = satsb((int16_t)d->W(5));
1257 r.B(6) = satsb((int16_t)d->W(6));
1258 r.B(7) = satsb((int16_t)d->W(7));
1259#endif
1260 r.B((4 << SHIFT) + 0) = satsb((int16_t)s->W(0));
1261 r.B((4 << SHIFT) + 1) = satsb((int16_t)s->W(1));
1262 r.B((4 << SHIFT) + 2) = satsb((int16_t)s->W(2));
1263 r.B((4 << SHIFT) + 3) = satsb((int16_t)s->W(3));
1264#if SHIFT == 1
1265 r.B(12) = satsb((int16_t)s->W(4));
1266 r.B(13) = satsb((int16_t)s->W(5));
1267 r.B(14) = satsb((int16_t)s->W(6));
1268 r.B(15) = satsb((int16_t)s->W(7));
1269#endif
1270 *d = r;
1271}
1272
1273void OPPROTO glue(op_packuswb, SUFFIX) (void)
1274{
1275 Reg r, *d, *s;
1276 d = (Reg *)((char *)env + PARAM1);
1277 s = (Reg *)((char *)env + PARAM2);
1278
1279 r.B(0) = satub((int16_t)d->W(0));
1280 r.B(1) = satub((int16_t)d->W(1));
1281 r.B(2) = satub((int16_t)d->W(2));
1282 r.B(3) = satub((int16_t)d->W(3));
1283#if SHIFT == 1
1284 r.B(4) = satub((int16_t)d->W(4));
1285 r.B(5) = satub((int16_t)d->W(5));
1286 r.B(6) = satub((int16_t)d->W(6));
1287 r.B(7) = satub((int16_t)d->W(7));
1288#endif
1289 r.B((4 << SHIFT) + 0) = satub((int16_t)s->W(0));
1290 r.B((4 << SHIFT) + 1) = satub((int16_t)s->W(1));
1291 r.B((4 << SHIFT) + 2) = satub((int16_t)s->W(2));
1292 r.B((4 << SHIFT) + 3) = satub((int16_t)s->W(3));
1293#if SHIFT == 1
1294 r.B(12) = satub((int16_t)s->W(4));
1295 r.B(13) = satub((int16_t)s->W(5));
1296 r.B(14) = satub((int16_t)s->W(6));
1297 r.B(15) = satub((int16_t)s->W(7));
1298#endif
1299 *d = r;
1300}
1301
1302void OPPROTO glue(op_packssdw, SUFFIX) (void)
1303{
1304 Reg r, *d, *s;
1305 d = (Reg *)((char *)env + PARAM1);
1306 s = (Reg *)((char *)env + PARAM2);
1307
1308 r.W(0) = satsw(d->L(0));
1309 r.W(1) = satsw(d->L(1));
1310#if SHIFT == 1
1311 r.W(2) = satsw(d->L(2));
1312 r.W(3) = satsw(d->L(3));
1313#endif
1314 r.W((2 << SHIFT) + 0) = satsw(s->L(0));
1315 r.W((2 << SHIFT) + 1) = satsw(s->L(1));
1316#if SHIFT == 1
1317 r.W(6) = satsw(s->L(2));
1318 r.W(7) = satsw(s->L(3));
1319#endif
1320 *d = r;
1321}
1322
1323#define UNPCK_OP(base_name, base) \
1324 \
1325void OPPROTO glue(op_punpck ## base_name ## bw, SUFFIX) (void) \
1326{ \
1327 Reg r, *d, *s; \
1328 d = (Reg *)((char *)env + PARAM1); \
1329 s = (Reg *)((char *)env + PARAM2); \
1330 \
1331 r.B(0) = d->B((base << (SHIFT + 2)) + 0); \
1332 r.B(1) = s->B((base << (SHIFT + 2)) + 0); \
1333 r.B(2) = d->B((base << (SHIFT + 2)) + 1); \
1334 r.B(3) = s->B((base << (SHIFT + 2)) + 1); \
1335 r.B(4) = d->B((base << (SHIFT + 2)) + 2); \
1336 r.B(5) = s->B((base << (SHIFT + 2)) + 2); \
1337 r.B(6) = d->B((base << (SHIFT + 2)) + 3); \
1338 r.B(7) = s->B((base << (SHIFT + 2)) + 3); \
1339XMM_ONLY( \
1340 r.B(8) = d->B((base << (SHIFT + 2)) + 4); \
1341 r.B(9) = s->B((base << (SHIFT + 2)) + 4); \
1342 r.B(10) = d->B((base << (SHIFT + 2)) + 5); \
1343 r.B(11) = s->B((base << (SHIFT + 2)) + 5); \
1344 r.B(12) = d->B((base << (SHIFT + 2)) + 6); \
1345 r.B(13) = s->B((base << (SHIFT + 2)) + 6); \
1346 r.B(14) = d->B((base << (SHIFT + 2)) + 7); \
1347 r.B(15) = s->B((base << (SHIFT + 2)) + 7); \
1348) \
1349 *d = r; \
1350} \
1351 \
1352void OPPROTO glue(op_punpck ## base_name ## wd, SUFFIX) (void) \
1353{ \
1354 Reg r, *d, *s; \
1355 d = (Reg *)((char *)env + PARAM1); \
1356 s = (Reg *)((char *)env + PARAM2); \
1357 \
1358 r.W(0) = d->W((base << (SHIFT + 1)) + 0); \
1359 r.W(1) = s->W((base << (SHIFT + 1)) + 0); \
1360 r.W(2) = d->W((base << (SHIFT + 1)) + 1); \
1361 r.W(3) = s->W((base << (SHIFT + 1)) + 1); \
1362XMM_ONLY( \
1363 r.W(4) = d->W((base << (SHIFT + 1)) + 2); \
1364 r.W(5) = s->W((base << (SHIFT + 1)) + 2); \
1365 r.W(6) = d->W((base << (SHIFT + 1)) + 3); \
1366 r.W(7) = s->W((base << (SHIFT + 1)) + 3); \
1367) \
1368 *d = r; \
1369} \
1370 \
1371void OPPROTO glue(op_punpck ## base_name ## dq, SUFFIX) (void) \
1372{ \
1373 Reg r, *d, *s; \
1374 d = (Reg *)((char *)env + PARAM1); \
1375 s = (Reg *)((char *)env + PARAM2); \
1376 \
1377 r.L(0) = d->L((base << SHIFT) + 0); \
1378 r.L(1) = s->L((base << SHIFT) + 0); \
1379XMM_ONLY( \
1380 r.L(2) = d->L((base << SHIFT) + 1); \
1381 r.L(3) = s->L((base << SHIFT) + 1); \
1382) \
1383 *d = r; \
1384} \
1385 \
1386XMM_ONLY( \
1387void OPPROTO glue(op_punpck ## base_name ## qdq, SUFFIX) (void) \
1388{ \
1389 Reg r, *d, *s; \
1390 d = (Reg *)((char *)env + PARAM1); \
1391 s = (Reg *)((char *)env + PARAM2); \
1392 \
1393 r.Q(0) = d->Q(base); \
1394 r.Q(1) = s->Q(base); \
1395 *d = r; \
1396} \
1397)
1398
1399UNPCK_OP(l, 0)
1400UNPCK_OP(h, 1)
1401
1402#undef SHIFT
1403#undef XMM_ONLY
1404#undef Reg
1405#undef B
1406#undef W
1407#undef L
1408#undef Q
1409#undef SUFFIX
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette