2 * MMX/SSE/SSE2/PNI support
4 * Copyright (c) 2005 Fabrice Bellard
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.
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.
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
22 #define XMM_ONLY(x...)
30 #define XMM_ONLY(x...) x
38 void OPPROTO
glue(op_psrlw
, SUFFIX
)(void)
43 d
= (Reg
*)((char *)env
+ PARAM1
);
44 s
= (Reg
*)((char *)env
+ PARAM2
);
67 void OPPROTO
glue(op_psraw
, SUFFIX
)(void)
72 d
= (Reg
*)((char *)env
+ PARAM1
);
73 s
= (Reg
*)((char *)env
+ PARAM2
);
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
;
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
;
92 void OPPROTO
glue(op_psllw
, SUFFIX
)(void)
97 d
= (Reg
*)((char *)env
+ PARAM1
);
98 s
= (Reg
*)((char *)env
+ PARAM2
);
121 void OPPROTO
glue(op_psrld
, SUFFIX
)(void)
126 d
= (Reg
*)((char *)env
+ PARAM1
);
127 s
= (Reg
*)((char *)env
+ PARAM2
);
146 void OPPROTO
glue(op_psrad
, SUFFIX
)(void)
151 d
= (Reg
*)((char *)env
+ PARAM1
);
152 s
= (Reg
*)((char *)env
+ PARAM2
);
159 d
->L(0) = (int32_t)d
->L(0) >> shift
;
160 d
->L(1) = (int32_t)d
->L(1) >> shift
;
162 d
->L(2) = (int32_t)d
->L(2) >> shift
;
163 d
->L(3) = (int32_t)d
->L(3) >> shift
;
167 void OPPROTO
glue(op_pslld
, SUFFIX
)(void)
172 d
= (Reg
*)((char *)env
+ PARAM1
);
173 s
= (Reg
*)((char *)env
+ PARAM2
);
192 void OPPROTO
glue(op_psrlq
, SUFFIX
)(void)
197 d
= (Reg
*)((char *)env
+ PARAM1
);
198 s
= (Reg
*)((char *)env
+ PARAM2
);
215 void OPPROTO
glue(op_psllq
, SUFFIX
)(void)
220 d
= (Reg
*)((char *)env
+ PARAM1
);
221 s
= (Reg
*)((char *)env
+ PARAM2
);
239 void OPPROTO
glue(op_psrldq
, SUFFIX
)(void)
244 d
= (Reg
*)((char *)env
+ PARAM1
);
245 s
= (Reg
*)((char *)env
+ PARAM2
);
249 for(i
= 0; i
< 16 - shift
; i
++)
250 d
->B(i
) = d
->B(i
+ shift
);
251 for(i
= 16 - shift
; i
< 16; i
++)
256 void OPPROTO
glue(op_pslldq
, SUFFIX
)(void)
261 d
= (Reg
*)((char *)env
+ PARAM1
);
262 s
= (Reg
*)((char *)env
+ PARAM2
);
266 for(i
= 15; i
>= shift
; i
--)
267 d
->B(i
) = d
->B(i
- shift
);
268 for(i
= 0; i
< shift
; i
++)
274 #define SSE_OP_B(name, F)\
275 void OPPROTO glue(name, SUFFIX) (void)\
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));\
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));\
300 #define SSE_OP_W(name, F)\
301 void OPPROTO glue(name, SUFFIX) (void)\
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));\
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));\
318 #define SSE_OP_L(name, F)\
319 void OPPROTO glue(name, SUFFIX) (void)\
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));\
327 d->L(2) = F(d->L(2), s->L(2));\
328 d->L(3) = F(d->L(3), s->L(3));\
332 #define SSE_OP_Q(name, F)\
333 void OPPROTO glue(name, SUFFIX) (void)\
336 d = (Reg *)((char *)env + PARAM1);\
337 s = (Reg *)((char *)env + PARAM2);\
338 d->Q(0) = F(d->Q(0), s->Q(0));\
340 d->Q(1) = F(d->Q(1), s->Q(1));\
345 static inline int satub(int x
)
355 static inline int satuw(int x
)
365 static inline int satsb(int x
)
375 static inline int satsw(int x
)
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))
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)
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)
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
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
415 #define FAVG(a, b) ((a) + (b) + 1) >> 1
418 SSE_OP_B(op_paddb
, FADD
)
419 SSE_OP_W(op_paddw
, FADD
)
420 SSE_OP_L(op_paddl
, FADD
)
421 SSE_OP_Q(op_paddq
, FADD
)
423 SSE_OP_B(op_psubb
, FSUB
)
424 SSE_OP_W(op_psubw
, FSUB
)
425 SSE_OP_L(op_psubl
, FSUB
)
426 SSE_OP_Q(op_psubq
, FSUB
)
428 SSE_OP_B(op_paddusb
, FADDUB
)
429 SSE_OP_B(op_paddsb
, FADDSB
)
430 SSE_OP_B(op_psubusb
, FSUBUB
)
431 SSE_OP_B(op_psubsb
, FSUBSB
)
433 SSE_OP_W(op_paddusw
, FADDUW
)
434 SSE_OP_W(op_paddsw
, FADDSW
)
435 SSE_OP_W(op_psubusw
, FSUBUW
)
436 SSE_OP_W(op_psubsw
, FSUBSW
)
438 SSE_OP_B(op_pminub
, FMINUB
)
439 SSE_OP_B(op_pmaxub
, FMAXUB
)
441 SSE_OP_W(op_pminsw
, FMINSW
)
442 SSE_OP_W(op_pmaxsw
, FMAXSW
)
444 SSE_OP_Q(op_pand
, FAND
)
445 SSE_OP_Q(op_pandn
, FANDN
)
446 SSE_OP_Q(op_por
, FOR
)
447 SSE_OP_Q(op_pxor
, FXOR
)
449 SSE_OP_B(op_pcmpgtb
, FCMPGTB
)
450 SSE_OP_W(op_pcmpgtw
, FCMPGTW
)
451 SSE_OP_L(op_pcmpgtl
, FCMPGTL
)
453 SSE_OP_B(op_pcmpeqb
, FCMPEQ
)
454 SSE_OP_W(op_pcmpeqw
, FCMPEQ
)
455 SSE_OP_L(op_pcmpeql
, FCMPEQ
)
457 SSE_OP_W(op_pmullw
, FMULLW
)
458 SSE_OP_W(op_pmulhuw
, FMULHUW
)
459 SSE_OP_W(op_pmulhw
, FMULHW
)
461 SSE_OP_B(op_pavgb
, FAVG
)
462 SSE_OP_W(op_pavgw
, FAVG
)
464 void OPPROTO
glue(op_pmuludq
, SUFFIX
) (void)
467 d
= (Reg
*)((char *)env
+ PARAM1
);
468 s
= (Reg
*)((char *)env
+ PARAM2
);
470 d
->Q(0) = (uint64_t)s
->L(0) * (uint64_t)d
->L(0);
472 d
->Q(1) = (uint64_t)s
->L(2) * (uint64_t)d
->L(2);
476 void OPPROTO
glue(op_pmaddwd
, SUFFIX
) (void)
480 d
= (Reg
*)((char *)env
+ PARAM1
);
481 s
= (Reg
*)((char *)env
+ PARAM2
);
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);
491 static inline int abs1(int a
)
499 void OPPROTO
glue(op_psadbw
, SUFFIX
) (void)
503 d
= (Reg
*)((char *)env
+ PARAM1
);
504 s
= (Reg
*)((char *)env
+ PARAM2
);
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));
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));
530 void OPPROTO
glue(op_maskmov
, SUFFIX
) (void)
534 d
= (Reg
*)((char *)env
+ PARAM1
);
535 s
= (Reg
*)((char *)env
+ PARAM2
);
536 for(i
= 0; i
< (8 << SHIFT
); i
++) {
538 stb(A0
+ i
, d
->B(i
));
543 void OPPROTO
glue(op_movl_mm_T0
, SUFFIX
) (void)
546 d
= (Reg
*)((char *)env
+ PARAM1
);
554 void OPPROTO
glue(op_movl_T0_mm
, SUFFIX
) (void)
557 s
= (Reg
*)((char *)env
+ PARAM1
);
562 void OPPROTO
glue(op_movq_mm_T0
, SUFFIX
) (void)
565 d
= (Reg
*)((char *)env
+ PARAM1
);
572 void OPPROTO
glue(op_movq_T0_mm
, SUFFIX
) (void)
575 s
= (Reg
*)((char *)env
+ PARAM1
);
581 void OPPROTO
glue(op_pshufw
, SUFFIX
) (void)
585 d
= (Reg
*)((char *)env
+ PARAM1
);
586 s
= (Reg
*)((char *)env
+ PARAM2
);
588 r
.W(0) = s
->W(order
& 3);
589 r
.W(1) = s
->W((order
>> 2) & 3);
590 r
.W(2) = s
->W((order
>> 4) & 3);
591 r
.W(3) = s
->W((order
>> 6) & 3);
595 void OPPROTO
op_shufps(void)
599 d
= (Reg
*)((char *)env
+ PARAM1
);
600 s
= (Reg
*)((char *)env
+ PARAM2
);
602 r
.L(0) = d
->L(order
& 3);
603 r
.L(1) = d
->L((order
>> 2) & 3);
604 r
.L(2) = s
->L((order
>> 4) & 3);
605 r
.L(3) = s
->L((order
>> 6) & 3);
609 void OPPROTO
op_shufpd(void)
613 d
= (Reg
*)((char *)env
+ PARAM1
);
614 s
= (Reg
*)((char *)env
+ PARAM2
);
616 r
.Q(0) = d
->Q(order
& 1);
617 r
.Q(1) = s
->Q((order
>> 1) & 1);
621 void OPPROTO
glue(op_pshufd
, SUFFIX
) (void)
625 d
= (Reg
*)((char *)env
+ PARAM1
);
626 s
= (Reg
*)((char *)env
+ PARAM2
);
628 r
.L(0) = s
->L(order
& 3);
629 r
.L(1) = s
->L((order
>> 2) & 3);
630 r
.L(2) = s
->L((order
>> 4) & 3);
631 r
.L(3) = s
->L((order
>> 6) & 3);
635 void OPPROTO
glue(op_pshuflw
, SUFFIX
) (void)
639 d
= (Reg
*)((char *)env
+ PARAM1
);
640 s
= (Reg
*)((char *)env
+ PARAM2
);
642 r
.W(0) = s
->W(order
& 3);
643 r
.W(1) = s
->W((order
>> 2) & 3);
644 r
.W(2) = s
->W((order
>> 4) & 3);
645 r
.W(3) = s
->W((order
>> 6) & 3);
650 void OPPROTO
glue(op_pshufhw
, SUFFIX
) (void)
654 d
= (Reg
*)((char *)env
+ PARAM1
);
655 s
= (Reg
*)((char *)env
+ PARAM2
);
658 r
.W(4) = s
->W(4 + (order
& 3));
659 r
.W(5) = s
->W(4 + ((order
>> 2) & 3));
660 r
.W(6) = s
->W(4 + ((order
>> 4) & 3));
661 r
.W(7) = s
->W(4 + ((order
>> 6) & 3));
668 /* XXX: not accurate */
670 #define SSE_OP_S(name, F)\
671 void OPPROTO op_ ## name ## ps (void)\
674 d = (Reg *)((char *)env + PARAM1);\
675 s = (Reg *)((char *)env + PARAM2);\
676 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
677 d->XMM_S(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
678 d->XMM_S(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
679 d->XMM_S(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
682 void OPPROTO op_ ## name ## ss (void)\
685 d = (Reg *)((char *)env + PARAM1);\
686 s = (Reg *)((char *)env + PARAM2);\
687 d->XMM_S(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
689 void OPPROTO op_ ## name ## pd (void)\
692 d = (Reg *)((char *)env + PARAM1);\
693 s = (Reg *)((char *)env + PARAM2);\
694 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
695 d->XMM_D(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
698 void OPPROTO op_ ## name ## sd (void)\
701 d = (Reg *)((char *)env + PARAM1);\
702 s = (Reg *)((char *)env + PARAM2);\
703 d->XMM_D(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
706 #define FPU_ADD(size, a, b) float ## size ## _add(a, b, &env->sse_status)
707 #define FPU_SUB(size, a, b) float ## size ## _sub(a, b, &env->sse_status)
708 #define FPU_MUL(size, a, b) float ## size ## _mul(a, b, &env->sse_status)
709 #define FPU_DIV(size, a, b) float ## size ## _div(a, b, &env->sse_status)
710 #define FPU_MIN(size, a, b) (a) < (b) ? (a) : (b)
711 #define FPU_MAX(size, a, b) (a) > (b) ? (a) : (b)
712 #define FPU_SQRT(size, a, b) float ## size ## _sqrt(b, &env->sse_status)
714 SSE_OP_S(add
, FPU_ADD
)
715 SSE_OP_S(sub
, FPU_SUB
)
716 SSE_OP_S(mul
, FPU_MUL
)
717 SSE_OP_S(div
, FPU_DIV
)
718 SSE_OP_S(min
, FPU_MIN
)
719 SSE_OP_S(max
, FPU_MAX
)
720 SSE_OP_S(sqrt
, FPU_SQRT
)
723 /* float to float conversions */
724 void OPPROTO
op_cvtps2pd(void)
728 d
= (Reg
*)((char *)env
+ PARAM1
);
729 s
= (Reg
*)((char *)env
+ PARAM2
);
732 d
->XMM_D(0) = float32_to_float64(s0
, &env
->sse_status
);
733 d
->XMM_D(1) = float32_to_float64(s1
, &env
->sse_status
);
736 void OPPROTO
op_cvtpd2ps(void)
739 d
= (Reg
*)((char *)env
+ PARAM1
);
740 s
= (Reg
*)((char *)env
+ PARAM2
);
741 d
->XMM_S(0) = float64_to_float32(s
->XMM_D(0), &env
->sse_status
);
742 d
->XMM_S(1) = float64_to_float32(s
->XMM_D(1), &env
->sse_status
);
746 void OPPROTO
op_cvtss2sd(void)
749 d
= (Reg
*)((char *)env
+ PARAM1
);
750 s
= (Reg
*)((char *)env
+ PARAM2
);
751 d
->XMM_D(0) = float32_to_float64(s
->XMM_S(0), &env
->sse_status
);
754 void OPPROTO
op_cvtsd2ss(void)
757 d
= (Reg
*)((char *)env
+ PARAM1
);
758 s
= (Reg
*)((char *)env
+ PARAM2
);
759 d
->XMM_S(0) = float64_to_float32(s
->XMM_D(0), &env
->sse_status
);
762 /* integer to float */
763 void OPPROTO
op_cvtdq2ps(void)
765 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
766 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
767 d
->XMM_S(0) = int32_to_float32(s
->XMM_L(0), &env
->sse_status
);
768 d
->XMM_S(1) = int32_to_float32(s
->XMM_L(1), &env
->sse_status
);
769 d
->XMM_S(2) = int32_to_float32(s
->XMM_L(2), &env
->sse_status
);
770 d
->XMM_S(3) = int32_to_float32(s
->XMM_L(3), &env
->sse_status
);
773 void OPPROTO
op_cvtdq2pd(void)
775 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
776 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
778 l0
= (int32_t)s
->XMM_L(0);
779 l1
= (int32_t)s
->XMM_L(1);
780 d
->XMM_D(0) = int32_to_float64(l0
, &env
->sse_status
);
781 d
->XMM_D(1) = int32_to_float64(l1
, &env
->sse_status
);
784 void OPPROTO
op_cvtpi2ps(void)
786 XMMReg
*d
= (Reg
*)((char *)env
+ PARAM1
);
787 MMXReg
*s
= (MMXReg
*)((char *)env
+ PARAM2
);
788 d
->XMM_S(0) = int32_to_float32(s
->MMX_L(0), &env
->sse_status
);
789 d
->XMM_S(1) = int32_to_float32(s
->MMX_L(1), &env
->sse_status
);
792 void OPPROTO
op_cvtpi2pd(void)
794 XMMReg
*d
= (Reg
*)((char *)env
+ PARAM1
);
795 MMXReg
*s
= (MMXReg
*)((char *)env
+ PARAM2
);
796 d
->XMM_D(0) = int32_to_float64(s
->MMX_L(0), &env
->sse_status
);
797 d
->XMM_D(1) = int32_to_float64(s
->MMX_L(1), &env
->sse_status
);
800 void OPPROTO
op_cvtsi2ss(void)
802 XMMReg
*d
= (Reg
*)((char *)env
+ PARAM1
);
803 d
->XMM_S(0) = int32_to_float32(T0
, &env
->sse_status
);
806 void OPPROTO
op_cvtsi2sd(void)
808 XMMReg
*d
= (Reg
*)((char *)env
+ PARAM1
);
809 d
->XMM_D(0) = int32_to_float64(T0
, &env
->sse_status
);
813 void OPPROTO
op_cvtsq2ss(void)
815 XMMReg
*d
= (Reg
*)((char *)env
+ PARAM1
);
816 d
->XMM_S(0) = int64_to_float32(T0
, &env
->sse_status
);
819 void OPPROTO
op_cvtsq2sd(void)
821 XMMReg
*d
= (Reg
*)((char *)env
+ PARAM1
);
822 d
->XMM_D(0) = int64_to_float64(T0
, &env
->sse_status
);
826 /* float to integer */
827 void OPPROTO
op_cvtps2dq(void)
829 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
830 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
831 d
->XMM_L(0) = float32_to_int32(s
->XMM_S(0), &env
->sse_status
);
832 d
->XMM_L(1) = float32_to_int32(s
->XMM_S(1), &env
->sse_status
);
833 d
->XMM_L(2) = float32_to_int32(s
->XMM_S(2), &env
->sse_status
);
834 d
->XMM_L(3) = float32_to_int32(s
->XMM_S(3), &env
->sse_status
);
837 void OPPROTO
op_cvtpd2dq(void)
839 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
840 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
841 d
->XMM_L(0) = float64_to_int32(s
->XMM_D(0), &env
->sse_status
);
842 d
->XMM_L(1) = float64_to_int32(s
->XMM_D(1), &env
->sse_status
);
846 void OPPROTO
op_cvtps2pi(void)
848 MMXReg
*d
= (MMXReg
*)((char *)env
+ PARAM1
);
849 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
850 d
->MMX_L(0) = float32_to_int32(s
->XMM_S(0), &env
->sse_status
);
851 d
->MMX_L(1) = float32_to_int32(s
->XMM_S(1), &env
->sse_status
);
854 void OPPROTO
op_cvtpd2pi(void)
856 MMXReg
*d
= (MMXReg
*)((char *)env
+ PARAM1
);
857 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
858 d
->MMX_L(0) = float64_to_int32(s
->XMM_D(0), &env
->sse_status
);
859 d
->MMX_L(1) = float64_to_int32(s
->XMM_D(1), &env
->sse_status
);
862 void OPPROTO
op_cvtss2si(void)
864 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
865 T0
= float32_to_int32(s
->XMM_S(0), &env
->sse_status
);
868 void OPPROTO
op_cvtsd2si(void)
870 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
871 T0
= float64_to_int32(s
->XMM_D(0), &env
->sse_status
);
875 void OPPROTO
op_cvtss2sq(void)
877 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
878 T0
= float32_to_int64(s
->XMM_S(0), &env
->sse_status
);
881 void OPPROTO
op_cvtsd2sq(void)
883 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
884 T0
= float64_to_int64(s
->XMM_D(0), &env
->sse_status
);
888 /* float to integer truncated */
889 void OPPROTO
op_cvttps2dq(void)
891 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
892 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
893 d
->XMM_L(0) = float32_to_int32_round_to_zero(s
->XMM_S(0), &env
->sse_status
);
894 d
->XMM_L(1) = float32_to_int32_round_to_zero(s
->XMM_S(1), &env
->sse_status
);
895 d
->XMM_L(2) = float32_to_int32_round_to_zero(s
->XMM_S(2), &env
->sse_status
);
896 d
->XMM_L(3) = float32_to_int32_round_to_zero(s
->XMM_S(3), &env
->sse_status
);
899 void OPPROTO
op_cvttpd2dq(void)
901 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
902 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
903 d
->XMM_L(0) = float64_to_int32_round_to_zero(s
->XMM_D(0), &env
->sse_status
);
904 d
->XMM_L(1) = float64_to_int32_round_to_zero(s
->XMM_D(1), &env
->sse_status
);
908 void OPPROTO
op_cvttps2pi(void)
910 MMXReg
*d
= (MMXReg
*)((char *)env
+ PARAM1
);
911 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
912 d
->MMX_L(0) = float32_to_int32_round_to_zero(s
->XMM_S(0), &env
->sse_status
);
913 d
->MMX_L(1) = float32_to_int32_round_to_zero(s
->XMM_S(1), &env
->sse_status
);
916 void OPPROTO
op_cvttpd2pi(void)
918 MMXReg
*d
= (MMXReg
*)((char *)env
+ PARAM1
);
919 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
920 d
->MMX_L(0) = float64_to_int32_round_to_zero(s
->XMM_D(0), &env
->sse_status
);
921 d
->MMX_L(1) = float64_to_int32_round_to_zero(s
->XMM_D(1), &env
->sse_status
);
924 void OPPROTO
op_cvttss2si(void)
926 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
927 T0
= float32_to_int32_round_to_zero(s
->XMM_S(0), &env
->sse_status
);
930 void OPPROTO
op_cvttsd2si(void)
932 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
933 T0
= float64_to_int32_round_to_zero(s
->XMM_D(0), &env
->sse_status
);
937 void OPPROTO
op_cvttss2sq(void)
939 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
940 T0
= float32_to_int64_round_to_zero(s
->XMM_S(0), &env
->sse_status
);
943 void OPPROTO
op_cvttsd2sq(void)
945 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM1
);
946 T0
= float64_to_int64_round_to_zero(s
->XMM_D(0), &env
->sse_status
);
950 void OPPROTO
op_rsqrtps(void)
952 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
953 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
954 d
->XMM_S(0) = approx_rsqrt(s
->XMM_S(0));
955 d
->XMM_S(1) = approx_rsqrt(s
->XMM_S(1));
956 d
->XMM_S(2) = approx_rsqrt(s
->XMM_S(2));
957 d
->XMM_S(3) = approx_rsqrt(s
->XMM_S(3));
960 void OPPROTO
op_rsqrtss(void)
962 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
963 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
964 d
->XMM_S(0) = approx_rsqrt(s
->XMM_S(0));
967 void OPPROTO
op_rcpps(void)
969 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
970 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
971 d
->XMM_S(0) = approx_rcp(s
->XMM_S(0));
972 d
->XMM_S(1) = approx_rcp(s
->XMM_S(1));
973 d
->XMM_S(2) = approx_rcp(s
->XMM_S(2));
974 d
->XMM_S(3) = approx_rcp(s
->XMM_S(3));
977 void OPPROTO
op_rcpss(void)
979 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
980 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
981 d
->XMM_S(0) = approx_rcp(s
->XMM_S(0));
984 void OPPROTO
op_haddps(void)
986 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
987 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
989 r
.XMM_S(0) = d
->XMM_S(0) + d
->XMM_S(1);
990 r
.XMM_S(1) = d
->XMM_S(2) + d
->XMM_S(3);
991 r
.XMM_S(2) = s
->XMM_S(0) + s
->XMM_S(1);
992 r
.XMM_S(3) = s
->XMM_S(2) + s
->XMM_S(3);
996 void OPPROTO
op_haddpd(void)
998 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
999 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
1001 r
.XMM_D(0) = d
->XMM_D(0) + d
->XMM_D(1);
1002 r
.XMM_D(1) = s
->XMM_D(0) + s
->XMM_D(1);
1006 void OPPROTO
op_hsubps(void)
1008 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
1009 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
1011 r
.XMM_S(0) = d
->XMM_S(0) - d
->XMM_S(1);
1012 r
.XMM_S(1) = d
->XMM_S(2) - d
->XMM_S(3);
1013 r
.XMM_S(2) = s
->XMM_S(0) - s
->XMM_S(1);
1014 r
.XMM_S(3) = s
->XMM_S(2) - s
->XMM_S(3);
1018 void OPPROTO
op_hsubpd(void)
1020 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
1021 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
1023 r
.XMM_D(0) = d
->XMM_D(0) - d
->XMM_D(1);
1024 r
.XMM_D(1) = s
->XMM_D(0) - s
->XMM_D(1);
1028 void OPPROTO
op_addsubps(void)
1030 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
1031 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
1032 d
->XMM_S(0) = d
->XMM_S(0) - s
->XMM_S(0);
1033 d
->XMM_S(1) = d
->XMM_S(1) + s
->XMM_S(1);
1034 d
->XMM_S(2) = d
->XMM_S(2) - s
->XMM_S(2);
1035 d
->XMM_S(3) = d
->XMM_S(3) + s
->XMM_S(3);
1038 void OPPROTO
op_addsubpd(void)
1040 XMMReg
*d
= (XMMReg
*)((char *)env
+ PARAM1
);
1041 XMMReg
*s
= (XMMReg
*)((char *)env
+ PARAM2
);
1042 d
->XMM_D(0) = d
->XMM_D(0) - s
->XMM_D(0);
1043 d
->XMM_D(1) = d
->XMM_D(1) + s
->XMM_D(1);
1046 /* XXX: unordered */
1047 #define SSE_OP_CMP(name, F)\
1048 void OPPROTO op_ ## name ## ps (void)\
1051 d = (Reg *)((char *)env + PARAM1);\
1052 s = (Reg *)((char *)env + PARAM2);\
1053 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1054 d->XMM_L(1) = F(32, d->XMM_S(1), s->XMM_S(1));\
1055 d->XMM_L(2) = F(32, d->XMM_S(2), s->XMM_S(2));\
1056 d->XMM_L(3) = F(32, d->XMM_S(3), s->XMM_S(3));\
1059 void OPPROTO op_ ## name ## ss (void)\
1062 d = (Reg *)((char *)env + PARAM1);\
1063 s = (Reg *)((char *)env + PARAM2);\
1064 d->XMM_L(0) = F(32, d->XMM_S(0), s->XMM_S(0));\
1066 void OPPROTO op_ ## name ## pd (void)\
1069 d = (Reg *)((char *)env + PARAM1);\
1070 s = (Reg *)((char *)env + PARAM2);\
1071 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1072 d->XMM_Q(1) = F(64, d->XMM_D(1), s->XMM_D(1));\
1075 void OPPROTO op_ ## name ## sd (void)\
1078 d = (Reg *)((char *)env + PARAM1);\
1079 s = (Reg *)((char *)env + PARAM2);\
1080 d->XMM_Q(0) = F(64, d->XMM_D(0), s->XMM_D(0));\
1083 #define FPU_CMPEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? -1 : 0
1084 #define FPU_CMPLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? -1 : 0
1085 #define FPU_CMPLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? -1 : 0
1086 #define FPU_CMPUNORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? - 1 : 0
1087 #define FPU_CMPNEQ(size, a, b) float ## size ## _eq(a, b, &env->sse_status) ? 0 : -1
1088 #define FPU_CMPNLT(size, a, b) float ## size ## _lt(a, b, &env->sse_status) ? 0 : -1
1089 #define FPU_CMPNLE(size, a, b) float ## size ## _le(a, b, &env->sse_status) ? 0 : -1
1090 #define FPU_CMPORD(size, a, b) float ## size ## _unordered(a, b, &env->sse_status) ? 0 : -1
1092 SSE_OP_CMP(cmpeq
, FPU_CMPEQ
)
1093 SSE_OP_CMP(cmplt
, FPU_CMPLT
)
1094 SSE_OP_CMP(cmple
, FPU_CMPLE
)
1095 SSE_OP_CMP(cmpunord
, FPU_CMPUNORD
)
1096 SSE_OP_CMP(cmpneq
, FPU_CMPNEQ
)
1097 SSE_OP_CMP(cmpnlt
, FPU_CMPNLT
)
1098 SSE_OP_CMP(cmpnle
, FPU_CMPNLE
)
1099 SSE_OP_CMP(cmpord
, FPU_CMPORD
)
1101 const int comis_eflags
[4] = {CC_C
, CC_Z
, 0, CC_Z
| CC_P
| CC_C
};
1103 void OPPROTO
op_ucomiss(void)
1108 d
= (Reg
*)((char *)env
+ PARAM1
);
1109 s
= (Reg
*)((char *)env
+ PARAM2
);
1113 ret
= float32_compare_quiet(s0
, s1
, &env
->sse_status
);
1114 CC_SRC
= comis_eflags
[ret
+ 1];
1118 void OPPROTO
op_comiss(void)
1123 d
= (Reg
*)((char *)env
+ PARAM1
);
1124 s
= (Reg
*)((char *)env
+ PARAM2
);
1128 ret
= float32_compare(s0
, s1
, &env
->sse_status
);
1129 CC_SRC
= comis_eflags
[ret
+ 1];
1133 void OPPROTO
op_ucomisd(void)
1138 d
= (Reg
*)((char *)env
+ PARAM1
);
1139 s
= (Reg
*)((char *)env
+ PARAM2
);
1143 ret
= float64_compare_quiet(d0
, d1
, &env
->sse_status
);
1144 CC_SRC
= comis_eflags
[ret
+ 1];
1148 void OPPROTO
op_comisd(void)
1153 d
= (Reg
*)((char *)env
+ PARAM1
);
1154 s
= (Reg
*)((char *)env
+ PARAM2
);
1158 ret
= float64_compare(d0
, d1
, &env
->sse_status
);
1159 CC_SRC
= comis_eflags
[ret
+ 1];
1163 void OPPROTO
op_movmskps(void)
1167 s
= (Reg
*)((char *)env
+ PARAM1
);
1168 b0
= s
->XMM_L(0) >> 31;
1169 b1
= s
->XMM_L(1) >> 31;
1170 b2
= s
->XMM_L(2) >> 31;
1171 b3
= s
->XMM_L(3) >> 31;
1172 T0
= b0
| (b1
<< 1) | (b2
<< 2) | (b3
<< 3);
1175 void OPPROTO
op_movmskpd(void)
1179 s
= (Reg
*)((char *)env
+ PARAM1
);
1180 b0
= s
->XMM_L(1) >> 31;
1181 b1
= s
->XMM_L(3) >> 31;
1182 T0
= b0
| (b1
<< 1);
1187 void OPPROTO
glue(op_pmovmskb
, SUFFIX
)(void)
1190 s
= (Reg
*)((char *)env
+ PARAM1
);
1192 T0
|= (s
->XMM_B(0) >> 7);
1193 T0
|= (s
->XMM_B(1) >> 6) & 0x02;
1194 T0
|= (s
->XMM_B(2) >> 5) & 0x04;
1195 T0
|= (s
->XMM_B(3) >> 4) & 0x08;
1196 T0
|= (s
->XMM_B(4) >> 3) & 0x10;
1197 T0
|= (s
->XMM_B(5) >> 2) & 0x20;
1198 T0
|= (s
->XMM_B(6) >> 1) & 0x40;
1199 T0
|= (s
->XMM_B(7)) & 0x80;
1201 T0
|= (s
->XMM_B(8) << 1) & 0x0100;
1202 T0
|= (s
->XMM_B(9) << 2) & 0x0200;
1203 T0
|= (s
->XMM_B(10) << 3) & 0x0400;
1204 T0
|= (s
->XMM_B(11) << 4) & 0x0800;
1205 T0
|= (s
->XMM_B(12) << 5) & 0x1000;
1206 T0
|= (s
->XMM_B(13) << 6) & 0x2000;
1207 T0
|= (s
->XMM_B(14) << 7) & 0x4000;
1208 T0
|= (s
->XMM_B(15) << 8) & 0x8000;
1212 void OPPROTO
glue(op_pinsrw
, SUFFIX
) (void)
1214 Reg
*d
= (Reg
*)((char *)env
+ PARAM1
);
1220 void OPPROTO
glue(op_pextrw
, SUFFIX
) (void)
1222 Reg
*s
= (Reg
*)((char *)env
+ PARAM1
);
1228 void OPPROTO
glue(op_packsswb
, SUFFIX
) (void)
1231 d
= (Reg
*)((char *)env
+ PARAM1
);
1232 s
= (Reg
*)((char *)env
+ PARAM2
);
1234 r
.B(0) = satsb((int16_t)d
->W(0));
1235 r
.B(1) = satsb((int16_t)d
->W(1));
1236 r
.B(2) = satsb((int16_t)d
->W(2));
1237 r
.B(3) = satsb((int16_t)d
->W(3));
1239 r
.B(4) = satsb((int16_t)d
->W(4));
1240 r
.B(5) = satsb((int16_t)d
->W(5));
1241 r
.B(6) = satsb((int16_t)d
->W(6));
1242 r
.B(7) = satsb((int16_t)d
->W(7));
1244 r
.B((4 << SHIFT
) + 0) = satsb((int16_t)s
->W(0));
1245 r
.B((4 << SHIFT
) + 1) = satsb((int16_t)s
->W(1));
1246 r
.B((4 << SHIFT
) + 2) = satsb((int16_t)s
->W(2));
1247 r
.B((4 << SHIFT
) + 3) = satsb((int16_t)s
->W(3));
1249 r
.B(12) = satsb((int16_t)s
->W(4));
1250 r
.B(13) = satsb((int16_t)s
->W(5));
1251 r
.B(14) = satsb((int16_t)s
->W(6));
1252 r
.B(15) = satsb((int16_t)s
->W(7));
1257 void OPPROTO
glue(op_packuswb
, SUFFIX
) (void)
1260 d
= (Reg
*)((char *)env
+ PARAM1
);
1261 s
= (Reg
*)((char *)env
+ PARAM2
);
1263 r
.B(0) = satub((int16_t)d
->W(0));
1264 r
.B(1) = satub((int16_t)d
->W(1));
1265 r
.B(2) = satub((int16_t)d
->W(2));
1266 r
.B(3) = satub((int16_t)d
->W(3));
1268 r
.B(4) = satub((int16_t)d
->W(4));
1269 r
.B(5) = satub((int16_t)d
->W(5));
1270 r
.B(6) = satub((int16_t)d
->W(6));
1271 r
.B(7) = satub((int16_t)d
->W(7));
1273 r
.B((4 << SHIFT
) + 0) = satub((int16_t)s
->W(0));
1274 r
.B((4 << SHIFT
) + 1) = satub((int16_t)s
->W(1));
1275 r
.B((4 << SHIFT
) + 2) = satub((int16_t)s
->W(2));
1276 r
.B((4 << SHIFT
) + 3) = satub((int16_t)s
->W(3));
1278 r
.B(12) = satub((int16_t)s
->W(4));
1279 r
.B(13) = satub((int16_t)s
->W(5));
1280 r
.B(14) = satub((int16_t)s
->W(6));
1281 r
.B(15) = satub((int16_t)s
->W(7));
1286 void OPPROTO
glue(op_packssdw
, SUFFIX
) (void)
1289 d
= (Reg
*)((char *)env
+ PARAM1
);
1290 s
= (Reg
*)((char *)env
+ PARAM2
);
1292 r
.W(0) = satsw(d
->L(0));
1293 r
.W(1) = satsw(d
->L(1));
1295 r
.W(2) = satsw(d
->L(2));
1296 r
.W(3) = satsw(d
->L(3));
1298 r
.W((2 << SHIFT
) + 0) = satsw(s
->L(0));
1299 r
.W((2 << SHIFT
) + 1) = satsw(s
->L(1));
1301 r
.W(6) = satsw(s
->L(2));
1302 r
.W(7) = satsw(s
->L(3));
1307 #define UNPCK_OP(base_name, base) \
1309 void OPPROTO glue(op_punpck ## base_name ## bw, SUFFIX) (void) \
1312 d = (Reg *)((char *)env + PARAM1); \
1313 s = (Reg *)((char *)env + PARAM2); \
1315 r.B(0) = d->B((base << (SHIFT + 2)) + 0); \
1316 r.B(1) = s->B((base << (SHIFT + 2)) + 0); \
1317 r.B(2) = d->B((base << (SHIFT + 2)) + 1); \
1318 r.B(3) = s->B((base << (SHIFT + 2)) + 1); \
1319 r.B(4) = d->B((base << (SHIFT + 2)) + 2); \
1320 r.B(5) = s->B((base << (SHIFT + 2)) + 2); \
1321 r.B(6) = d->B((base << (SHIFT + 2)) + 3); \
1322 r.B(7) = s->B((base << (SHIFT + 2)) + 3); \
1324 r.B(8) = d->B((base << (SHIFT + 2)) + 4); \
1325 r.B(9) = s->B((base << (SHIFT + 2)) + 4); \
1326 r.B(10) = d->B((base << (SHIFT + 2)) + 5); \
1327 r.B(11) = s->B((base << (SHIFT + 2)) + 5); \
1328 r.B(12) = d->B((base << (SHIFT + 2)) + 6); \
1329 r.B(13) = s->B((base << (SHIFT + 2)) + 6); \
1330 r.B(14) = d->B((base << (SHIFT + 2)) + 7); \
1331 r.B(15) = s->B((base << (SHIFT + 2)) + 7); \
1336 void OPPROTO glue(op_punpck ## base_name ## wd, SUFFIX) (void) \
1339 d = (Reg *)((char *)env + PARAM1); \
1340 s = (Reg *)((char *)env + PARAM2); \
1342 r.W(0) = d->W((base << (SHIFT + 1)) + 0); \
1343 r.W(1) = s->W((base << (SHIFT + 1)) + 0); \
1344 r.W(2) = d->W((base << (SHIFT + 1)) + 1); \
1345 r.W(3) = s->W((base << (SHIFT + 1)) + 1); \
1347 r.W(4) = d->W((base << (SHIFT + 1)) + 2); \
1348 r.W(5) = s->W((base << (SHIFT + 1)) + 2); \
1349 r.W(6) = d->W((base << (SHIFT + 1)) + 3); \
1350 r.W(7) = s->W((base << (SHIFT + 1)) + 3); \
1355 void OPPROTO glue(op_punpck ## base_name ## dq, SUFFIX) (void) \
1358 d = (Reg *)((char *)env + PARAM1); \
1359 s = (Reg *)((char *)env + PARAM2); \
1361 r.L(0) = d->L((base << SHIFT) + 0); \
1362 r.L(1) = s->L((base << SHIFT) + 0); \
1364 r.L(2) = d->L((base << SHIFT) + 1); \
1365 r.L(3) = s->L((base << SHIFT) + 1); \
1371 void OPPROTO glue(op_punpck ## base_name ## qdq, SUFFIX) (void) \
1374 d = (Reg *)((char *)env + PARAM1); \
1375 s = (Reg *)((char *)env + PARAM2); \
1377 r.Q(0) = d->Q(base); \
1378 r.Q(1) = s->Q(base); \