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 #if defined(__i386__) || defined(__386__) || defined(i386)
26 #include "pipe/p_compiler.h"
27 #include "pipe/p_debug.h"
28 #include "pipe/p_pointer.h"
30 #include "rtasm_execmem.h"
31 #include "rtasm_x86sse.h"
36 static unsigned char *cptr( void (*label
)() )
38 return (unsigned char *) label
;
42 static void do_realloc( struct x86_function
*p
)
46 p
->store
= rtasm_exec_malloc(p
->size
);
50 uintptr_t used
= pointer_to_uintptr( p
->csr
) - pointer_to_uintptr( p
->store
);
51 unsigned char *tmp
= p
->store
;
53 p
->store
= rtasm_exec_malloc(p
->size
);
54 memcpy(p
->store
, tmp
, used
);
55 p
->csr
= p
->store
+ used
;
60 /* Emit bytes to the instruction stream:
62 static unsigned char *reserve( struct x86_function
*p
, int bytes
)
64 if (p
->csr
+ bytes
- p
->store
> (int) p
->size
)
68 unsigned char *csr
= p
->csr
;
76 static void emit_1b( struct x86_function
*p
, char b0
)
78 char *csr
= (char *)reserve(p
, 1);
82 static void emit_1i( struct x86_function
*p
, int i0
)
84 int *icsr
= (int *)reserve(p
, sizeof(i0
));
88 static void emit_1ub( struct x86_function
*p
, unsigned char b0
)
90 unsigned char *csr
= reserve(p
, 1);
94 static void emit_2ub( struct x86_function
*p
, unsigned char b0
, unsigned char b1
)
96 unsigned char *csr
= reserve(p
, 2);
101 static void emit_3ub( struct x86_function
*p
, unsigned char b0
, unsigned char b1
, unsigned char b2
)
103 unsigned char *csr
= reserve(p
, 3);
110 /* Build a modRM byte + possible displacement. No treatment of SIB
111 * indexing. BZZT - no way to encode an absolute address.
113 static void emit_modrm( struct x86_function
*p
,
115 struct x86_reg regmem
)
117 unsigned char val
= 0;
119 assert(reg
.mod
== mod_REG
);
121 val
|= regmem
.mod
<< 6; /* mod field */
122 val
|= reg
.idx
<< 3; /* reg field */
123 val
|= regmem
.idx
; /* r/m field */
127 /* Oh-oh we've stumbled into the SIB thing.
129 if (regmem
.file
== file_REG32
&&
130 regmem
.idx
== reg_SP
) {
131 emit_1ub(p
, 0x24); /* simplistic! */
134 switch (regmem
.mod
) {
139 emit_1b(p
, (char) regmem
.disp
);
142 emit_1i(p
, regmem
.disp
);
151 static void emit_modrm_noreg( struct x86_function
*p
,
153 struct x86_reg regmem
)
155 struct x86_reg dummy
= x86_make_reg(file_REG32
, op
);
156 emit_modrm(p
, dummy
, regmem
);
159 /* Many x86 instructions have two opcodes to cope with the situations
160 * where the destination is a register or memory reference
161 * respectively. This function selects the correct opcode based on
162 * the arguments presented.
164 static void emit_op_modrm( struct x86_function
*p
,
165 unsigned char op_dst_is_reg
,
166 unsigned char op_dst_is_mem
,
172 emit_1ub(p
, op_dst_is_reg
);
173 emit_modrm(p
, dst
, src
);
178 assert(src
.mod
== mod_REG
);
179 emit_1ub(p
, op_dst_is_mem
);
180 emit_modrm(p
, src
, dst
);
194 /* Create and manipulate registers and regmem values:
196 struct x86_reg
x86_make_reg( enum x86_reg_file file
,
197 enum x86_reg_name idx
)
209 struct x86_reg
x86_make_disp( struct x86_reg reg
,
212 assert(reg
.file
== file_REG32
);
214 if (reg
.mod
== mod_REG
)
220 reg
.mod
= mod_INDIRECT
;
221 else if (reg
.disp
<= 127 && reg
.disp
>= -128)
224 reg
.mod
= mod_DISP32
;
229 struct x86_reg
x86_deref( struct x86_reg reg
)
231 return x86_make_disp(reg
, 0);
234 struct x86_reg
x86_get_base_reg( struct x86_reg reg
)
236 return x86_make_reg( reg
.file
, reg
.idx
);
239 unsigned char *x86_get_label( struct x86_function
*p
)
246 /***********************************************************************
251 void x86_jcc( struct x86_function
*p
,
253 unsigned char *label
)
255 intptr_t offset
= pointer_to_intptr( label
) - (pointer_to_intptr( x86_get_label(p
) ) + 2);
257 if (offset
<= 127 && offset
>= -128) {
258 emit_1ub(p
, 0x70 + cc
);
259 emit_1b(p
, (char) offset
);
262 offset
= pointer_to_intptr( label
) - (pointer_to_intptr( x86_get_label(p
) ) + 6);
263 emit_2ub(p
, 0x0f, 0x80 + cc
);
268 /* Always use a 32bit offset for forward jumps:
270 unsigned char *x86_jcc_forward( struct x86_function
*p
,
273 emit_2ub(p
, 0x0f, 0x80 + cc
);
275 return x86_get_label(p
);
278 unsigned char *x86_jmp_forward( struct x86_function
*p
)
282 return x86_get_label(p
);
285 unsigned char *x86_call_forward( struct x86_function
*p
)
289 return x86_get_label(p
);
292 /* Fixup offset from forward jump:
294 void x86_fixup_fwd_jump( struct x86_function
*p
,
295 unsigned char *fixup
)
297 *(int *)(fixup
- 4) = pointer_to_intptr( x86_get_label(p
) ) - pointer_to_intptr( fixup
);
300 void x86_jmp( struct x86_function
*p
, unsigned char *label
)
303 emit_1i(p
, pointer_to_intptr( label
) - pointer_to_intptr( x86_get_label(p
) ) - 4);
307 /* This doesn't work once we start reallocating & copying the
308 * generated code on buffer fills, because the call is relative to the
311 void x86_call( struct x86_function
*p
, void (*label
)())
314 emit_1i(p
, cptr(label
) - x86_get_label(p
) - 4);
317 void x86_call( struct x86_function
*p
, struct x86_reg reg
)
320 emit_modrm(p
, reg
, reg
);
326 * Temporary. As I need immediate operands, and dont want to mess with the codegen,
327 * I load the immediate into general purpose register and use it.
329 void x86_mov_reg_imm( struct x86_function
*p
, struct x86_reg dst
, int imm
)
331 assert(dst
.mod
== mod_REG
);
332 emit_1ub(p
, 0xb8 + dst
.idx
);
336 void x86_push( struct x86_function
*p
,
339 assert(reg
.mod
== mod_REG
);
340 emit_1ub(p
, 0x50 + reg
.idx
);
341 p
->stack_offset
+= 4;
344 void x86_pop( struct x86_function
*p
,
347 assert(reg
.mod
== mod_REG
);
348 emit_1ub(p
, 0x58 + reg
.idx
);
349 p
->stack_offset
-= 4;
352 void x86_inc( struct x86_function
*p
,
355 assert(reg
.mod
== mod_REG
);
356 emit_1ub(p
, 0x40 + reg
.idx
);
359 void x86_dec( struct x86_function
*p
,
362 assert(reg
.mod
== mod_REG
);
363 emit_1ub(p
, 0x48 + reg
.idx
);
366 void x86_ret( struct x86_function
*p
)
371 void x86_sahf( struct x86_function
*p
)
376 void x86_mov( struct x86_function
*p
,
380 emit_op_modrm( p
, 0x8b, 0x89, dst
, src
);
383 void x86_xor( struct x86_function
*p
,
387 emit_op_modrm( p
, 0x33, 0x31, dst
, src
);
390 void x86_cmp( struct x86_function
*p
,
394 emit_op_modrm( p
, 0x3b, 0x39, dst
, src
);
397 void x86_lea( struct x86_function
*p
,
402 emit_modrm( p
, dst
, src
);
405 void x86_test( struct x86_function
*p
,
410 emit_modrm( p
, dst
, src
);
413 void x86_add( struct x86_function
*p
,
417 emit_op_modrm(p
, 0x03, 0x01, dst
, src
);
420 void x86_mul( struct x86_function
*p
,
423 assert (src
.file
== file_REG32
&& src
.mod
== mod_REG
);
424 emit_op_modrm(p
, 0xf7, 0, x86_make_reg (file_REG32
, reg_SP
), src
);
427 void x86_sub( struct x86_function
*p
,
431 emit_op_modrm(p
, 0x2b, 0x29, dst
, src
);
434 void x86_or( struct x86_function
*p
,
438 emit_op_modrm( p
, 0x0b, 0x09, dst
, src
);
441 void x86_and( struct x86_function
*p
,
445 emit_op_modrm( p
, 0x23, 0x21, dst
, src
);
450 /***********************************************************************
455 void sse_movss( struct x86_function
*p
,
459 emit_2ub(p
, 0xF3, X86_TWOB
);
460 emit_op_modrm( p
, 0x10, 0x11, dst
, src
);
463 void sse_movaps( struct x86_function
*p
,
467 emit_1ub(p
, X86_TWOB
);
468 emit_op_modrm( p
, 0x28, 0x29, dst
, src
);
471 void sse_movups( struct x86_function
*p
,
475 emit_1ub(p
, X86_TWOB
);
476 emit_op_modrm( p
, 0x10, 0x11, dst
, src
);
479 void sse_movhps( struct x86_function
*p
,
483 assert(dst
.mod
!= mod_REG
|| src
.mod
!= mod_REG
);
484 emit_1ub(p
, X86_TWOB
);
485 emit_op_modrm( p
, 0x16, 0x17, dst
, src
); /* cf movlhps */
488 void sse_movlps( struct x86_function
*p
,
492 assert(dst
.mod
!= mod_REG
|| src
.mod
!= mod_REG
);
493 emit_1ub(p
, X86_TWOB
);
494 emit_op_modrm( p
, 0x12, 0x13, dst
, src
); /* cf movhlps */
497 void sse_maxps( struct x86_function
*p
,
501 emit_2ub(p
, X86_TWOB
, 0x5F);
502 emit_modrm( p
, dst
, src
);
505 void sse_maxss( struct x86_function
*p
,
509 emit_3ub(p
, 0xF3, X86_TWOB
, 0x5F);
510 emit_modrm( p
, dst
, src
);
513 void sse_divss( struct x86_function
*p
,
517 emit_3ub(p
, 0xF3, X86_TWOB
, 0x5E);
518 emit_modrm( p
, dst
, src
);
521 void sse_minps( struct x86_function
*p
,
525 emit_2ub(p
, X86_TWOB
, 0x5D);
526 emit_modrm( p
, dst
, src
);
529 void sse_subps( struct x86_function
*p
,
533 emit_2ub(p
, X86_TWOB
, 0x5C);
534 emit_modrm( p
, dst
, src
);
537 void sse_mulps( struct x86_function
*p
,
541 emit_2ub(p
, X86_TWOB
, 0x59);
542 emit_modrm( p
, dst
, src
);
545 void sse_mulss( struct x86_function
*p
,
549 emit_3ub(p
, 0xF3, X86_TWOB
, 0x59);
550 emit_modrm( p
, dst
, src
);
553 void sse_addps( struct x86_function
*p
,
557 emit_2ub(p
, X86_TWOB
, 0x58);
558 emit_modrm( p
, dst
, src
);
561 void sse_addss( struct x86_function
*p
,
565 emit_3ub(p
, 0xF3, X86_TWOB
, 0x58);
566 emit_modrm( p
, dst
, src
);
569 void sse_andnps( struct x86_function
*p
,
573 emit_2ub(p
, X86_TWOB
, 0x55);
574 emit_modrm( p
, dst
, src
);
577 void sse_andps( struct x86_function
*p
,
581 emit_2ub(p
, X86_TWOB
, 0x54);
582 emit_modrm( p
, dst
, src
);
585 void sse_rsqrtps( struct x86_function
*p
,
589 emit_2ub(p
, X86_TWOB
, 0x52);
590 emit_modrm( p
, dst
, src
);
593 void sse_rsqrtss( struct x86_function
*p
,
597 emit_3ub(p
, 0xF3, X86_TWOB
, 0x52);
598 emit_modrm( p
, dst
, src
);
602 void sse_movhlps( struct x86_function
*p
,
606 assert(dst
.mod
== mod_REG
&& src
.mod
== mod_REG
);
607 emit_2ub(p
, X86_TWOB
, 0x12);
608 emit_modrm( p
, dst
, src
);
611 void sse_movlhps( struct x86_function
*p
,
615 assert(dst
.mod
== mod_REG
&& src
.mod
== mod_REG
);
616 emit_2ub(p
, X86_TWOB
, 0x16);
617 emit_modrm( p
, dst
, src
);
620 void sse_orps( struct x86_function
*p
,
624 emit_2ub(p
, X86_TWOB
, 0x56);
625 emit_modrm( p
, dst
, src
);
628 void sse_xorps( struct x86_function
*p
,
632 emit_2ub(p
, X86_TWOB
, 0x57);
633 emit_modrm( p
, dst
, src
);
636 void sse_cvtps2pi( struct x86_function
*p
,
640 assert(dst
.file
== file_MMX
&&
641 (src
.file
== file_XMM
|| src
.mod
!= mod_REG
));
645 emit_2ub(p
, X86_TWOB
, 0x2d);
646 emit_modrm( p
, dst
, src
);
650 /* Shufps can also be used to implement a reduced swizzle when dest ==
653 void sse_shufps( struct x86_function
*p
,
658 emit_2ub(p
, X86_TWOB
, 0xC6);
659 emit_modrm(p
, dest
, arg0
);
663 void sse_cmpps( struct x86_function
*p
,
668 emit_2ub(p
, X86_TWOB
, 0xC2);
669 emit_modrm(p
, dest
, arg0
);
673 void sse_pmovmskb( struct x86_function
*p
,
677 emit_3ub(p
, 0x66, X86_TWOB
, 0xD7);
678 emit_modrm(p
, dest
, src
);
681 /***********************************************************************
686 * Perform a reduced swizzle:
688 void sse2_pshufd( struct x86_function
*p
,
693 emit_3ub(p
, 0x66, X86_TWOB
, 0x70);
694 emit_modrm(p
, dest
, arg0
);
698 void sse2_cvttps2dq( struct x86_function
*p
,
702 emit_3ub( p
, 0xF3, X86_TWOB
, 0x5B );
703 emit_modrm( p
, dst
, src
);
706 void sse2_cvtps2dq( struct x86_function
*p
,
710 emit_3ub(p
, 0x66, X86_TWOB
, 0x5B);
711 emit_modrm( p
, dst
, src
);
714 void sse2_packssdw( struct x86_function
*p
,
718 emit_3ub(p
, 0x66, X86_TWOB
, 0x6B);
719 emit_modrm( p
, dst
, src
);
722 void sse2_packsswb( struct x86_function
*p
,
726 emit_3ub(p
, 0x66, X86_TWOB
, 0x63);
727 emit_modrm( p
, dst
, src
);
730 void sse2_packuswb( struct x86_function
*p
,
734 emit_3ub(p
, 0x66, X86_TWOB
, 0x67);
735 emit_modrm( p
, dst
, src
);
738 void sse2_rcpps( struct x86_function
*p
,
742 emit_2ub(p
, X86_TWOB
, 0x53);
743 emit_modrm( p
, dst
, src
);
746 void sse2_rcpss( struct x86_function
*p
,
750 emit_3ub(p
, 0xF3, X86_TWOB
, 0x53);
751 emit_modrm( p
, dst
, src
);
754 void sse2_movd( struct x86_function
*p
,
758 emit_2ub(p
, 0x66, X86_TWOB
);
759 emit_op_modrm( p
, 0x6e, 0x7e, dst
, src
);
765 /***********************************************************************
768 void x87_fist( struct x86_function
*p
, struct x86_reg dst
)
771 emit_modrm_noreg(p
, 2, dst
);
774 void x87_fistp( struct x86_function
*p
, struct x86_reg dst
)
777 emit_modrm_noreg(p
, 3, dst
);
780 void x87_fild( struct x86_function
*p
, struct x86_reg arg
)
783 emit_modrm_noreg(p
, 0, arg
);
786 void x87_fldz( struct x86_function
*p
)
788 emit_2ub(p
, 0xd9, 0xee);
792 void x87_fldcw( struct x86_function
*p
, struct x86_reg arg
)
794 assert(arg
.file
== file_REG32
);
795 assert(arg
.mod
!= mod_REG
);
797 emit_modrm_noreg(p
, 5, arg
);
800 void x87_fld1( struct x86_function
*p
)
802 emit_2ub(p
, 0xd9, 0xe8);
805 void x87_fldl2e( struct x86_function
*p
)
807 emit_2ub(p
, 0xd9, 0xea);
810 void x87_fldln2( struct x86_function
*p
)
812 emit_2ub(p
, 0xd9, 0xed);
815 void x87_fwait( struct x86_function
*p
)
820 void x87_fnclex( struct x86_function
*p
)
822 emit_2ub(p
, 0xdb, 0xe2);
825 void x87_fclex( struct x86_function
*p
)
832 static void x87_arith_op( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
,
833 unsigned char dst0ub0
,
834 unsigned char dst0ub1
,
835 unsigned char arg0ub0
,
836 unsigned char arg0ub1
,
837 unsigned char argmem_noreg
)
839 assert(dst
.file
== file_x87
);
841 if (arg
.file
== file_x87
) {
843 emit_2ub(p
, dst0ub0
, dst0ub1
+arg
.idx
);
844 else if (arg
.idx
== 0)
845 emit_2ub(p
, arg0ub0
, arg0ub1
+arg
.idx
);
849 else if (dst
.idx
== 0) {
850 assert(arg
.file
== file_REG32
);
852 emit_modrm_noreg(p
, argmem_noreg
, arg
);
858 void x87_fmul( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
)
860 x87_arith_op(p
, dst
, arg
,
866 void x87_fsub( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
)
868 x87_arith_op(p
, dst
, arg
,
874 void x87_fsubr( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
)
876 x87_arith_op(p
, dst
, arg
,
882 void x87_fadd( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
)
884 x87_arith_op(p
, dst
, arg
,
890 void x87_fdiv( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
)
892 x87_arith_op(p
, dst
, arg
,
898 void x87_fdivr( struct x86_function
*p
, struct x86_reg dst
, struct x86_reg arg
)
900 x87_arith_op(p
, dst
, arg
,
906 void x87_fmulp( struct x86_function
*p
, struct x86_reg dst
)
908 assert(dst
.file
== file_x87
);
909 assert(dst
.idx
>= 1);
910 emit_2ub(p
, 0xde, 0xc8+dst
.idx
);
913 void x87_fsubp( struct x86_function
*p
, struct x86_reg dst
)
915 assert(dst
.file
== file_x87
);
916 assert(dst
.idx
>= 1);
917 emit_2ub(p
, 0xde, 0xe8+dst
.idx
);
920 void x87_fsubrp( struct x86_function
*p
, struct x86_reg dst
)
922 assert(dst
.file
== file_x87
);
923 assert(dst
.idx
>= 1);
924 emit_2ub(p
, 0xde, 0xe0+dst
.idx
);
927 void x87_faddp( struct x86_function
*p
, struct x86_reg dst
)
929 assert(dst
.file
== file_x87
);
930 assert(dst
.idx
>= 1);
931 emit_2ub(p
, 0xde, 0xc0+dst
.idx
);
934 void x87_fdivp( struct x86_function
*p
, struct x86_reg dst
)
936 assert(dst
.file
== file_x87
);
937 assert(dst
.idx
>= 1);
938 emit_2ub(p
, 0xde, 0xf8+dst
.idx
);
941 void x87_fdivrp( struct x86_function
*p
, struct x86_reg dst
)
943 assert(dst
.file
== file_x87
);
944 assert(dst
.idx
>= 1);
945 emit_2ub(p
, 0xde, 0xf0+dst
.idx
);
948 void x87_fucom( struct x86_function
*p
, struct x86_reg arg
)
950 assert(arg
.file
== file_x87
);
951 emit_2ub(p
, 0xdd, 0xe0+arg
.idx
);
954 void x87_fucomp( struct x86_function
*p
, struct x86_reg arg
)
956 assert(arg
.file
== file_x87
);
957 emit_2ub(p
, 0xdd, 0xe8+arg
.idx
);
960 void x87_fucompp( struct x86_function
*p
)
962 emit_2ub(p
, 0xda, 0xe9);
965 void x87_fxch( struct x86_function
*p
, struct x86_reg arg
)
967 assert(arg
.file
== file_x87
);
968 emit_2ub(p
, 0xd9, 0xc8+arg
.idx
);
971 void x87_fabs( struct x86_function
*p
)
973 emit_2ub(p
, 0xd9, 0xe1);
976 void x87_fchs( struct x86_function
*p
)
978 emit_2ub(p
, 0xd9, 0xe0);
981 void x87_fcos( struct x86_function
*p
)
983 emit_2ub(p
, 0xd9, 0xff);
987 void x87_fprndint( struct x86_function
*p
)
989 emit_2ub(p
, 0xd9, 0xfc);
992 void x87_fscale( struct x86_function
*p
)
994 emit_2ub(p
, 0xd9, 0xfd);
997 void x87_fsin( struct x86_function
*p
)
999 emit_2ub(p
, 0xd9, 0xfe);
1002 void x87_fsincos( struct x86_function
*p
)
1004 emit_2ub(p
, 0xd9, 0xfb);
1007 void x87_fsqrt( struct x86_function
*p
)
1009 emit_2ub(p
, 0xd9, 0xfa);
1012 void x87_fxtract( struct x86_function
*p
)
1014 emit_2ub(p
, 0xd9, 0xf4);
1019 * Restrictions: -1.0 <= st0 <= 1.0
1021 void x87_f2xm1( struct x86_function
*p
)
1023 emit_2ub(p
, 0xd9, 0xf0);
1026 /* st1 = st1 * log2(st0);
1029 void x87_fyl2x( struct x86_function
*p
)
1031 emit_2ub(p
, 0xd9, 0xf1);
1034 /* st1 = st1 * log2(st0 + 1.0);
1037 * A fast operation, with restrictions: -.29 < st0 < .29
1039 void x87_fyl2xp1( struct x86_function
*p
)
1041 emit_2ub(p
, 0xd9, 0xf9);
1045 void x87_fld( struct x86_function
*p
, struct x86_reg arg
)
1047 if (arg
.file
== file_x87
)
1048 emit_2ub(p
, 0xd9, 0xc0 + arg
.idx
);
1051 emit_modrm_noreg(p
, 0, arg
);
1055 void x87_fst( struct x86_function
*p
, struct x86_reg dst
)
1057 if (dst
.file
== file_x87
)
1058 emit_2ub(p
, 0xdd, 0xd0 + dst
.idx
);
1061 emit_modrm_noreg(p
, 2, dst
);
1065 void x87_fstp( struct x86_function
*p
, struct x86_reg dst
)
1067 if (dst
.file
== file_x87
)
1068 emit_2ub(p
, 0xdd, 0xd8 + dst
.idx
);
1071 emit_modrm_noreg(p
, 3, dst
);
1075 void x87_fcom( struct x86_function
*p
, struct x86_reg dst
)
1077 if (dst
.file
== file_x87
)
1078 emit_2ub(p
, 0xd8, 0xd0 + dst
.idx
);
1081 emit_modrm_noreg(p
, 2, dst
);
1085 void x87_fcomp( struct x86_function
*p
, struct x86_reg dst
)
1087 if (dst
.file
== file_x87
)
1088 emit_2ub(p
, 0xd8, 0xd8 + dst
.idx
);
1091 emit_modrm_noreg(p
, 3, dst
);
1096 void x87_fnstsw( struct x86_function
*p
, struct x86_reg dst
)
1098 assert(dst
.file
== file_REG32
);
1100 if (dst
.idx
== reg_AX
&&
1102 emit_2ub(p
, 0xdf, 0xe0);
1105 emit_modrm_noreg(p
, 7, dst
);
1112 /***********************************************************************
1116 void mmx_emms( struct x86_function
*p
)
1118 assert(p
->need_emms
);
1119 emit_2ub(p
, 0x0f, 0x77);
1123 void mmx_packssdw( struct x86_function
*p
,
1125 struct x86_reg src
)
1127 assert(dst
.file
== file_MMX
&&
1128 (src
.file
== file_MMX
|| src
.mod
!= mod_REG
));
1132 emit_2ub(p
, X86_TWOB
, 0x6b);
1133 emit_modrm( p
, dst
, src
);
1136 void mmx_packuswb( struct x86_function
*p
,
1138 struct x86_reg src
)
1140 assert(dst
.file
== file_MMX
&&
1141 (src
.file
== file_MMX
|| src
.mod
!= mod_REG
));
1145 emit_2ub(p
, X86_TWOB
, 0x67);
1146 emit_modrm( p
, dst
, src
);
1149 void mmx_movd( struct x86_function
*p
,
1151 struct x86_reg src
)
1154 emit_1ub(p
, X86_TWOB
);
1155 emit_op_modrm( p
, 0x6e, 0x7e, dst
, src
);
1158 void mmx_movq( struct x86_function
*p
,
1160 struct x86_reg src
)
1163 emit_1ub(p
, X86_TWOB
);
1164 emit_op_modrm( p
, 0x6f, 0x7f, dst
, src
);
1168 /***********************************************************************
1173 /* Retreive a reference to one of the function arguments, taking into
1174 * account any push/pop activity:
1176 struct x86_reg
x86_fn_arg( struct x86_function
*p
,
1179 return x86_make_disp(x86_make_reg(file_REG32
, reg_SP
),
1180 p
->stack_offset
+ arg
* 4); /* ??? */
1184 void x86_init_func( struct x86_function
*p
)
1191 void x86_init_func_size( struct x86_function
*p
, unsigned code_size
)
1193 p
->size
= code_size
;
1194 p
->store
= rtasm_exec_malloc(code_size
);
1198 void x86_release_func( struct x86_function
*p
)
1200 rtasm_exec_free(p
->store
);
1207 void (*x86_get_func( struct x86_function
*p
))(void)
1209 if (DISASSEM
&& p
->store
)
1210 debug_printf("disassemble %p %p\n", p
->store
, p
->csr
);
1211 return (void (*)(void)) p
->store
;
1216 void x86sse_dummy( void )