1 /**************************************************************************
3 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 **************************************************************************/
24 #include "pipe/p_config.h"
25 #include "util/u_cpu_detect.h"
27 #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
29 #include "pipe/p_compiler.h"
30 #include "util/u_debug.h"
31 #include "util/u_pointer.h"
33 #include "rtasm_execmem.h"
34 #include "rtasm_x86sse.h"
43 void x86_print_reg( struct x86_reg reg
)
45 if (reg
.mod
!= mod_REG
)
51 case reg_AX
: debug_printf( "EAX" ); break;
52 case reg_CX
: debug_printf( "ECX" ); break;
53 case reg_DX
: debug_printf( "EDX" ); break;
54 case reg_BX
: debug_printf( "EBX" ); break;
55 case reg_SP
: debug_printf( "ESP" ); break;
56 case reg_BP
: debug_printf( "EBP" ); break;
57 case reg_SI
: debug_printf( "ESI" ); break;
58 case reg_DI
: debug_printf( "EDI" ); break;
62 debug_printf( "MMX%u", reg
.idx
);
65 debug_printf( "XMM%u", reg
.idx
);
68 debug_printf( "fp%u", reg
.idx
);
72 if (reg
.mod
== mod_DISP8
||
73 reg
.mod
== mod_DISP32
)
74 debug_printf("+%d", reg
.disp
);
76 if (reg
.mod
!= mod_REG
)
82 #define DUMP_START() debug_printf( "\n" )
83 #define DUMP_END() debug_printf( "\n" )
86 const char *foo = __FUNCTION__; \
87 while (*foo && *foo != '_') \
91 debug_printf( "\n%4x %14s ", p->csr - p->store, foo ); \
94 #define DUMP_I( I ) do { \
96 debug_printf( "%u", I ); \
99 #define DUMP_R( R0 ) do { \
101 x86_print_reg( R0 ); \
104 #define DUMP_RR( R0, R1 ) do { \
106 x86_print_reg( R0 ); \
107 debug_printf( ", " ); \
108 x86_print_reg( R1 ); \
111 #define DUMP_RI( R0, I ) do { \
113 x86_print_reg( R0 ); \
114 debug_printf( ", %u", I ); \
117 #define DUMP_RRI( R0, R1, I ) do { \
119 x86_print_reg( R0 ); \
120 debug_printf( ", " ); \
121 x86_print_reg( R1 ); \
122 debug_printf( ", %u", I ); \
132 #define DUMP_RR( R0, R1 )
133 #define DUMP_RI( R0, I )
134 #define DUMP_RRI( R0, R1, I )
139 static void do_realloc( struct x86_function
*p
)
141 if (p
->store
== p
->error_overflow
) {
144 else if (p
->size
== 0) {
146 p
->store
= rtasm_exec_malloc(p
->size
);
150 uintptr_t used
= pointer_to_uintptr( p
->csr
) - pointer_to_uintptr( p
->store
);
151 unsigned char *tmp
= p
->store
;
153 p
->store
= rtasm_exec_malloc(p
->size
);
156 memcpy(p
->store
, tmp
, used
);
157 p
->csr
= p
->store
+ used
;
163 rtasm_exec_free(tmp
);
166 if (p
->store
== NULL
) {
167 p
->store
= p
->csr
= p
->error_overflow
;
168 p
->size
= sizeof(p
->error_overflow
);
172 /* Emit bytes to the instruction stream:
174 static unsigned char *reserve( struct x86_function
*p
, int bytes
)
176 if (p
->csr
+ bytes
- p
->store
> (int) p
->size
)
180 unsigned char *csr
= p
->csr
;
188 static void emit_1b( struct x86_function
*p
, char b0
)
190 char *csr
= (char *)reserve(p
, 1);
194 static void emit_1i( struct x86_function
*p
, int i0
)
196 int *icsr
= (int *)reserve(p
, sizeof(i0
));
200 static void emit_1ub( struct x86_function
*p
, unsigned char b0
)
202 unsigned char *csr
= reserve(p
, 1);
206 static void emit_2ub( struct x86_function
*p
, unsigned char b0
, unsigned char b1
)
208 unsigned char *csr
= reserve(p
, 2);
213 static void emit_3ub( struct x86_function
*p
, unsigned char b0
, unsigned char b1
, unsigned char b2
)
215 unsigned char *csr
= reserve(p
, 3);
222 /* Build a modRM byte + possible displacement. No treatment of SIB
223 * indexing. BZZT - no way to encode an absolute address.
225 * This is the "/r" field in the x86 manuals...
227 static void emit_modrm( struct x86_function
*p
,
229 struct x86_reg regmem
)
231 unsigned char val
= 0;
233 assert(reg
.mod
== mod_REG
);
235 /* TODO: support extended x86-64 registers */
237 assert(regmem
.idx
< 8);
239 val
|= regmem
.mod
<< 6; /* mod field */
240 val
|= reg
.idx
<< 3; /* reg field */
241 val
|= regmem
.idx
; /* r/m field */
245 /* Oh-oh we've stumbled into the SIB thing.
247 if (regmem
.file
== file_REG32
&&
248 regmem
.idx
== reg_SP
&&
249 regmem
.mod
!= mod_REG
) {
250 emit_1ub(p
, 0x24); /* simplistic! */
253 switch (regmem
.mod
) {
258 emit_1b(p
, (char) regmem
.disp
);
261 emit_1i(p
, regmem
.disp
);
269 /* Emits the "/0".."/7" specialized versions of the modrm ("/r") bytes.
271 static void emit_modrm_noreg( struct x86_function
*p
,
273 struct x86_reg regmem
)
275 struct x86_reg dummy
= x86_make_reg(file_REG32
, op
);
276 emit_modrm(p
, dummy
, regmem
);
279 /* Many x86 instructions have two opcodes to cope with the situations
280 * where the destination is a register or memory reference
281 * respectively. This function selects the correct opcode based on
282 * the arguments presented.
284 static void emit_op_modrm( struct x86_function
*p
,
285 unsigned char op_dst_is_reg
,
286 unsigned char op_dst_is_mem
,
292 emit_1ub(p
, op_dst_is_reg
);
293 emit_modrm(p
, dst
, src
);
298 assert(src
.mod
== mod_REG
);
299 emit_1ub(p
, op_dst_is_mem
);
300 emit_modrm(p
, src
, dst
);
314 /* Create and manipulate registers and regmem values:
316 struct x86_reg
x86_make_reg( enum x86_reg_file file
,
317 enum x86_reg_name idx
)
329 struct x86_reg
x86_make_disp( struct x86_reg reg
,
332 assert(reg
.file
== file_REG32
);
334 if (reg
.mod
== mod_REG
)
339 if (reg
.disp
== 0 && reg
.idx
!= reg_BP
)
340 reg
.mod
= mod_INDIRECT
;
341 else if (reg
.disp
<= 127 && reg
.disp
>= -128)
344 reg
.mod
= mod_DISP32
;
349 struct x86_reg
x86_deref( struct x86_reg reg
)
351 return x86_make_disp(reg
, 0);
354 struct x86_reg
x86_get_base_reg( struct x86_reg reg
)
356 return x86_make_reg( reg
.file
, reg
.idx
);
359 int x86_get_label( struct x86_function
*p
)
361 return p
->csr
- p
->store
;
366 /***********************************************************************
371 void x64_rexw(struct x86_function
*p
)
373 if(x86_target(p
) != X86_32
)
377 void x86_jcc( struct x86_function
*p
,
381 int offset
= label
- (x86_get_label(p
) + 2);
385 /*assert(p->csr - p->store > -offset);*/
386 if (p
->csr
- p
->store
<= -offset
) {
387 /* probably out of memory (using the error_overflow buffer) */
392 if (offset
<= 127 && offset
>= -128) {
393 emit_1ub(p
, 0x70 + cc
);
394 emit_1b(p
, (char) offset
);
397 offset
= label
- (x86_get_label(p
) + 6);
398 emit_2ub(p
, 0x0f, 0x80 + cc
);
403 /* Always use a 32bit offset for forward jumps:
405 int x86_jcc_forward( struct x86_function
*p
,
409 emit_2ub(p
, 0x0f, 0x80 + cc
);
411 return x86_get_label(p
);
414 int x86_jmp_forward( struct x86_function
*p
)
419 return x86_get_label(p
);
422 int x86_call_forward( struct x86_function
*p
)
428 return x86_get_label(p
);
431 /* Fixup offset from forward jump:
433 void x86_fixup_fwd_jump( struct x86_function
*p
,
436 *(int *)(p
->store
+ fixup
- 4) = x86_get_label(p
) - fixup
;
439 void x86_jmp( struct x86_function
*p
, int label
)
443 emit_1i(p
, label
- x86_get_label(p
) - 4);
446 void x86_call( struct x86_function
*p
, struct x86_reg reg
)
450 emit_modrm_noreg(p
, 2, reg
);
454 void x86_mov_reg_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
457 assert(dst
.file
== file_REG32
);
458 assert(dst
.mod
== mod_REG
);
459 emit_1ub(p
, 0xb8 + dst
.idx
);
463 void x86_mov_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
466 if(dst
.mod
== mod_REG
)
467 x86_mov_reg_imm(p
, dst
, imm
);
471 emit_modrm_noreg(p
, 0, dst
);
476 void x86_mov16_imm( struct x86_function
*p
, struct x86_reg dst
, uint16_t imm
)
480 if(dst
.mod
== mod_REG
)
482 emit_1ub(p
, 0xb8 + dst
.idx
);
483 emit_2ub(p
, imm
& 0xff, imm
>> 8);
488 emit_modrm_noreg(p
, 0, dst
);
489 emit_2ub(p
, imm
& 0xff, imm
>> 8);
493 void x86_mov8_imm( struct x86_function
*p
, struct x86_reg dst
, uint8_t imm
)
496 if(dst
.mod
== mod_REG
)
498 emit_1ub(p
, 0xb0 + dst
.idx
);
504 emit_modrm_noreg(p
, 0, dst
);
510 * Immediate group 1 instructions.
513 x86_group1_imm( struct x86_function
*p
,
514 unsigned op
, struct x86_reg dst
, int imm
)
516 assert(dst
.file
== file_REG32
);
517 assert(dst
.mod
== mod_REG
);
518 if(-0x80 <= imm
&& imm
< 0x80) {
520 emit_modrm_noreg(p
, op
, dst
);
521 emit_1b(p
, (char)imm
);
525 emit_modrm_noreg(p
, op
, dst
);
530 void x86_add_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
533 x86_group1_imm(p
, 0, dst
, imm
);
536 void x86_or_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
539 x86_group1_imm(p
, 1, dst
, imm
);
542 void x86_and_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
545 x86_group1_imm(p
, 4, dst
, imm
);
548 void x86_sub_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
551 x86_group1_imm(p
, 5, dst
, imm
);
554 void x86_xor_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
557 x86_group1_imm(p
, 6, dst
, imm
);
560 void x86_cmp_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
563 x86_group1_imm(p
, 7, dst
, imm
);
567 void x86_push( struct x86_function
*p
,
571 if (reg
.mod
== mod_REG
)
572 emit_1ub(p
, 0x50 + reg
.idx
);
576 emit_modrm_noreg(p
, 6, reg
);
580 p
->stack_offset
+= sizeof(void*);
583 void x86_push_imm32( struct x86_function
*p
,
590 p
->stack_offset
+= sizeof(void*);
594 void x86_pop( struct x86_function
*p
,
598 assert(reg
.mod
== mod_REG
);
599 emit_1ub(p
, 0x58 + reg
.idx
);
600 p
->stack_offset
-= sizeof(void*);
603 void x86_inc( struct x86_function
*p
,
607 if(x86_target(p
) == X86_32
&& reg
.mod
== mod_REG
)
609 emit_1ub(p
, 0x40 + reg
.idx
);
613 emit_modrm_noreg(p
, 0, reg
);
616 void x86_dec( struct x86_function
*p
,
620 if(x86_target(p
) == X86_32
&& reg
.mod
== mod_REG
)
622 emit_1ub(p
, 0x48 + reg
.idx
);
626 emit_modrm_noreg(p
, 1, reg
);
629 void x86_ret( struct x86_function
*p
)
632 assert(p
->stack_offset
== 0);
636 void x86_retw( struct x86_function
*p
, unsigned short imm
)
639 emit_3ub(p
, 0xc2, imm
& 0xff, (imm
>> 8) & 0xff);
642 void x86_sahf( struct x86_function
*p
)
648 void x86_mov( struct x86_function
*p
,
653 /* special hack for reading arguments until we support x86-64 registers everywhere */
654 if(src
.mod
== mod_REG
&& dst
.mod
== mod_REG
&& (src
.idx
>= 8 || dst
.idx
>= 8))
669 emit_op_modrm( p
, 0x8b, 0x89, dst
, src
);
672 void x86_mov16( struct x86_function
*p
,
678 emit_op_modrm( p
, 0x8b, 0x89, dst
, src
);
681 void x86_mov8( struct x86_function
*p
,
686 emit_op_modrm( p
, 0x8a, 0x88, dst
, src
);
689 void x64_mov64( struct x86_function
*p
,
695 assert(x86_target(p
) != X86_32
);
697 /* special hack for reading arguments until we support x86-64 registers everywhere */
698 if(src
.mod
== mod_REG
&& dst
.mod
== mod_REG
&& (src
.idx
>= 8 || dst
.idx
>= 8))
712 emit_op_modrm( p
, 0x8b, 0x89, dst
, src
);
715 void x86_movzx8(struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
718 emit_2ub(p
, 0x0f, 0xb6);
719 emit_modrm(p
, dst
, src
);
722 void x86_movzx16(struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
725 emit_2ub(p
, 0x0f, 0xb7);
726 emit_modrm(p
, dst
, src
);
729 void x86_xor( struct x86_function
*p
,
734 emit_op_modrm( p
, 0x33, 0x31, dst
, src
);
737 void x86_cmp( struct x86_function
*p
,
742 emit_op_modrm( p
, 0x3b, 0x39, dst
, src
);
745 void x86_lea( struct x86_function
*p
,
751 emit_modrm( p
, dst
, src
);
754 void x86_test( struct x86_function
*p
,
760 emit_modrm( p
, dst
, src
);
763 void x86_add( struct x86_function
*p
,
768 emit_op_modrm(p
, 0x03, 0x01, dst
, src
);
771 /* Calculate EAX * src, results in EDX:EAX.
773 void x86_mul( struct x86_function
*p
,
778 emit_modrm_noreg(p
, 4, src
);
782 void x86_imul( struct x86_function
*p
,
787 emit_2ub(p
, X86_TWOB
, 0xAF);
788 emit_modrm(p
, dst
, src
);
792 void x86_sub( struct x86_function
*p
,
797 emit_op_modrm(p
, 0x2b, 0x29, dst
, src
);
800 void x86_or( struct x86_function
*p
,
805 emit_op_modrm( p
, 0x0b, 0x09, dst
, src
);
808 void x86_and( struct x86_function
*p
,
813 emit_op_modrm( p
, 0x23, 0x21, dst
, src
);
816 void x86_div( struct x86_function
*p
,
819 assert(src
.file
== file_REG32
&& src
.mod
== mod_REG
);
820 emit_op_modrm(p
, 0xf7, 0, x86_make_reg(file_REG32
, 6), src
);
823 void x86_bswap( struct x86_function
*p
, struct x86_reg reg
)
826 assert(reg
.file
== file_REG32
);
827 assert(reg
.mod
== mod_REG
);
828 emit_2ub(p
, 0x0f, 0xc8 + reg
.idx
);
831 void x86_shr_imm( struct x86_function
*p
, struct x86_reg reg
, unsigned imm
)
837 emit_modrm_noreg(p
, 5, reg
);
842 emit_modrm_noreg(p
, 5, reg
);
847 void x86_sar_imm( struct x86_function
*p
, struct x86_reg reg
, unsigned imm
)
853 emit_modrm_noreg(p
, 7, reg
);
858 emit_modrm_noreg(p
, 7, reg
);
863 void x86_shl_imm( struct x86_function
*p
, struct x86_reg reg
, unsigned imm
)
869 emit_modrm_noreg(p
, 4, reg
);
874 emit_modrm_noreg(p
, 4, reg
);
880 /***********************************************************************
884 void sse_prefetchnta( struct x86_function
*p
, struct x86_reg ptr
)
887 assert(ptr
.mod
!= mod_REG
);
888 emit_2ub(p
, 0x0f, 0x18);
889 emit_modrm_noreg(p
, 0, ptr
);
892 void sse_prefetch0( struct x86_function
*p
, struct x86_reg ptr
)
895 assert(ptr
.mod
!= mod_REG
);
896 emit_2ub(p
, 0x0f, 0x18);
897 emit_modrm_noreg(p
, 1, ptr
);
900 void sse_prefetch1( struct x86_function
*p
, struct x86_reg ptr
)
903 assert(ptr
.mod
!= mod_REG
);
904 emit_2ub(p
, 0x0f, 0x18);
905 emit_modrm_noreg(p
, 2, ptr
);
908 void sse_movntps( struct x86_function
*p
,
914 assert(dst
.mod
!= mod_REG
);
915 assert(src
.mod
== mod_REG
);
916 emit_2ub(p
, 0x0f, 0x2b);
917 emit_modrm(p
, src
, dst
);
923 void sse_movss( struct x86_function
*p
,
928 emit_2ub(p
, 0xF3, X86_TWOB
);
929 emit_op_modrm( p
, 0x10, 0x11, dst
, src
);
932 void sse_movaps( struct x86_function
*p
,
937 emit_1ub(p
, X86_TWOB
);
938 emit_op_modrm( p
, 0x28, 0x29, dst
, src
);
941 void sse_movups( struct x86_function
*p
,
946 emit_1ub(p
, X86_TWOB
);
947 emit_op_modrm( p
, 0x10, 0x11, dst
, src
);
950 void sse_movhps( struct x86_function
*p
,
955 assert(dst
.mod
!= mod_REG
|| src
.mod
!= mod_REG
);
956 emit_1ub(p
, X86_TWOB
);
957 emit_op_modrm( p
, 0x16, 0x17, dst
, src
); /* cf movlhps */
960 void sse_movlps( struct x86_function
*p
,
965 assert(dst
.mod
!= mod_REG
|| src
.mod
!= mod_REG
);
966 emit_1ub(p
, X86_TWOB
);
967 emit_op_modrm( p
, 0x12, 0x13, dst
, src
); /* cf movhlps */
970 void sse_maxps( struct x86_function
*p
,
975 emit_2ub(p
, X86_TWOB
, 0x5F);
976 emit_modrm( p
, dst
, src
);
979 void sse_maxss( struct x86_function
*p
,
984 emit_3ub(p
, 0xF3, X86_TWOB
, 0x5F);
985 emit_modrm( p
, dst
, src
);
988 void sse_divss( struct x86_function
*p
,
993 emit_3ub(p
, 0xF3, X86_TWOB
, 0x5E);
994 emit_modrm( p
, dst
, src
);
997 void sse_minps( struct x86_function
*p
,
1001 DUMP_RR( dst
, src
);
1002 emit_2ub(p
, X86_TWOB
, 0x5D);
1003 emit_modrm( p
, dst
, src
);
1006 void sse_subps( struct x86_function
*p
,
1008 struct x86_reg src
)
1010 DUMP_RR( dst
, src
);
1011 emit_2ub(p
, X86_TWOB
, 0x5C);
1012 emit_modrm( p
, dst
, src
);
1015 void sse_mulps( struct x86_function
*p
,
1017 struct x86_reg src
)
1019 DUMP_RR( dst
, src
);
1020 emit_2ub(p
, X86_TWOB
, 0x59);
1021 emit_modrm( p
, dst
, src
);
1024 void sse_mulss( struct x86_function
*p
,
1026 struct x86_reg src
)
1028 DUMP_RR( dst
, src
);
1029 emit_3ub(p
, 0xF3, X86_TWOB
, 0x59);
1030 emit_modrm( p
, dst
, src
);
1033 void sse_addps( struct x86_function
*p
,
1035 struct x86_reg src
)
1037 DUMP_RR( dst
, src
);
1038 emit_2ub(p
, X86_TWOB
, 0x58);
1039 emit_modrm( p
, dst
, src
);
1042 void sse_addss( struct x86_function
*p
,
1044 struct x86_reg src
)
1046 DUMP_RR( dst
, src
);
1047 emit_3ub(p
, 0xF3, X86_TWOB
, 0x58);
1048 emit_modrm( p
, dst
, src
);
1051 void sse_andnps( struct x86_function
*p
,
1053 struct x86_reg src
)
1055 DUMP_RR( dst
, src
);
1056 emit_2ub(p
, X86_TWOB
, 0x55);
1057 emit_modrm( p
, dst
, src
);
1060 void sse_andps( struct x86_function
*p
,
1062 struct x86_reg src
)
1064 DUMP_RR( dst
, src
);
1065 emit_2ub(p
, X86_TWOB
, 0x54);
1066 emit_modrm( p
, dst
, src
);
1069 void sse_rsqrtps( struct x86_function
*p
,
1071 struct x86_reg src
)
1073 DUMP_RR( dst
, src
);
1074 emit_2ub(p
, X86_TWOB
, 0x52);
1075 emit_modrm( p
, dst
, src
);
1078 void sse_rsqrtss( struct x86_function
*p
,
1080 struct x86_reg src
)
1082 DUMP_RR( dst
, src
);
1083 emit_3ub(p
, 0xF3, X86_TWOB
, 0x52);
1084 emit_modrm( p
, dst
, src
);
1088 void sse_movhlps( struct x86_function
*p
,
1090 struct x86_reg src
)
1092 DUMP_RR( dst
, src
);
1093 assert(dst
.mod
== mod_REG
&& src
.mod
== mod_REG
);
1094 emit_2ub(p
, X86_TWOB
, 0x12);
1095 emit_modrm( p
, dst
, src
);
1098 void sse_movlhps( struct x86_function
*p
,
1100 struct x86_reg src
)
1102 DUMP_RR( dst
, src
);
1103 assert(dst
.mod
== mod_REG
&& src
.mod
== mod_REG
);
1104 emit_2ub(p
, X86_TWOB
, 0x16);
1105 emit_modrm( p
, dst
, src
);
1108 void sse_orps( struct x86_function
*p
,
1110 struct x86_reg src
)
1112 DUMP_RR( dst
, src
);
1113 emit_2ub(p
, X86_TWOB
, 0x56);
1114 emit_modrm( p
, dst
, src
);
1117 void sse_xorps( struct x86_function
*p
,
1119 struct x86_reg src
)
1121 DUMP_RR( dst
, src
);
1122 emit_2ub(p
, X86_TWOB
, 0x57);
1123 emit_modrm( p
, dst
, src
);
1126 void sse_cvtps2pi( struct x86_function
*p
,
1128 struct x86_reg src
)
1130 DUMP_RR( dst
, src
);
1131 assert(dst
.file
== file_MMX
&&
1132 (src
.file
== file_XMM
|| src
.mod
!= mod_REG
));
1136 emit_2ub(p
, X86_TWOB
, 0x2d);
1137 emit_modrm( p
, dst
, src
);
1140 void sse2_cvtdq2ps( struct x86_function
*p
,
1142 struct x86_reg src
)
1144 DUMP_RR( dst
, src
);
1145 emit_2ub(p
, X86_TWOB
, 0x5b);
1146 emit_modrm( p
, dst
, src
);
1150 /* Shufps can also be used to implement a reduced swizzle when dest ==
1153 void sse_shufps( struct x86_function
*p
,
1158 DUMP_RRI( dst
, src
, shuf
);
1159 emit_2ub(p
, X86_TWOB
, 0xC6);
1160 emit_modrm(p
, dst
, src
);
1164 void sse_unpckhps( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1166 DUMP_RR( dst
, src
);
1167 emit_2ub( p
, X86_TWOB
, 0x15 );
1168 emit_modrm( p
, dst
, src
);
1171 void sse_unpcklps( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1173 DUMP_RR( dst
, src
);
1174 emit_2ub( p
, X86_TWOB
, 0x14 );
1175 emit_modrm( p
, dst
, src
);
1178 void sse_cmpps( struct x86_function
*p
,
1183 DUMP_RRI( dst
, src
, cc
);
1184 emit_2ub(p
, X86_TWOB
, 0xC2);
1185 emit_modrm(p
, dst
, src
);
1189 void sse_pmovmskb( struct x86_function
*p
,
1193 DUMP_RR( dst
, src
);
1194 emit_3ub(p
, 0x66, X86_TWOB
, 0xD7);
1195 emit_modrm(p
, dst
, src
);
1198 void sse_movmskps( struct x86_function
*p
,
1202 DUMP_RR( dst
, src
);
1203 emit_2ub(p
, X86_TWOB
, 0x50);
1204 emit_modrm(p
, dst
, src
);
1207 /***********************************************************************
1211 void sse2_movd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1214 emit_2ub(p
, 0x66, 0x0f);
1215 if(dst
.mod
== mod_REG
&& dst
.file
== file_REG32
)
1218 emit_modrm(p
, src
, dst
);
1222 emit_op_modrm(p
, 0x6e, 0x7e, dst
, src
);
1226 void sse2_movq( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1231 emit_3ub(p
, 0xf3, 0x0f, 0x7e);
1232 emit_modrm(p
, dst
, src
);
1237 assert(src
.mod
== mod_REG
);
1238 emit_3ub(p
, 0x66, 0x0f, 0xd6);
1239 emit_modrm(p
, src
, dst
);
1247 void sse2_movdqu( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1250 emit_2ub(p
, 0xf3, 0x0f);
1251 emit_op_modrm(p
, 0x6f, 0x7f, dst
, src
);
1254 void sse2_movdqa( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1257 emit_2ub(p
, 0x66, 0x0f);
1258 emit_op_modrm(p
, 0x6f, 0x7f, dst
, src
);
1261 void sse2_movsd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1264 emit_2ub(p
, 0xf2, 0x0f);
1265 emit_op_modrm(p
, 0x10, 0x11, dst
, src
);
1268 void sse2_movupd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1271 emit_2ub(p
, 0x66, 0x0f);
1272 emit_op_modrm(p
, 0x10, 0x11, dst
, src
);
1275 void sse2_movapd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1278 emit_2ub(p
, 0x66, 0x0f);
1279 emit_op_modrm(p
, 0x28, 0x29, dst
, src
);
1283 * Perform a reduced swizzle:
1285 void sse2_pshufd( struct x86_function
*p
,
1290 DUMP_RRI( dst
, src
, shuf
);
1291 emit_3ub(p
, 0x66, X86_TWOB
, 0x70);
1292 emit_modrm(p
, dst
, src
);
1296 void sse2_pshuflw( struct x86_function
*p
,
1301 DUMP_RRI( dst
, src
, shuf
);
1302 emit_3ub(p
, 0xf2, X86_TWOB
, 0x70);
1303 emit_modrm(p
, dst
, src
);
1307 void sse2_pshufhw( struct x86_function
*p
,
1312 DUMP_RRI( dst
, src
, shuf
);
1313 emit_3ub(p
, 0xf3, X86_TWOB
, 0x70);
1314 emit_modrm(p
, dst
, src
);
1318 void sse2_cvttps2dq( struct x86_function
*p
,
1320 struct x86_reg src
)
1322 DUMP_RR( dst
, src
);
1323 emit_3ub( p
, 0xF3, X86_TWOB
, 0x5B );
1324 emit_modrm( p
, dst
, src
);
1327 void sse2_cvtps2dq( struct x86_function
*p
,
1329 struct x86_reg src
)
1331 DUMP_RR( dst
, src
);
1332 emit_3ub(p
, 0x66, X86_TWOB
, 0x5B);
1333 emit_modrm( p
, dst
, src
);
1336 void sse2_cvtsd2ss( struct x86_function
*p
,
1338 struct x86_reg src
)
1340 DUMP_RR( dst
, src
);
1341 emit_3ub(p
, 0xf2, 0x0f, 0x5a);
1342 emit_modrm( p
, dst
, src
);
1345 void sse2_cvtpd2ps( struct x86_function
*p
,
1347 struct x86_reg src
)
1349 DUMP_RR( dst
, src
);
1350 emit_3ub(p
, 0x66, 0x0f, 0x5a);
1351 emit_modrm( p
, dst
, src
);
1354 void sse2_packssdw( struct x86_function
*p
,
1356 struct x86_reg src
)
1358 DUMP_RR( dst
, src
);
1359 emit_3ub(p
, 0x66, X86_TWOB
, 0x6B);
1360 emit_modrm( p
, dst
, src
);
1363 void sse2_packsswb( struct x86_function
*p
,
1365 struct x86_reg src
)
1367 DUMP_RR( dst
, src
);
1368 emit_3ub(p
, 0x66, X86_TWOB
, 0x63);
1369 emit_modrm( p
, dst
, src
);
1372 void sse2_packuswb( struct x86_function
*p
,
1374 struct x86_reg src
)
1376 DUMP_RR( dst
, src
);
1377 emit_3ub(p
, 0x66, X86_TWOB
, 0x67);
1378 emit_modrm( p
, dst
, src
);
1381 void sse2_punpcklbw( struct x86_function
*p
,
1383 struct x86_reg src
)
1385 DUMP_RR( dst
, src
);
1386 emit_3ub(p
, 0x66, X86_TWOB
, 0x60);
1387 emit_modrm( p
, dst
, src
);
1390 void sse2_punpcklwd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1392 DUMP_RR( dst
, src
);
1393 emit_3ub(p
, 0x66, 0x0f, 0x61);
1394 emit_modrm( p
, dst
, src
);
1397 void sse2_punpckldq( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1399 DUMP_RR( dst
, src
);
1400 emit_3ub(p
, 0x66, 0x0f, 0x62);
1401 emit_modrm( p
, dst
, src
);
1404 void sse2_punpcklqdq( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1406 DUMP_RR( dst
, src
);
1407 emit_3ub(p
, 0x66, 0x0f, 0x6c);
1408 emit_modrm( p
, dst
, src
);
1411 void sse2_psllw_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1414 emit_3ub(p
, 0x66, 0x0f, 0x71);
1415 emit_modrm_noreg(p
, 6, dst
);
1419 void sse2_pslld_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1422 emit_3ub(p
, 0x66, 0x0f, 0x72);
1423 emit_modrm_noreg(p
, 6, dst
);
1427 void sse2_psllq_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1430 emit_3ub(p
, 0x66, 0x0f, 0x73);
1431 emit_modrm_noreg(p
, 6, dst
);
1435 void sse2_psrlw_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1438 emit_3ub(p
, 0x66, 0x0f, 0x71);
1439 emit_modrm_noreg(p
, 2, dst
);
1443 void sse2_psrld_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1446 emit_3ub(p
, 0x66, 0x0f, 0x72);
1447 emit_modrm_noreg(p
, 2, dst
);
1451 void sse2_psrlq_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1454 emit_3ub(p
, 0x66, 0x0f, 0x73);
1455 emit_modrm_noreg(p
, 2, dst
);
1459 void sse2_psraw_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1462 emit_3ub(p
, 0x66, 0x0f, 0x71);
1463 emit_modrm_noreg(p
, 4, dst
);
1467 void sse2_psrad_imm( struct x86_function
*p
, struct x86_reg dst
, unsigned imm
)
1470 emit_3ub(p
, 0x66, 0x0f, 0x72);
1471 emit_modrm_noreg(p
, 4, dst
);
1475 void sse2_por( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1478 emit_3ub(p
, 0x66, 0x0f, 0xeb);
1479 emit_modrm(p
, dst
, src
);
1482 void sse2_rcpps( struct x86_function
*p
,
1484 struct x86_reg src
)
1486 DUMP_RR( dst
, src
);
1487 emit_2ub(p
, X86_TWOB
, 0x53);
1488 emit_modrm( p
, dst
, src
);
1491 void sse2_rcpss( struct x86_function
*p
,
1493 struct x86_reg src
)
1495 DUMP_RR( dst
, src
);
1496 emit_3ub(p
, 0xF3, X86_TWOB
, 0x53);
1497 emit_modrm( p
, dst
, src
);
1500 /***********************************************************************
1503 static void note_x87_pop( struct x86_function
*p
)
1506 assert(p
->x87_stack
>= 0);
1509 static void note_x87_push( struct x86_function
*p
)
1512 assert(p
->x87_stack
<= 7);
1515 void x87_assert_stack_empty( struct x86_function
*p
)
1517 assert (p
->x87_stack
== 0);
1521 void x87_fist( struct x86_function
*p
, struct x86_reg dst
)
1525 emit_modrm_noreg(p
, 2, dst
);
1528 void x87_fistp( struct x86_function
*p
, struct x86_reg dst
)
1532 emit_modrm_noreg(p
, 3, dst
);
1536 void x87_fild( struct x86_function
*p
, struct x86_reg arg
)
1540 emit_modrm_noreg(p
, 0, arg
);
1544 void x87_fldz( struct x86_function
*p
)
1547 emit_2ub(p
, 0xd9, 0xee);
1552 void x87_fldcw( struct x86_function
*p
, struct x86_reg arg
)
1555 assert(arg
.file
== file_REG32
);
1556 assert(arg
.mod
!= mod_REG
);
1558 emit_modrm_noreg(p
, 5, arg
);
1561 void x87_fld1( struct x86_function
*p
)
1564 emit_2ub(p
, 0xd9, 0xe8);
1568 void x87_fldl2e( struct x86_function
*p
)
1571 emit_2ub(p
, 0xd9, 0xea);
1575 void x87_fldln2( struct x86_function
*p
)
1578 emit_2ub(p
, 0xd9, 0xed);
1582 void x87_fwait( struct x86_function
*p
)
1588 void x87_fnclex( struct x86_function
*p
)
1591 emit_2ub(p
, 0xdb, 0xe2);
1594 void x87_fclex( struct x86_function
*p
)
1600 void x87_fcmovb( struct x86_function
*p
, struct x86_reg arg
)
1603 assert(arg
.file
== file_x87
);
1604 emit_2ub(p
, 0xda, 0xc0+arg
.idx
);
1607 void x87_fcmove( struct x86_function
*p
, struct x86_reg arg
)
1610 assert(arg
.file
== file_x87
);
1611 emit_2ub(p
, 0xda, 0xc8+arg
.idx
);
1614 void x87_fcmovbe( struct x86_function
*p
, struct x86_reg arg
)
1617 assert(arg
.file
== file_x87
);
1618 emit_2ub(p
, 0xda, 0xd0+arg
.idx
);
1621 void x87_fcmovnb( struct x86_function
*p
, struct x86_reg arg
)
1624 assert(arg
.file
== file_x87
);
1625 emit_2ub(p
, 0xdb, 0xc0+arg
.idx
);
1628 void x87_fcmovne( struct x86_function
*p
, struct x86_reg arg
)
1631 assert(arg
.file
== file_x87
);
1632 emit_2ub(p
, 0xdb, 0xc8+arg
.idx
);
1635 void x87_fcmovnbe( struct x86_function
*p
, struct x86_reg arg
)
1638 assert(arg
.file
== file_x87
);
1639 emit_2ub(p
, 0xdb, 0xd0+arg
.idx
);
1644 static void x87_arith_op( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
,
1645 unsigned char dst0ub0
,
1646 unsigned char dst0ub1
,
1647 unsigned char arg0ub0
,
1648 unsigned char arg0ub1
,
1649 unsigned char argmem_noreg
)
1651 assert(dst
.file
== file_x87
);
1653 if (arg
.file
== file_x87
) {
1655 emit_2ub(p
, dst0ub0
, dst0ub1
+arg
.idx
);
1656 else if (arg
.idx
== 0)
1657 emit_2ub(p
, arg0ub0
, arg0ub1
+arg
.idx
);
1661 else if (dst
.idx
== 0) {
1662 assert(arg
.file
== file_REG32
);
1664 emit_modrm_noreg(p
, argmem_noreg
, arg
);
1670 void x87_fmul( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1672 DUMP_RR( dst
, src
);
1673 x87_arith_op(p
, dst
, src
,
1679 void x87_fsub( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1681 DUMP_RR( dst
, src
);
1682 x87_arith_op(p
, dst
, src
,
1688 void x87_fsubr( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1690 DUMP_RR( dst
, src
);
1691 x87_arith_op(p
, dst
, src
,
1697 void x87_fadd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1699 DUMP_RR( dst
, src
);
1700 x87_arith_op(p
, dst
, src
,
1706 void x87_fdiv( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1708 DUMP_RR( dst
, src
);
1709 x87_arith_op(p
, dst
, src
,
1715 void x87_fdivr( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg src
)
1717 DUMP_RR( dst
, src
);
1718 x87_arith_op(p
, dst
, src
,
1724 void x87_fmulp( struct x86_function
*p
, struct x86_reg dst
)
1727 assert(dst
.file
== file_x87
);
1728 assert(dst
.idx
>= 1);
1729 emit_2ub(p
, 0xde, 0xc8+dst
.idx
);
1733 void x87_fsubp( struct x86_function
*p
, struct x86_reg dst
)
1736 assert(dst
.file
== file_x87
);
1737 assert(dst
.idx
>= 1);
1738 emit_2ub(p
, 0xde, 0xe8+dst
.idx
);
1742 void x87_fsubrp( struct x86_function
*p
, struct x86_reg dst
)
1745 assert(dst
.file
== file_x87
);
1746 assert(dst
.idx
>= 1);
1747 emit_2ub(p
, 0xde, 0xe0+dst
.idx
);
1751 void x87_faddp( struct x86_function
*p
, struct x86_reg dst
)
1754 assert(dst
.file
== file_x87
);
1755 assert(dst
.idx
>= 1);
1756 emit_2ub(p
, 0xde, 0xc0+dst
.idx
);
1760 void x87_fdivp( struct x86_function
*p
, struct x86_reg dst
)
1763 assert(dst
.file
== file_x87
);
1764 assert(dst
.idx
>= 1);
1765 emit_2ub(p
, 0xde, 0xf8+dst
.idx
);
1769 void x87_fdivrp( struct x86_function
*p
, struct x86_reg dst
)
1772 assert(dst
.file
== file_x87
);
1773 assert(dst
.idx
>= 1);
1774 emit_2ub(p
, 0xde, 0xf0+dst
.idx
);
1778 void x87_ftst( struct x86_function
*p
)
1781 emit_2ub(p
, 0xd9, 0xe4);
1784 void x87_fucom( struct x86_function
*p
, struct x86_reg arg
)
1787 assert(arg
.file
== file_x87
);
1788 emit_2ub(p
, 0xdd, 0xe0+arg
.idx
);
1791 void x87_fucomp( struct x86_function
*p
, struct x86_reg arg
)
1794 assert(arg
.file
== file_x87
);
1795 emit_2ub(p
, 0xdd, 0xe8+arg
.idx
);
1799 void x87_fucompp( struct x86_function
*p
)
1802 emit_2ub(p
, 0xda, 0xe9);
1803 note_x87_pop(p
); /* pop twice */
1804 note_x87_pop(p
); /* pop twice */
1807 void x87_fxch( struct x86_function
*p
, struct x86_reg arg
)
1810 assert(arg
.file
== file_x87
);
1811 emit_2ub(p
, 0xd9, 0xc8+arg
.idx
);
1814 void x87_fabs( struct x86_function
*p
)
1817 emit_2ub(p
, 0xd9, 0xe1);
1820 void x87_fchs( struct x86_function
*p
)
1823 emit_2ub(p
, 0xd9, 0xe0);
1826 void x87_fcos( struct x86_function
*p
)
1829 emit_2ub(p
, 0xd9, 0xff);
1833 void x87_fprndint( struct x86_function
*p
)
1836 emit_2ub(p
, 0xd9, 0xfc);
1839 void x87_fscale( struct x86_function
*p
)
1842 emit_2ub(p
, 0xd9, 0xfd);
1845 void x87_fsin( struct x86_function
*p
)
1848 emit_2ub(p
, 0xd9, 0xfe);
1851 void x87_fsincos( struct x86_function
*p
)
1854 emit_2ub(p
, 0xd9, 0xfb);
1857 void x87_fsqrt( struct x86_function
*p
)
1860 emit_2ub(p
, 0xd9, 0xfa);
1863 void x87_fxtract( struct x86_function
*p
)
1866 emit_2ub(p
, 0xd9, 0xf4);
1871 * Restrictions: -1.0 <= st0 <= 1.0
1873 void x87_f2xm1( struct x86_function
*p
)
1876 emit_2ub(p
, 0xd9, 0xf0);
1879 /* st1 = st1 * log2(st0);
1882 void x87_fyl2x( struct x86_function
*p
)
1885 emit_2ub(p
, 0xd9, 0xf1);
1889 /* st1 = st1 * log2(st0 + 1.0);
1892 * A fast operation, with restrictions: -.29 < st0 < .29
1894 void x87_fyl2xp1( struct x86_function
*p
)
1897 emit_2ub(p
, 0xd9, 0xf9);
1902 void x87_fld( struct x86_function
*p
, struct x86_reg arg
)
1905 if (arg
.file
== file_x87
)
1906 emit_2ub(p
, 0xd9, 0xc0 + arg
.idx
);
1909 emit_modrm_noreg(p
, 0, arg
);
1914 void x87_fst( struct x86_function
*p
, struct x86_reg dst
)
1917 if (dst
.file
== file_x87
)
1918 emit_2ub(p
, 0xdd, 0xd0 + dst
.idx
);
1921 emit_modrm_noreg(p
, 2, dst
);
1925 void x87_fstp( struct x86_function
*p
, struct x86_reg dst
)
1928 if (dst
.file
== file_x87
)
1929 emit_2ub(p
, 0xdd, 0xd8 + dst
.idx
);
1932 emit_modrm_noreg(p
, 3, dst
);
1937 void x87_fpop( struct x86_function
*p
)
1939 x87_fstp( p
, x86_make_reg( file_x87
, 0 ));
1943 void x87_fcom( struct x86_function
*p
, struct x86_reg dst
)
1946 if (dst
.file
== file_x87
)
1947 emit_2ub(p
, 0xd8, 0xd0 + dst
.idx
);
1950 emit_modrm_noreg(p
, 2, dst
);
1955 void x87_fcomp( struct x86_function
*p
, struct x86_reg dst
)
1958 if (dst
.file
== file_x87
)
1959 emit_2ub(p
, 0xd8, 0xd8 + dst
.idx
);
1962 emit_modrm_noreg(p
, 3, dst
);
1967 void x87_fcomi( struct x86_function
*p
, struct x86_reg arg
)
1970 emit_2ub(p
, 0xdb, 0xf0+arg
.idx
);
1973 void x87_fcomip( struct x86_function
*p
, struct x86_reg arg
)
1976 emit_2ub(p
, 0xdb, 0xf0+arg
.idx
);
1981 void x87_fnstsw( struct x86_function
*p
, struct x86_reg dst
)
1984 assert(dst
.file
== file_REG32
);
1986 if (dst
.idx
== reg_AX
&&
1988 emit_2ub(p
, 0xdf, 0xe0);
1991 emit_modrm_noreg(p
, 7, dst
);
1996 void x87_fnstcw( struct x86_function
*p
, struct x86_reg dst
)
1999 assert(dst
.file
== file_REG32
);
2001 emit_1ub(p
, 0x9b); /* WAIT -- needed? */
2003 emit_modrm_noreg(p
, 7, dst
);
2009 /***********************************************************************
2013 void mmx_emms( struct x86_function
*p
)
2016 assert(p
->need_emms
);
2017 emit_2ub(p
, 0x0f, 0x77);
2021 void mmx_packssdw( struct x86_function
*p
,
2023 struct x86_reg src
)
2025 DUMP_RR( dst
, src
);
2026 assert(dst
.file
== file_MMX
&&
2027 (src
.file
== file_MMX
|| src
.mod
!= mod_REG
));
2031 emit_2ub(p
, X86_TWOB
, 0x6b);
2032 emit_modrm( p
, dst
, src
);
2035 void mmx_packuswb( struct x86_function
*p
,
2037 struct x86_reg src
)
2039 DUMP_RR( dst
, src
);
2040 assert(dst
.file
== file_MMX
&&
2041 (src
.file
== file_MMX
|| src
.mod
!= mod_REG
));
2045 emit_2ub(p
, X86_TWOB
, 0x67);
2046 emit_modrm( p
, dst
, src
);
2049 void mmx_movd( struct x86_function
*p
,
2051 struct x86_reg src
)
2053 DUMP_RR( dst
, src
);
2055 emit_1ub(p
, X86_TWOB
);
2056 emit_op_modrm( p
, 0x6e, 0x7e, dst
, src
);
2059 void mmx_movq( struct x86_function
*p
,
2061 struct x86_reg src
)
2063 DUMP_RR( dst
, src
);
2065 emit_1ub(p
, X86_TWOB
);
2066 emit_op_modrm( p
, 0x6f, 0x7f, dst
, src
);
2070 /***********************************************************************
2075 void x86_cdecl_caller_push_regs( struct x86_function
*p
)
2077 x86_push(p
, x86_make_reg(file_REG32
, reg_AX
));
2078 x86_push(p
, x86_make_reg(file_REG32
, reg_CX
));
2079 x86_push(p
, x86_make_reg(file_REG32
, reg_DX
));
2082 void x86_cdecl_caller_pop_regs( struct x86_function
*p
)
2084 x86_pop(p
, x86_make_reg(file_REG32
, reg_DX
));
2085 x86_pop(p
, x86_make_reg(file_REG32
, reg_CX
));
2086 x86_pop(p
, x86_make_reg(file_REG32
, reg_AX
));
2090 struct x86_reg
x86_fn_arg( struct x86_function
*p
,
2093 switch(x86_target(p
))
2095 case X86_64_WIN64_ABI
:
2096 /* Microsoft uses a different calling convention than the rest of the world */
2100 return x86_make_reg(file_REG32
, reg_CX
);
2102 return x86_make_reg(file_REG32
, reg_DX
);
2104 return x86_make_reg(file_REG32
, reg_R8
);
2106 return x86_make_reg(file_REG32
, reg_R9
);
2108 return x86_make_disp(x86_make_reg(file_REG32
, reg_SP
),
2109 p
->stack_offset
+ (arg
- 4) * 8); /* ??? */
2111 case X86_64_STD_ABI
:
2115 return x86_make_reg(file_REG32
, reg_DI
);
2117 return x86_make_reg(file_REG32
, reg_SI
);
2119 return x86_make_reg(file_REG32
, reg_DX
);
2121 return x86_make_reg(file_REG32
, reg_CX
);
2123 return x86_make_reg(file_REG32
, reg_R8
);
2125 return x86_make_reg(file_REG32
, reg_R9
);
2127 return x86_make_disp(x86_make_reg(file_REG32
, reg_SP
),
2128 p
->stack_offset
+ (arg
- 6) * 8); /* ??? */
2131 return x86_make_disp(x86_make_reg(file_REG32
, reg_SP
),
2132 p
->stack_offset
+ arg
* 4); /* ??? */
2138 static void x86_init_func_common( struct x86_function
*p
)
2142 if(util_cpu_caps
.has_mmx
)
2144 if(util_cpu_caps
.has_mmx2
)
2145 p
->caps
|= X86_MMX2
;
2146 if(util_cpu_caps
.has_sse
)
2148 if(util_cpu_caps
.has_sse2
)
2149 p
->caps
|= X86_SSE2
;
2150 if(util_cpu_caps
.has_sse3
)
2151 p
->caps
|= X86_SSE3
;
2152 if(util_cpu_caps
.has_sse4_1
)
2153 p
->caps
|= X86_SSE4_1
;
2158 void x86_init_func( struct x86_function
*p
)
2162 x86_init_func_common(p
);
2165 void x86_init_func_size( struct x86_function
*p
, unsigned code_size
)
2167 p
->size
= code_size
;
2168 p
->store
= rtasm_exec_malloc(code_size
);
2169 if (p
->store
== NULL
) {
2170 p
->store
= p
->error_overflow
;
2172 x86_init_func_common(p
);
2175 void x86_release_func( struct x86_function
*p
)
2177 if (p
->store
&& p
->store
!= p
->error_overflow
)
2178 rtasm_exec_free(p
->store
);
2186 static INLINE x86_func
2187 voidptr_to_x86_func(void *v
)
2193 assert(sizeof(u
.v
) == sizeof(u
.f
));
2199 x86_func
x86_get_func( struct x86_function
*p
)
2202 if (DISASSEM
&& p
->store
)
2203 debug_printf("disassemble %p %p\n", p
->store
, p
->csr
);
2205 if (p
->store
== p
->error_overflow
)
2206 return voidptr_to_x86_func(NULL
);
2208 return voidptr_to_x86_func(p
->store
);
2213 void x86sse_dummy( void );
2215 void x86sse_dummy( void )