VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.8 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#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
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
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;
597 r.Q(0) = d->Q(order & 1);
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);\
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));\
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);\
668 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
669}\
670void OPPROTO op_ ## name ## pd (void)\
671{\
672 Reg *d, *s;\
673 d = (Reg *)((char *)env + PARAM1);\
674 s = (Reg *)((char *)env + PARAM2);\
675 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
676 d->XMM_D(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
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);\
684 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
685}
686
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)
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{
707 float32 s0, s1;
708 Reg *d, *s;
709 d = (Reg *)((char *)env + PARAM1);
710 s = (Reg *)((char *)env + PARAM2);
711 s0 = s->XMM_S(0);
712 s1 = s->XMM_S(1);
713 d->XMM_D(0) = float32_to_float64(s0, &env->sse_status);
714 d->XMM_D(1) = float32_to_float64(s1, &env->sse_status);
715}
716
717void OPPROTO op_cvtpd2ps(void)
718{
719 Reg *d, *s;
720 d = (Reg *)((char *)env + PARAM1);
721 s = (Reg *)((char *)env + PARAM2);
722 d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
723 d->XMM_S(1) = float64_to_float32(s->XMM_D(1), &env->sse_status);
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);
732 d->XMM_D(0) = float32_to_float64(s->XMM_S(0), &env->sse_status);
733}
734
735void OPPROTO op_cvtsd2ss(void)
736{
737 Reg *d, *s;
738 d = (Reg *)((char *)env + PARAM1);
739 s = (Reg *)((char *)env + PARAM2);
740 d->XMM_S(0) = float64_to_float32(s->XMM_D(0), &env->sse_status);
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);
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);
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);
761 d->XMM_D(0) = int32_to_float64(l0, &env->sse_status);
762 d->XMM_D(1) = int32_to_float64(l1, &env->sse_status);
763}
764
765void OPPROTO op_cvtpi2ps(void)
766{
767 XMMReg *d = (Reg *)((char *)env + PARAM1);
768 MMXReg *s = (MMXReg *)((char *)env + PARAM2);
769 d->XMM_S(0) = int32_to_float32(s->MMX_L(0), &env->sse_status);
770 d->XMM_S(1) = int32_to_float32(s->MMX_L(1), &env->sse_status);
771}
772
773void OPPROTO op_cvtpi2pd(void)
774{
775 XMMReg *d = (Reg *)((char *)env + PARAM1);
776 MMXReg *s = (MMXReg *)((char *)env + PARAM2);
777 d->XMM_D(0) = int32_to_float64(s->MMX_L(0), &env->sse_status);
778 d->XMM_D(1) = int32_to_float64(s->MMX_L(1), &env->sse_status);
779}
780
781void OPPROTO op_cvtsi2ss(void)
782{
783 XMMReg *d = (Reg *)((char *)env + PARAM1);
784 d->XMM_S(0) = int32_to_float32(T0, &env->sse_status);
785}
786
787void OPPROTO op_cvtsi2sd(void)
788{
789 XMMReg *d = (Reg *)((char *)env + PARAM1);
790 d->XMM_D(0) = int32_to_float64(T0, &env->sse_status);
791}
792
793#ifdef TARGET_X86_64
794void OPPROTO op_cvtsq2ss(void)
795{
796 XMMReg *d = (Reg *)((char *)env + PARAM1);
797 d->XMM_S(0) = int64_to_float32(T0, &env->sse_status);
798}
799
800void OPPROTO op_cvtsq2sd(void)
801{
802 XMMReg *d = (Reg *)((char *)env + PARAM1);
803 d->XMM_D(0) = int64_to_float64(T0, &env->sse_status);
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);
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);
816}
817
818void OPPROTO op_cvtpd2dq(void)
819{
820 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
821 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
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);
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);
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);
833}
834
835void OPPROTO op_cvtpd2pi(void)
836{
837 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
838 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
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);
841}
842
843void OPPROTO op_cvtss2si(void)
844{
845 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
846 T0 = float32_to_int32(s->XMM_S(0), &env->sse_status);
847}
848
849void OPPROTO op_cvtsd2si(void)
850{
851 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
852 T0 = float64_to_int32(s->XMM_D(0), &env->sse_status);
853}
854
855#ifdef TARGET_X86_64
856void OPPROTO op_cvtss2sq(void)
857{
858 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
859 T0 = float32_to_int64(s->XMM_S(0), &env->sse_status);
860}
861
862void OPPROTO op_cvtsd2sq(void)
863{
864 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
865 T0 = float64_to_int64(s->XMM_D(0), &env->sse_status);
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);
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);
878}
879
880void OPPROTO op_cvttpd2dq(void)
881{
882 XMMReg *d = (XMMReg *)((char *)env + PARAM1);
883 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
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);
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);
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);
895}
896
897void OPPROTO op_cvttpd2pi(void)
898{
899 MMXReg *d = (MMXReg *)((char *)env + PARAM1);
900 XMMReg *s = (XMMReg *)((char *)env + PARAM2);
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);
903}
904
905void OPPROTO op_cvttss2si(void)
906{
907 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
908 T0 = float32_to_int32_round_to_zero(s->XMM_S(0), &env->sse_status);
909}
910
911void OPPROTO op_cvttsd2si(void)
912{
913 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
914 T0 = float64_to_int32_round_to_zero(s->XMM_D(0), &env->sse_status);
915}
916
917#ifdef TARGET_X86_64
918void OPPROTO op_cvttss2sq(void)
919{
920 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
921 T0 = float32_to_int64_round_to_zero(s->XMM_S(0), &env->sse_status);
922}
923
924void OPPROTO op_cvttsd2sq(void)
925{
926 XMMReg *s = (XMMReg *)((char *)env + PARAM1);
927 T0 = float64_to_int64_round_to_zero(s->XMM_D(0), &env->sse_status);
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);\
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));\
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);\
1045 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1046}\
1047void OPPROTO op_ ## name ## pd (void)\
1048{\
1049 Reg *d, *s;\
1050 d = (Reg *)((char *)env + PARAM1);\
1051 s = (Reg *)((char *)env + PARAM2);\
1052 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1053 d->XMM_Q(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
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);\
1061 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1062}
1063
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
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
1082const int comis_eflags[4] = {CC_C, CC_Z, 0, CC_Z | CC_P | CC_C};
1083
1084void OPPROTO op_ucomiss(void)
1085{
1086 int ret;
1087 float32 s0, s1;
1088 Reg *d, *s;
1089 d = (Reg *)((char *)env + PARAM1);
1090 s = (Reg *)((char *)env + PARAM2);
1091
1092 s0 = d->XMM_S(0);
1093 s1 = s->XMM_S(0);
1094 ret = float32_compare_quiet(s0, s1, &env->sse_status);
1095 CC_SRC = comis_eflags[ret + 1];
1096 FORCE_RET();
1097}
1098
1099void OPPROTO op_comiss(void)
1100{
1101 int ret;
1102 float32 s0, s1;
1103 Reg *d, *s;
1104 d = (Reg *)((char *)env + PARAM1);
1105 s = (Reg *)((char *)env + PARAM2);
1106
1107 s0 = d->XMM_S(0);
1108 s1 = s->XMM_S(0);
1109 ret = float32_compare(s0, s1, &env->sse_status);
1110 CC_SRC = comis_eflags[ret + 1];
1111 FORCE_RET();
1112}
1113
1114void OPPROTO op_ucomisd(void)
1115{
1116 int ret;
1117 float64 d0, d1;
1118 Reg *d, *s;
1119 d = (Reg *)((char *)env + PARAM1);
1120 s = (Reg *)((char *)env + PARAM2);
1121
1122 d0 = d->XMM_D(0);
1123 d1 = s->XMM_D(0);
1124 ret = float64_compare_quiet(d0, d1, &env->sse_status);
1125 CC_SRC = comis_eflags[ret + 1];
1126 FORCE_RET();
1127}
1128
1129void OPPROTO op_comisd(void)
1130{
1131 int ret;
1132 float64 d0, d1;
1133 Reg *d, *s;
1134 d = (Reg *)((char *)env + PARAM1);
1135 s = (Reg *)((char *)env + PARAM2);
1136
1137 d0 = d->XMM_D(0);
1138 d1 = s->XMM_D(0);
1139 ret = float64_compare(d0, d1, &env->sse_status);
1140 CC_SRC = comis_eflags[ret + 1];
1141 FORCE_RET();
1142}
1143
1144void OPPROTO op_movmskps(void)
1145{
1146 int b0, b1, b2, b3;
1147 Reg *s;
1148 s = (Reg *)((char *)env + PARAM1);
1149 b0 = s->XMM_L(0) >> 31;
1150 b1 = s->XMM_L(1) >> 31;
1151 b2 = s->XMM_L(2) >> 31;
1152 b3 = s->XMM_L(3) >> 31;
1153 T0 = b0 | (b1 << 1) | (b2 << 2) | (b3 << 3);
1154}
1155
1156void OPPROTO op_movmskpd(void)
1157{
1158 int b0, b1;
1159 Reg *s;
1160 s = (Reg *)((char *)env + PARAM1);
1161 b0 = s->XMM_L(1) >> 31;
1162 b1 = s->XMM_L(3) >> 31;
1163 T0 = b0 | (b1 << 1);
1164}
1165
1166#endif
1167
1168void OPPROTO glue(op_pmovmskb, SUFFIX)(void)
1169{
1170 Reg *s;
1171 s = (Reg *)((char *)env + PARAM1);
1172 T0 = 0;
1173 T0 |= (s->XMM_B(0) >> 7);
1174 T0 |= (s->XMM_B(1) >> 6) & 0x02;
1175 T0 |= (s->XMM_B(2) >> 5) & 0x04;
1176 T0 |= (s->XMM_B(3) >> 4) & 0x08;
1177 T0 |= (s->XMM_B(4) >> 3) & 0x10;
1178 T0 |= (s->XMM_B(5) >> 2) & 0x20;
1179 T0 |= (s->XMM_B(6) >> 1) & 0x40;
1180 T0 |= (s->XMM_B(7)) & 0x80;
1181#if SHIFT == 1
1182 T0 |= (s->XMM_B(8) << 1) & 0x0100;
1183 T0 |= (s->XMM_B(9) << 2) & 0x0200;
1184 T0 |= (s->XMM_B(10) << 3) & 0x0400;
1185 T0 |= (s->XMM_B(11) << 4) & 0x0800;
1186 T0 |= (s->XMM_B(12) << 5) & 0x1000;
1187 T0 |= (s->XMM_B(13) << 6) & 0x2000;
1188 T0 |= (s->XMM_B(14) << 7) & 0x4000;
1189 T0 |= (s->XMM_B(15) << 8) & 0x8000;
1190#endif
1191}
1192
1193void OPPROTO glue(op_pinsrw, SUFFIX) (void)
1194{
1195 Reg *d = (Reg *)((char *)env + PARAM1);
1196 int pos = PARAM2;
1197
1198 d->W(pos) = T0;
1199}
1200
1201void OPPROTO glue(op_pextrw, SUFFIX) (void)
1202{
1203 Reg *s = (Reg *)((char *)env + PARAM1);
1204 int pos = PARAM2;
1205
1206 T0 = s->W(pos);
1207}
1208
1209void OPPROTO glue(op_packsswb, SUFFIX) (void)
1210{
1211 Reg r, *d, *s;
1212 d = (Reg *)((char *)env + PARAM1);
1213 s = (Reg *)((char *)env + PARAM2);
1214
1215 r.B(0) = satsb((int16_t)d->W(0));
1216 r.B(1) = satsb((int16_t)d->W(1));
1217 r.B(2) = satsb((int16_t)d->W(2));
1218 r.B(3) = satsb((int16_t)d->W(3));
1219#if SHIFT == 1
1220 r.B(4) = satsb((int16_t)d->W(4));
1221 r.B(5) = satsb((int16_t)d->W(5));
1222 r.B(6) = satsb((int16_t)d->W(6));
1223 r.B(7) = satsb((int16_t)d->W(7));
1224#endif
1225 r.B((4 << SHIFT) + 0) = satsb((int16_t)s->W(0));
1226 r.B((4 << SHIFT) + 1) = satsb((int16_t)s->W(1));
1227 r.B((4 << SHIFT) + 2) = satsb((int16_t)s->W(2));
1228 r.B((4 << SHIFT) + 3) = satsb((int16_t)s->W(3));
1229#if SHIFT == 1
1230 r.B(12) = satsb((int16_t)s->W(4));
1231 r.B(13) = satsb((int16_t)s->W(5));
1232 r.B(14) = satsb((int16_t)s->W(6));
1233 r.B(15) = satsb((int16_t)s->W(7));
1234#endif
1235 *d = r;
1236}
1237
1238void OPPROTO glue(op_packuswb, SUFFIX) (void)
1239{
1240 Reg r, *d, *s;
1241 d = (Reg *)((char *)env + PARAM1);
1242 s = (Reg *)((char *)env + PARAM2);
1243
1244 r.B(0) = satub((int16_t)d->W(0));
1245 r.B(1) = satub((int16_t)d->W(1));
1246 r.B(2) = satub((int16_t)d->W(2));
1247 r.B(3) = satub((int16_t)d->W(3));
1248#if SHIFT == 1
1249 r.B(4) = satub((int16_t)d->W(4));
1250 r.B(5) = satub((int16_t)d->W(5));
1251 r.B(6) = satub((int16_t)d->W(6));
1252 r.B(7) = satub((int16_t)d->W(7));
1253#endif
1254 r.B((4 << SHIFT) + 0) = satub((int16_t)s->W(0));
1255 r.B((4 << SHIFT) + 1) = satub((int16_t)s->W(1));
1256 r.B((4 << SHIFT) + 2) = satub((int16_t)s->W(2));
1257 r.B((4 << SHIFT) + 3) = satub((int16_t)s->W(3));
1258#if SHIFT == 1
1259 r.B(12) = satub((int16_t)s->W(4));
1260 r.B(13) = satub((int16_t)s->W(5));
1261 r.B(14) = satub((int16_t)s->W(6));
1262 r.B(15) = satub((int16_t)s->W(7));
1263#endif
1264 *d = r;
1265}
1266
1267void OPPROTO glue(op_packssdw, SUFFIX) (void)
1268{
1269 Reg r, *d, *s;
1270 d = (Reg *)((char *)env + PARAM1);
1271 s = (Reg *)((char *)env + PARAM2);
1272
1273 r.W(0) = satsw(d->L(0));
1274 r.W(1) = satsw(d->L(1));
1275#if SHIFT == 1
1276 r.W(2) = satsw(d->L(2));
1277 r.W(3) = satsw(d->L(3));
1278#endif
1279 r.W((2 << SHIFT) + 0) = satsw(s->L(0));
1280 r.W((2 << SHIFT) + 1) = satsw(s->L(1));
1281#if SHIFT == 1
1282 r.W(6) = satsw(s->L(2));
1283 r.W(7) = satsw(s->L(3));
1284#endif
1285 *d = r;
1286}
1287
1288#define UNPCK_OP(base_name, base) \
1289 \
1290void OPPROTO glue(op_punpck ## base_name ## bw, SUFFIX) (void) \
1291{ \
1292 Reg r, *d, *s; \
1293 d = (Reg *)((char *)env + PARAM1); \
1294 s = (Reg *)((char *)env + PARAM2); \
1295 \
1296 r.B(0) = d->B((base << (SHIFT + 2)) + 0); \
1297 r.B(1) = s->B((base << (SHIFT + 2)) + 0); \
1298 r.B(2) = d->B((base << (SHIFT + 2)) + 1); \
1299 r.B(3) = s->B((base << (SHIFT + 2)) + 1); \
1300 r.B(4) = d->B((base << (SHIFT + 2)) + 2); \
1301 r.B(5) = s->B((base << (SHIFT + 2)) + 2); \
1302 r.B(6) = d->B((base << (SHIFT + 2)) + 3); \
1303 r.B(7) = s->B((base << (SHIFT + 2)) + 3); \
1304XMM_ONLY( \
1305 r.B(8) = d->B((base << (SHIFT + 2)) + 4); \
1306 r.B(9) = s->B((base << (SHIFT + 2)) + 4); \
1307 r.B(10) = d->B((base << (SHIFT + 2)) + 5); \
1308 r.B(11) = s->B((base << (SHIFT + 2)) + 5); \
1309 r.B(12) = d->B((base << (SHIFT + 2)) + 6); \
1310 r.B(13) = s->B((base << (SHIFT + 2)) + 6); \
1311 r.B(14) = d->B((base << (SHIFT + 2)) + 7); \
1312 r.B(15) = s->B((base << (SHIFT + 2)) + 7); \
1313) \
1314 *d = r; \
1315} \
1316 \
1317void OPPROTO glue(op_punpck ## base_name ## wd, SUFFIX) (void) \
1318{ \
1319 Reg r, *d, *s; \
1320 d = (Reg *)((char *)env + PARAM1); \
1321 s = (Reg *)((char *)env + PARAM2); \
1322 \
1323 r.W(0) = d->W((base << (SHIFT + 1)) + 0); \
1324 r.W(1) = s->W((base << (SHIFT + 1)) + 0); \
1325 r.W(2) = d->W((base << (SHIFT + 1)) + 1); \
1326 r.W(3) = s->W((base << (SHIFT + 1)) + 1); \
1327XMM_ONLY( \
1328 r.W(4) = d->W((base << (SHIFT + 1)) + 2); \
1329 r.W(5) = s->W((base << (SHIFT + 1)) + 2); \
1330 r.W(6) = d->W((base << (SHIFT + 1)) + 3); \
1331 r.W(7) = s->W((base << (SHIFT + 1)) + 3); \
1332) \
1333 *d = r; \
1334} \
1335 \
1336void OPPROTO glue(op_punpck ## base_name ## dq, SUFFIX) (void) \
1337{ \
1338 Reg r, *d, *s; \
1339 d = (Reg *)((char *)env + PARAM1); \
1340 s = (Reg *)((char *)env + PARAM2); \
1341 \
1342 r.L(0) = d->L((base << SHIFT) + 0); \
1343 r.L(1) = s->L((base << SHIFT) + 0); \
1344XMM_ONLY( \
1345 r.L(2) = d->L((base << SHIFT) + 1); \
1346 r.L(3) = s->L((base << SHIFT) + 1); \
1347) \
1348 *d = r; \
1349} \
1350 \
1351XMM_ONLY( \
1352void OPPROTO glue(op_punpck ## base_name ## qdq, SUFFIX) (void) \
1353{ \
1354 Reg r, *d, *s; \
1355 d = (Reg *)((char *)env + PARAM1); \
1356 s = (Reg *)((char *)env + PARAM2); \
1357 \
1358 r.Q(0) = d->Q(base); \
1359 r.Q(1) = s->Q(base); \
1360 *d = r; \
1361} \
1362)
1363
1364UNPCK_OP(l, 0)
1365UNPCK_OP(h, 1)
1366
1367#undef SHIFT
1368#undef XMM_ONLY
1369#undef Reg
1370#undef B
1371#undef W
1372#undef L
1373#undef Q
1374#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