2 * x86-64 code generator for TCC
4 * Copyright (c) 2008 Shinichiro Hamaji
6 * Based on i386-gen.c by Fabrice Bellard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifdef TARGET_DEFS_ONLY
25 /* number of available registers */
29 /* a register can belong to several classes. The classes must be
30 sorted from more general to more precise (see gv2() code which does
31 assumptions on it). */
32 #define RC_INT 0x0001 /* generic integer register */
33 #define RC_FLOAT 0x0002 /* generic float register */
41 #define RC_XMM0 0x0020
42 #define RC_XMM1 0x0040
43 #define RC_ST0 0x0080 /* only for long double */
44 #define RC_IRET RC_RAX /* function return: integer register */
45 #define RC_LRET RC_RDX /* function return: second integer register */
46 #define RC_FRET RC_XMM0 /* function return: float register */
47 #define RC_QRET RC_XMM1 /* function return: second float register */
49 /* pretty names for the registers */
69 #define REX_BASE(reg) (((reg) >> 3) & 1)
70 #define REG_VALUE(reg) ((reg) & 7)
72 /* return registers for function */
73 #define REG_IRET TREG_RAX /* single word int return register */
74 #define REG_LRET TREG_RDX /* second word return register (for long long) */
75 #define REG_FRET TREG_XMM0 /* float return register */
76 #define REG_QRET TREG_XMM1 /* second float return register */
78 /* defined if function parameters must be evaluated in reverse order */
79 #define INVERT_FUNC_PARAMS
81 /* pointer size, in bytes */
84 /* long double size and alignment, in bytes */
85 #define LDOUBLE_SIZE 16
86 #define LDOUBLE_ALIGN 8
87 /* maximum alignment (for aligned attribute support) */
90 /******************************************************/
93 #define EM_TCC_TARGET EM_X86_64
95 /* relocation type for 32 bit data relocation */
96 #define R_DATA_32 R_X86_64_32
97 #define R_DATA_PTR R_X86_64_64
98 #define R_JMP_SLOT R_X86_64_JUMP_SLOT
99 #define R_COPY R_X86_64_COPY
101 #define ELF_START_ADDR 0x08048000
102 #define ELF_PAGE_SIZE 0x1000
104 /******************************************************/
105 #else /* ! TARGET_DEFS_ONLY */
106 /******************************************************/
110 ST_DATA
const int reg_classes
[NB_REGS
+7] = {
111 /* eax */ RC_INT
| RC_RAX
,
112 /* ecx */ RC_INT
| RC_RCX
,
113 /* edx */ RC_INT
| RC_RDX
,
114 /* xmm0 */ RC_FLOAT
| RC_XMM0
,
115 /* xmm1 */ RC_FLOAT
| RC_XMM1
,
126 static unsigned long func_sub_sp_offset
;
127 static int func_ret_sub
;
129 /* XXX: make it faster ? */
134 if (ind1
> cur_text_section
->data_allocated
)
135 section_realloc(cur_text_section
, ind1
);
136 cur_text_section
->data
[ind
] = c
;
140 void o(unsigned int c
)
162 void gen_le64(int64_t c
)
174 void orex(int ll
, int r
, int r2
, int b
)
176 if ((r
& VT_VALMASK
) >= VT_CONST
)
178 if ((r2
& VT_VALMASK
) >= VT_CONST
)
180 if (ll
|| REX_BASE(r
) || REX_BASE(r2
))
181 o(0x40 | REX_BASE(r
) | (REX_BASE(r2
) << 2) | (ll
<< 3));
185 /* output a symbol and patch all calls to it */
186 void gsym_addr(int t
, int a
)
190 ptr
= (int *)(cur_text_section
->data
+ t
);
191 n
= *ptr
; /* next value */
202 /* psym is used to put an instruction with a data field which is a
203 reference to a symbol. It is in fact the same as oad ! */
206 static int is64_type(int t
)
208 return ((t
& VT_BTYPE
) == VT_PTR
||
209 (t
& VT_BTYPE
) == VT_FUNC
||
210 (t
& VT_BTYPE
) == VT_LLONG
);
213 static int is_sse_float(int t
) {
216 return bt
== VT_DOUBLE
|| bt
== VT_FLOAT
;
220 /* instruction + 4 bytes data. Return the address of the data */
221 ST_FUNC
int oad(int c
, int s
)
227 if (ind1
> cur_text_section
->data_allocated
)
228 section_realloc(cur_text_section
, ind1
);
229 *(int *)(cur_text_section
->data
+ ind
) = s
;
235 ST_FUNC
void gen_addr32(int r
, Sym
*sym
, int c
)
238 greloc(cur_text_section
, sym
, ind
, R_X86_64_32
);
242 /* output constant with relocation if 'r & VT_SYM' is true */
243 ST_FUNC
void gen_addr64(int r
, Sym
*sym
, int64_t c
)
246 greloc(cur_text_section
, sym
, ind
, R_X86_64_64
);
250 /* output constant with relocation if 'r & VT_SYM' is true */
251 ST_FUNC
void gen_addrpc32(int r
, Sym
*sym
, int c
)
254 greloc(cur_text_section
, sym
, ind
, R_X86_64_PC32
);
258 /* output got address with relocation */
259 static void gen_gotpcrel(int r
, Sym
*sym
, int c
)
261 #ifndef TCC_TARGET_PE
264 greloc(cur_text_section
, sym
, ind
, R_X86_64_GOTPCREL
);
265 sr
= cur_text_section
->reloc
;
266 rel
= (ElfW(Rela
) *)(sr
->data
+ sr
->data_offset
- sizeof(ElfW(Rela
)));
269 printf("picpic: %s %x %x | %02x %02x %02x\n", get_tok_str(sym
->v
, NULL
), c
, r
,
270 cur_text_section
->data
[ind
-3],
271 cur_text_section
->data
[ind
-2],
272 cur_text_section
->data
[ind
-1]
274 greloc(cur_text_section
, sym
, ind
, R_X86_64_PC32
);
278 /* we use add c, %xxx for displacement */
280 o(0xc0 + REG_VALUE(r
));
285 static void gen_modrm_impl(int op_reg
, int r
, Sym
*sym
, int c
, int is_got
)
287 op_reg
= REG_VALUE(op_reg
) << 3;
288 if ((r
& VT_VALMASK
) == VT_CONST
) {
289 /* constant memory reference */
292 gen_gotpcrel(r
, sym
, c
);
294 gen_addrpc32(r
, sym
, c
);
296 } else if ((r
& VT_VALMASK
) == VT_LOCAL
) {
297 /* currently, we use only ebp as base */
299 /* short reference */
303 oad(0x85 | op_reg
, c
);
305 } else if ((r
& VT_VALMASK
) >= TREG_MEM
) {
307 g(0x80 | op_reg
| REG_VALUE(r
));
310 g(0x00 | op_reg
| REG_VALUE(r
));
313 g(0x00 | op_reg
| REG_VALUE(r
));
317 /* generate a modrm reference. 'op_reg' contains the addtionnal 3
319 static void gen_modrm(int op_reg
, int r
, Sym
*sym
, int c
)
321 gen_modrm_impl(op_reg
, r
, sym
, c
, 0);
324 /* generate a modrm reference. 'op_reg' contains the addtionnal 3
326 static void gen_modrm64(int opcode
, int op_reg
, int r
, Sym
*sym
, int c
)
329 is_got
= (op_reg
& TREG_MEM
) && !(sym
->type
.t
& VT_STATIC
);
330 orex(1, r
, op_reg
, opcode
);
331 gen_modrm_impl(op_reg
, r
, sym
, c
, is_got
);
335 /* load 'r' from value 'sv' */
336 void load(int r
, SValue
*sv
)
338 int v
, t
, ft
, fc
, fr
;
343 sv
= pe_getimport(sv
, &v2
);
350 #ifndef TCC_TARGET_PE
351 /* we use indirect access via got */
352 if ((fr
& VT_VALMASK
) == VT_CONST
&& (fr
& VT_SYM
) &&
353 (fr
& VT_LVAL
) && !(sv
->sym
->type
.t
& VT_STATIC
)) {
354 /* use the result register as a temporal register */
355 int tr
= r
| TREG_MEM
;
357 /* we cannot use float registers as a temporal register */
358 tr
= get_reg(RC_INT
) | TREG_MEM
;
360 gen_modrm64(0x8b, tr
, fr
, sv
->sym
, 0);
362 /* load from the temporal register */
370 if (v
== VT_LLOCAL
) {
372 v1
.r
= VT_LOCAL
| VT_LVAL
;
375 if (!(reg_classes
[fr
] & RC_INT
))
376 fr
= get_reg(RC_INT
);
380 if ((ft
& VT_BTYPE
) == VT_FLOAT
) {
381 b
= 0x6e0f66, r
= 0; /* movd */
382 } else if ((ft
& VT_BTYPE
) == VT_DOUBLE
) {
383 b
= 0x7e0ff3; /* movq */
385 } else if ((ft
& VT_BTYPE
) == VT_LDOUBLE
) {
386 b
= 0xdb, r
= 5; /* fldt */
387 } else if ((ft
& VT_TYPE
) == VT_BYTE
) {
388 b
= 0xbe0f; /* movsbl */
389 } else if ((ft
& VT_TYPE
) == (VT_BYTE
| VT_UNSIGNED
)) {
390 b
= 0xb60f; /* movzbl */
391 } else if ((ft
& VT_TYPE
) == VT_SHORT
) {
392 b
= 0xbf0f; /* movswl */
393 } else if ((ft
& VT_TYPE
) == (VT_SHORT
| VT_UNSIGNED
)) {
394 b
= 0xb70f; /* movzwl */
396 assert(((ft
& VT_BTYPE
) == VT_INT
) || ((ft
& VT_BTYPE
) == VT_LLONG
)
397 || ((ft
& VT_BTYPE
) == VT_PTR
) || ((ft
& VT_BTYPE
) == VT_ENUM
)
398 || ((ft
& VT_BTYPE
) == VT_FUNC
));
403 gen_modrm64(b
, r
, fr
, sv
->sym
, fc
);
406 gen_modrm(r
, fr
, sv
->sym
, fc
);
413 o(0x05 + REG_VALUE(r
) * 8); /* lea xx(%rip), r */
414 gen_addrpc32(fr
, sv
->sym
, fc
);
416 if (sv
->sym
->type
.t
& VT_STATIC
) {
418 o(0x05 + REG_VALUE(r
) * 8); /* lea xx(%rip), r */
419 gen_addrpc32(fr
, sv
->sym
, fc
);
422 o(0x05 + REG_VALUE(r
) * 8); /* mov xx(%rip), r */
423 gen_gotpcrel(r
, sv
->sym
, fc
);
426 } else if (is64_type(ft
)) {
427 orex(1,r
,0, 0xb8 + REG_VALUE(r
)); /* mov $xx, r */
430 orex(0,r
,0, 0xb8 + REG_VALUE(r
)); /* mov $xx, r */
433 } else if (v
== VT_LOCAL
) {
434 orex(1,0,r
,0x8d); /* lea xxx(%ebp), r */
435 gen_modrm(r
, VT_LOCAL
, sv
->sym
, fc
);
436 } else if (v
== VT_CMP
) {
438 if ((fc
& ~0x100) != TOK_NE
)
439 oad(0xb8 + REG_VALUE(r
), 0); /* mov $0, r */
441 oad(0xb8 + REG_VALUE(r
), 1); /* mov $1, r */
444 /* This was a float compare. If the parity bit is
445 set the result was unordered, meaning false for everything
446 except TOK_NE, and true for TOK_NE. */
448 o(0x037a + (REX_BASE(r
) << 8));
450 orex(0,r
,0, 0x0f); /* setxx %br */
452 o(0xc0 + REG_VALUE(r
));
453 } else if (v
== VT_JMP
|| v
== VT_JMPI
) {
456 oad(0xb8 + REG_VALUE(r
), t
); /* mov $1, r */
457 o(0x05eb + (REX_BASE(r
) << 8)); /* jmp after */
460 oad(0xb8 + REG_VALUE(r
), t
^ 1); /* mov $0, r */
462 if ((r
== TREG_XMM0
) || (r
== TREG_XMM1
)) {
464 /* gen_cvt_ftof(VT_DOUBLE); */
465 o(0xf0245cdd); /* fstpl -0x10(%rsp) */
466 /* movsd -0x10(%rsp),%xmmN */
468 o(0x44 + ((r
- TREG_XMM0
) << 3)); /* %xmmN */
471 assert((v
== TREG_XMM0
) || (v
== TREG_XMM1
));
472 if ((ft
& VT_BTYPE
) == VT_FLOAT
) {
475 assert((ft
& VT_BTYPE
) == VT_DOUBLE
);
478 o(0xc0 + (v
- TREG_XMM0
) + ((r
- TREG_XMM0
) << 3));
480 } else if (r
== TREG_ST0
) {
481 assert((v
== TREG_XMM0
) || (v
== TREG_XMM1
));
482 /* gen_cvt_ftof(VT_LDOUBLE); */
483 /* movsd %xmm0,-0x10(%rsp) */
485 o(0x44 + ((r
- TREG_XMM0
) << 3)); /* %xmmN */
487 o(0xf02444dd); /* fldl -0x10(%rsp) */
490 o(0xc0 + REG_VALUE(r
) + REG_VALUE(v
) * 8); /* mov v, r */
496 /* store register 'r' in lvalue 'v' */
497 void store(int r
, SValue
*v
)
501 /* store the REX prefix in this variable when PIC is enabled */
506 v
= pe_getimport(v
, &v2
);
511 fr
= v
->r
& VT_VALMASK
;
514 #ifndef TCC_TARGET_PE
515 /* we need to access the variable via got */
516 if (fr
== VT_CONST
&& (v
->r
& VT_SYM
)) {
517 /* mov xx(%rip), %r11 */
519 gen_gotpcrel(TREG_R11
, v
->sym
, v
->c
.ul
);
520 pic
= is64_type(bt
) ? 0x49 : 0x41;
524 /* XXX: incorrect if float reg to reg */
525 if (bt
== VT_FLOAT
) {
528 o(0x7e0f); /* movd */
530 } else if (bt
== VT_DOUBLE
) {
533 o(0xd60f); /* movq */
535 } else if (bt
== VT_LDOUBLE
) {
536 o(0xc0d9); /* fld %st(0) */
544 if (bt
== VT_BYTE
|| bt
== VT_BOOL
)
546 else if (is64_type(bt
))
552 /* xxx r, (%r11) where xxx is mov, movq, fld, or etc */
557 if (fr
== VT_CONST
|| fr
== VT_LOCAL
|| (v
->r
& VT_LVAL
)) {
558 gen_modrm64(op64
, r
, v
->r
, v
->sym
, fc
);
559 } else if (fr
!= r
) {
560 /* XXX: don't we really come here? */
562 o(0xc0 + fr
+ r
* 8); /* mov r, fr */
565 if (fr
== VT_CONST
|| fr
== VT_LOCAL
|| (v
->r
& VT_LVAL
)) {
566 gen_modrm(r
, v
->r
, v
->sym
, fc
);
567 } else if (fr
!= r
) {
568 /* XXX: don't we really come here? */
570 o(0xc0 + fr
+ r
* 8); /* mov r, fr */
575 /* 'is_jmp' is '1' if it is a jump */
576 static void gcall_or_jmp(int is_jmp
)
579 if ((vtop
->r
& (VT_VALMASK
| VT_LVAL
)) == VT_CONST
) {
581 if (vtop
->r
& VT_SYM
) {
582 /* relocation case */
583 greloc(cur_text_section
, vtop
->sym
,
584 ind
+ 1, R_X86_64_PC32
);
586 /* put an empty PC32 relocation */
587 put_elf_reloc(symtab_section
, cur_text_section
,
588 ind
+ 1, R_X86_64_PC32
, 0);
590 oad(0xe8 + is_jmp
, vtop
->c
.ul
- 4); /* call/jmp im */
592 /* otherwise, indirect call */
596 o(0xff); /* call/jmp *r */
597 o(0xd0 + REG_VALUE(r
) + (is_jmp
<< 4));
604 static const uint8_t arg_regs
[] = {
605 TREG_RCX
, TREG_RDX
, TREG_R8
, TREG_R9
608 static int func_scratch
;
610 /* Generate function call. The function address is pushed first, then
611 all the parameters in call order. This functions pops all the
612 parameters and the function address. */
614 void gen_offs_sp(int b
, int r
, int d
)
616 orex(1,0,r
& 0x100 ? 0 : r
, b
);
618 o(0x2444 | (REG_VALUE(r
) << 3));
621 o(0x2484 | (REG_VALUE(r
) << 3));
626 /* Return 1 if this function returns via an sret pointer, 0 otherwise */
627 ST_FUNC
int gfunc_sret(CType
*vt
, CType
*ret
, int *ret_align
) {
628 *ret_align
= 1; // Never have to re-align return values for x86-64
632 void gfunc_call(int nb_args
)
634 int size
, align
, r
, args_size
, i
, d
, j
, bt
, struct_size
;
635 int nb_reg_args
, gen_reg
;
637 nb_reg_args
= nb_args
;
638 args_size
= (nb_reg_args
< REGN
? REGN
: nb_reg_args
) * PTR_SIZE
;
640 /* for struct arguments, we need to call memcpy and the function
641 call breaks register passing arguments we are preparing.
642 So, we process arguments which will be passed by stack first. */
643 struct_size
= args_size
;
644 for(i
= 0; i
< nb_args
; i
++) {
645 SValue
*sv
= &vtop
[-i
];
646 bt
= (sv
->type
.t
& VT_BTYPE
);
647 if (bt
== VT_STRUCT
) {
648 size
= type_size(&sv
->type
, &align
);
649 /* align to stack align size */
650 size
= (size
+ 15) & ~15;
651 /* generate structure store */
653 gen_offs_sp(0x8d, r
, struct_size
);
656 /* generate memcpy call */
657 vset(&sv
->type
, r
| VT_LVAL
, 0);
662 } else if (bt
== VT_LDOUBLE
) {
665 gen_offs_sp(0xdb, 0x107, struct_size
);
671 if (func_scratch
< struct_size
)
672 func_scratch
= struct_size
;
674 for (i
= 0; i
< REGN
; ++i
)
675 save_reg(arg_regs
[i
]);
678 gen_reg
= nb_reg_args
;
679 struct_size
= args_size
;
681 for(i
= 0; i
< nb_args
; i
++) {
682 bt
= (vtop
->type
.t
& VT_BTYPE
);
684 if (bt
== VT_STRUCT
|| bt
== VT_LDOUBLE
) {
685 if (bt
== VT_LDOUBLE
)
688 size
= type_size(&vtop
->type
, &align
);
689 /* align to stack align size */
690 size
= (size
+ 15) & ~15;
694 gen_offs_sp(0x8d, d
, struct_size
);
695 gen_offs_sp(0x89, d
, j
*8);
698 gen_offs_sp(0x8d, d
, struct_size
);
702 } else if (is_sse_float(vtop
->type
.t
)) {
703 gv(RC_XMM0
); /* only one float register */
706 /* movq %xmm0, j*8(%rsp) */
707 gen_offs_sp(0xd60f66, 0x100, j
*8);
709 /* movaps %xmm0, %xmmN */
713 /* mov %xmm0, %rxx */
716 o(0xc0 + REG_VALUE(d
));
722 gen_offs_sp(0x89, r
, j
*8);
726 gv(reg_classes
[d
] & ~RC_INT
);
731 o(0xc0 + REG_VALUE(d
) + REG_VALUE(r
) * 8);
745 #define FUNC_PROLOG_SIZE 11
747 /* generate function prolog of type 't' */
748 void gfunc_prolog(CType
*func_type
)
750 int addr
, reg_param_index
, bt
;
759 ind
+= FUNC_PROLOG_SIZE
;
760 func_sub_sp_offset
= ind
;
763 sym
= func_type
->ref
;
765 /* if the function returns a structure, then add an
766 implicit pointer parameter */
768 if ((func_vt
.t
& VT_BTYPE
) == VT_STRUCT
) {
769 gen_modrm64(0x89, arg_regs
[reg_param_index
], VT_LOCAL
, NULL
, addr
);
774 /* define parameters */
775 while ((sym
= sym
->next
) != NULL
) {
777 bt
= type
->t
& VT_BTYPE
;
778 if (reg_param_index
< REGN
) {
779 /* save arguments passed by register */
780 gen_modrm64(0x89, arg_regs
[reg_param_index
], VT_LOCAL
, NULL
, addr
);
782 if (bt
== VT_STRUCT
|| bt
== VT_LDOUBLE
) {
783 sym_push(sym
->v
& ~SYM_FIELD
, type
, VT_LOCAL
| VT_LVAL
| VT_REF
, addr
);
785 sym_push(sym
->v
& ~SYM_FIELD
, type
, VT_LOCAL
| VT_LVAL
, addr
);
791 while (reg_param_index
< REGN
) {
792 if (func_type
->ref
->c
== FUNC_ELLIPSIS
)
793 gen_modrm64(0x89, arg_regs
[reg_param_index
], VT_LOCAL
, NULL
, addr
);
799 /* generate function epilog */
800 void gfunc_epilog(void)
805 if (func_ret_sub
== 0) {
810 g(func_ret_sub
>> 8);
814 ind
= func_sub_sp_offset
- FUNC_PROLOG_SIZE
;
815 /* align local size to word & save local variables */
816 v
= (func_scratch
+ -loc
+ 15) & -16;
819 Sym
*sym
= external_global_sym(TOK___chkstk
, &func_old_type
, 0);
820 oad(0xb8, v
); /* mov stacksize, %eax */
821 oad(0xe8, -4); /* call __chkstk, (does the stackframe too) */
822 greloc(cur_text_section
, sym
, ind
-4, R_X86_64_PC32
);
823 o(0x90); /* fill for FUNC_PROLOG_SIZE = 11 bytes */
825 o(0xe5894855); /* push %rbp, mov %rsp, %rbp */
826 o(0xec8148); /* sub rsp, stacksize */
830 cur_text_section
->data_offset
= saved_ind
;
831 pe_add_unwind_data(ind
, saved_ind
, v
);
832 ind
= cur_text_section
->data_offset
;
837 static void gadd_sp(int val
)
839 if (val
== (char)val
) {
843 oad(0xc48148, val
); /* add $xxx, %rsp */
847 typedef enum X86_64_Mode
{
855 static X86_64_Mode
classify_x86_64_merge(X86_64_Mode a
, X86_64_Mode b
) {
858 else if (a
== x86_64_mode_none
)
860 else if (b
== x86_64_mode_none
)
862 else if ((a
== x86_64_mode_memory
) || (b
== x86_64_mode_memory
))
863 return x86_64_mode_memory
;
864 else if ((a
== x86_64_mode_integer
) || (b
== x86_64_mode_integer
))
865 return x86_64_mode_integer
;
866 else if ((a
== x86_64_mode_x87
) || (b
== x86_64_mode_x87
))
867 return x86_64_mode_memory
;
869 return x86_64_mode_sse
;
872 static X86_64_Mode
classify_x86_64_inner(CType
*ty
) {
876 switch (ty
->t
& VT_BTYPE
) {
877 case VT_VOID
: return x86_64_mode_none
;
886 case VT_ENUM
: return x86_64_mode_integer
;
889 case VT_DOUBLE
: return x86_64_mode_sse
;
891 case VT_LDOUBLE
: return x86_64_mode_x87
;
897 if (f
->next
&& (f
->c
== f
->next
->c
))
898 return x86_64_mode_memory
;
900 mode
= x86_64_mode_none
;
901 for (; f
; f
= f
->next
)
902 mode
= classify_x86_64_merge(mode
, classify_x86_64_inner(&f
->type
));
910 static X86_64_Mode
classify_x86_64_arg(CType
*ty
, CType
*ret
, int *psize
, int *reg_count
) {
912 int size
, align
, ret_t
;
914 if (ty
->t
& (VT_BITFIELD
|VT_ARRAY
)) {
918 mode
= x86_64_mode_integer
;
920 size
= type_size(ty
, &align
);
921 *psize
= (size
+ 7) & ~7;
924 mode
= x86_64_mode_memory
;
926 mode
= classify_x86_64_inner(ty
);
928 case x86_64_mode_integer
:
934 ret_t
= (size
> 4) ? VT_LLONG
: VT_INT
;
938 case x86_64_mode_x87
:
943 case x86_64_mode_sse
:
949 ret_t
= (size
> 4) ? VT_DOUBLE
: VT_FLOAT
;
964 ST_FUNC
int classify_x86_64_va_arg(CType
*ty
) {
965 /* This definition must be synced with stdarg.h */
967 __va_gen_reg
, __va_float_reg
, __va_stack
970 X86_64_Mode mode
= classify_x86_64_arg(ty
, NULL
, &size
, ®_count
);
972 default: return __va_stack
;
973 case x86_64_mode_integer
: return __va_gen_reg
;
974 case x86_64_mode_sse
: return __va_float_reg
;
978 /* Return 1 if this function returns via an sret pointer, 0 otherwise */
979 int gfunc_sret(CType
*vt
, CType
*ret
, int *ret_align
) {
981 *ret_align
= 1; // Never have to re-align return values for x86-64
982 return (classify_x86_64_arg(vt
, ret
, &size
, ®_count
) == x86_64_mode_memory
);
986 static const uint8_t arg_regs
[REGN
] = {
987 TREG_RDI
, TREG_RSI
, TREG_RDX
, TREG_RCX
, TREG_R8
, TREG_R9
990 static int arg_prepare_reg(int idx
) {
991 if (idx
== 2 || idx
== 3)
992 /* idx=2: r10, idx=3: r11 */
995 return arg_regs
[idx
];
998 /* Generate function call. The function address is pushed first, then
999 all the parameters in call order. This functions pops all the
1000 parameters and the function address. */
1001 void gfunc_call(int nb_args
)
1005 int size
, align
, r
, args_size
, i
, j
, reg_count
;
1006 int nb_reg_args
= 0;
1007 int nb_sse_args
= 0;
1008 int sse_reg
, gen_reg
;
1010 /* calculate the number of integer/float arguments */
1012 for(i
= 0; i
< nb_args
; i
++) {
1013 mode
= classify_x86_64_arg(&vtop
[-i
].type
, NULL
, &size
, ®_count
);
1015 case x86_64_mode_memory
:
1016 case x86_64_mode_x87
:
1020 case x86_64_mode_sse
:
1021 nb_sse_args
+= reg_count
;
1022 if (nb_sse_args
> 8) args_size
+= size
;
1025 case x86_64_mode_integer
:
1026 nb_reg_args
+= reg_count
;
1027 if (nb_reg_args
> REGN
) args_size
+= size
;
1032 /* for struct arguments, we need to call memcpy and the function
1033 call breaks register passing arguments we are preparing.
1034 So, we process arguments which will be passed by stack first. */
1035 gen_reg
= nb_reg_args
;
1036 sse_reg
= nb_sse_args
;
1038 /* adjust stack to align SSE boundary */
1039 if (args_size
&= 15) {
1040 /* fetch cpu flag before the following sub will change the value */
1041 if (vtop
>= vstack
&& (vtop
->r
& VT_VALMASK
) == VT_CMP
)
1044 args_size
= 16 - args_size
;
1046 oad(0xec81, args_size
); /* sub $xxx, %rsp */
1049 for(i
= 0; i
< nb_args
; i
++) {
1050 /* Swap argument to top, it will possibly be changed here,
1051 and might use more temps. All arguments must remain on the
1052 stack, so that get_reg can correctly evict some of them onto
1053 stack. We could use also use a vrott(nb_args) at the end
1054 of this loop, but this seems faster. */
1055 SValue tmp
= vtop
[0];
1058 mode
= classify_x86_64_arg(&vtop
->type
, NULL
, &size
, ®_count
);
1060 case x86_64_mode_memory
:
1061 /* allocate the necessary size on stack */
1063 oad(0xec81, size
); /* sub $xxx, %rsp */
1064 /* generate structure store */
1065 r
= get_reg(RC_INT
);
1066 orex(1, r
, 0, 0x89); /* mov %rsp, r */
1067 o(0xe0 + REG_VALUE(r
));
1068 vset(&vtop
->type
, r
| VT_LVAL
, 0);
1074 case x86_64_mode_x87
:
1076 size
= LDOUBLE_SIZE
;
1077 oad(0xec8148, size
); /* sub $xxx, %rsp */
1078 o(0x7cdb); /* fstpt 0(%rsp) */
1084 case x86_64_mode_sse
:
1087 o(0x50); /* push $rax */
1088 /* movq %xmm0, (%rsp) */
1093 sse_reg
-= reg_count
;
1096 case x86_64_mode_integer
:
1098 /* XXX: implicit cast ? */
1099 if (gen_reg
> REGN
) {
1101 orex(0,r
,0,0x50 + REG_VALUE(r
)); /* push r */
1104 gen_reg
-= reg_count
;
1108 /* And swap the argument back to it's original position. */
1114 /* XXX This should be superfluous. */
1115 save_regs(0); /* save used temporary registers */
1117 /* then, we prepare register passing arguments.
1118 Note that we cannot set RDX and RCX in this loop because gv()
1119 may break these temporary registers. Let's use R10 and R11
1121 gen_reg
= nb_reg_args
;
1122 sse_reg
= nb_sse_args
;
1123 for(i
= 0; i
< nb_args
; i
++) {
1124 mode
= classify_x86_64_arg(&vtop
->type
, &type
, &size
, ®_count
);
1125 /* Alter stack entry type so that gv() knows how to treat it */
1131 case x86_64_mode_sse
:
1132 sse_reg
-= reg_count
;
1133 if (sse_reg
+ reg_count
<= 8) {
1134 gv(RC_XMM0
); /* only one float register */
1135 if (sse_reg
) { /* avoid redundant movaps %xmm0, %xmm0 */
1136 /* movaps %xmm0, %xmmN */
1138 o(0xc0 + (sse_reg
<< 3));
1139 if (reg_count
== 2) {
1140 /* movaps %xmm1, %xmmN */
1142 o(0xc1 + ((sse_reg
+1) << 3));
1148 case x86_64_mode_integer
:
1150 /* XXX: implicit cast ? */
1151 gen_reg
-= reg_count
;
1152 if (gen_reg
+ reg_count
<= REGN
) {
1153 r
= gv((reg_count
== 1) ? RC_INT
: RC_IRET
);
1154 int d
= arg_prepare_reg(gen_reg
);
1155 orex(1,d
,r
,0x89); /* mov */
1156 o(0xc0 + REG_VALUE(r
) * 8 + REG_VALUE(d
));
1157 if (reg_count
== 2) {
1158 /* Second word of two-word value should always be in rdx
1159 this case is handled via RC_IRET */
1161 d
= arg_prepare_reg(gen_reg
+1);
1162 orex(1,d
,r
,0x89); /* mov */
1163 o(0xc0 + REG_VALUE(r
) * 8 + REG_VALUE(d
));
1171 /* We shouldn't have many operands on the stack anymore, but the
1172 call address itself is still there, and it might be in %eax
1173 (or edx/ecx) currently, which the below writes would clobber.
1174 So evict all remaining operands here. */
1177 /* Copy R10 and R11 into RDX and RCX, respectively */
1178 if (nb_reg_args
> 2) {
1179 o(0xd2894c); /* mov %r10, %rdx */
1180 if (nb_reg_args
> 3) {
1181 o(0xd9894c); /* mov %r11, %rcx */
1185 oad(0xb8, nb_sse_args
< 8 ? nb_sse_args
: 8); /* mov nb_sse_args, %eax */
1193 #define FUNC_PROLOG_SIZE 11
1195 static void push_arg_reg(int i
) {
1197 gen_modrm64(0x89, arg_regs
[i
], VT_LOCAL
, NULL
, loc
);
1200 /* generate function prolog of type 't' */
1201 void gfunc_prolog(CType
*func_type
)
1204 int i
, addr
, align
, size
, reg_count
;
1205 int param_index
, param_addr
, reg_param_index
, sse_param_index
;
1209 sym
= func_type
->ref
;
1210 addr
= PTR_SIZE
* 2;
1212 ind
+= FUNC_PROLOG_SIZE
;
1213 func_sub_sp_offset
= ind
;
1216 if (func_type
->ref
->c
== FUNC_ELLIPSIS
) {
1217 int seen_reg_num
, seen_sse_num
, seen_stack_size
;
1218 seen_reg_num
= seen_sse_num
= 0;
1219 /* frame pointer and return address */
1220 seen_stack_size
= PTR_SIZE
* 2;
1221 /* count the number of seen parameters */
1222 sym
= func_type
->ref
;
1223 while ((sym
= sym
->next
) != NULL
) {
1225 mode
= classify_x86_64_arg(type
, NULL
, &size
, ®_count
);
1228 seen_stack_size
+= size
;
1231 case x86_64_mode_integer
:
1232 if (seen_reg_num
+ reg_count
<= 8) {
1233 seen_reg_num
+= reg_count
;
1236 seen_stack_size
+= size
;
1240 case x86_64_mode_sse
:
1241 if (seen_sse_num
+ reg_count
<= 8) {
1242 seen_sse_num
+= reg_count
;
1245 seen_stack_size
+= size
;
1252 /* movl $0x????????, -0x10(%rbp) */
1254 gen_le32(seen_reg_num
* 8);
1255 /* movl $0x????????, -0xc(%rbp) */
1257 gen_le32(seen_sse_num
* 16 + 48);
1258 /* movl $0x????????, -0x8(%rbp) */
1260 gen_le32(seen_stack_size
);
1262 /* save all register passing arguments */
1263 for (i
= 0; i
< 8; i
++) {
1265 o(0xd60f66); /* movq */
1266 gen_modrm(7 - i
, VT_LOCAL
, NULL
, loc
);
1267 /* movq $0, loc+8(%rbp) */
1272 for (i
= 0; i
< REGN
; i
++) {
1273 push_arg_reg(REGN
-1-i
);
1277 sym
= func_type
->ref
;
1279 reg_param_index
= 0;
1280 sse_param_index
= 0;
1282 /* if the function returns a structure, then add an
1283 implicit pointer parameter */
1284 func_vt
= sym
->type
;
1285 mode
= classify_x86_64_arg(&func_vt
, NULL
, &size
, ®_count
);
1286 if (mode
== x86_64_mode_memory
) {
1287 push_arg_reg(reg_param_index
);
1294 /* define parameters */
1295 while ((sym
= sym
->next
) != NULL
) {
1297 mode
= classify_x86_64_arg(type
, NULL
, &size
, ®_count
);
1299 case x86_64_mode_sse
:
1300 if (sse_param_index
+ reg_count
<= 8) {
1301 /* save arguments passed by register */
1302 loc
-= reg_count
* 8;
1304 for (i
= 0; i
< reg_count
; ++i
) {
1305 o(0xd60f66); /* movq */
1306 gen_modrm(sse_param_index
, VT_LOCAL
, NULL
, param_addr
+ i
*8);
1312 sse_param_index
+= reg_count
;
1316 case x86_64_mode_memory
:
1317 case x86_64_mode_x87
:
1322 case x86_64_mode_integer
: {
1323 if (reg_param_index
+ reg_count
<= REGN
) {
1324 /* save arguments passed by register */
1325 loc
-= reg_count
* 8;
1327 for (i
= 0; i
< reg_count
; ++i
) {
1328 gen_modrm64(0x89, arg_regs
[reg_param_index
], VT_LOCAL
, NULL
, param_addr
+ i
*8);
1334 reg_param_index
+= reg_count
;
1339 sym_push(sym
->v
& ~SYM_FIELD
, type
,
1340 VT_LOCAL
| VT_LVAL
, param_addr
);
1345 /* generate function epilog */
1346 void gfunc_epilog(void)
1350 o(0xc9); /* leave */
1351 if (func_ret_sub
== 0) {
1354 o(0xc2); /* ret n */
1356 g(func_ret_sub
>> 8);
1358 /* align local size to word & save local variables */
1359 v
= (-loc
+ 15) & -16;
1361 ind
= func_sub_sp_offset
- FUNC_PROLOG_SIZE
;
1362 o(0xe5894855); /* push %rbp, mov %rsp, %rbp */
1363 o(0xec8148); /* sub rsp, stacksize */
1370 /* generate a jump to a label */
1373 return psym(0xe9, t
);
1376 /* generate a jump to a fixed address */
1377 void gjmp_addr(int a
)
1385 oad(0xe9, a
- ind
- 5);
1389 /* generate a test. set 'inv' to invert test. Stack entry is popped */
1390 int gtst(int inv
, int t
)
1394 v
= vtop
->r
& VT_VALMASK
;
1396 /* fast case : can jump directly since flags are set */
1397 if (vtop
->c
.i
& 0x100)
1399 /* This was a float compare. If the parity flag is set
1400 the result was unordered. For anything except != this
1401 means false and we don't jump (anding both conditions).
1402 For != this means true (oring both).
1403 Take care about inverting the test. We need to jump
1404 to our target if the result was unordered and test wasn't NE,
1405 otherwise if unordered we don't want to jump. */
1406 vtop
->c
.i
&= ~0x100;
1407 if (!inv
== (vtop
->c
.i
!= TOK_NE
))
1408 o(0x067a); /* jp +6 */
1412 t
= psym(0x8a, t
); /* jp t */
1416 t
= psym((vtop
->c
.i
- 16) ^ inv
, t
);
1417 } else if (v
== VT_JMP
|| v
== VT_JMPI
) {
1418 /* && or || optimization */
1419 if ((v
& 1) == inv
) {
1420 /* insert vtop->c jump list in t */
1423 p
= (int *)(cur_text_section
->data
+ *p
);
1431 if (is_float(vtop
->type
.t
) ||
1432 (vtop
->type
.t
& VT_BTYPE
) == VT_LLONG
) {
1436 if ((vtop
->r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) == VT_CONST
) {
1437 /* constant jmp optimization */
1438 if ((vtop
->c
.i
!= 0) != inv
)
1443 o(0xc0 + REG_VALUE(v
) * 9);
1445 t
= psym(0x85 ^ inv
, t
);
1452 /* generate an integer binary operation */
1453 void gen_opi(int op
)
1458 ll
= is64_type(vtop
[-1].type
.t
);
1459 uu
= (vtop
[-1].type
.t
& VT_UNSIGNED
) != 0;
1460 cc
= (vtop
->r
& (VT_VALMASK
| VT_LVAL
| VT_SYM
)) == VT_CONST
;
1464 case TOK_ADDC1
: /* add with carry generation */
1467 if (cc
&& (!ll
|| (int)vtop
->c
.ll
== vtop
->c
.ll
)) {
1474 /* XXX: generate inc and dec for smaller code ? */
1475 orex(ll
, r
, 0, 0x83);
1476 o(0xc0 | (opc
<< 3) | REG_VALUE(r
));
1479 orex(ll
, r
, 0, 0x81);
1480 oad(0xc0 | (opc
<< 3) | REG_VALUE(r
), c
);
1483 gv2(RC_INT
, RC_INT
);
1486 orex(ll
, r
, fr
, (opc
<< 3) | 0x01);
1487 o(0xc0 + REG_VALUE(r
) + REG_VALUE(fr
) * 8);
1490 if (op
>= TOK_ULT
&& op
<= TOK_GT
) {
1496 case TOK_SUBC1
: /* sub with carry generation */
1499 case TOK_ADDC2
: /* add with carry use */
1502 case TOK_SUBC2
: /* sub with carry use */
1515 gv2(RC_INT
, RC_INT
);
1518 orex(ll
, fr
, r
, 0xaf0f); /* imul fr, r */
1519 o(0xc0 + REG_VALUE(fr
) + REG_VALUE(r
) * 8);
1531 opc
= 0xc0 | (opc
<< 3);
1537 orex(ll
, r
, 0, 0xc1); /* shl/shr/sar $xxx, r */
1538 o(opc
| REG_VALUE(r
));
1539 g(vtop
->c
.i
& (ll
? 63 : 31));
1541 /* we generate the shift in ecx */
1542 gv2(RC_INT
, RC_RCX
);
1544 orex(ll
, r
, 0, 0xd3); /* shl/shr/sar %cl, r */
1545 o(opc
| REG_VALUE(r
));
1558 /* first operand must be in eax */
1559 /* XXX: need better constraint for second operand */
1560 gv2(RC_RAX
, RC_RCX
);
1565 orex(ll
, 0, 0, uu
? 0xd231 : 0x99); /* xor %edx,%edx : cqto */
1566 orex(ll
, fr
, 0, 0xf7); /* div fr, %eax */
1567 o((uu
? 0xf0 : 0xf8) + REG_VALUE(fr
));
1568 if (op
== '%' || op
== TOK_UMOD
)
1580 void gen_opl(int op
)
1585 /* generate a floating point operation 'v = t1 op t2' instruction. The
1586 two operands are guaranted to have the same floating point type */
1587 /* XXX: need to use ST1 and XMM1 too */
1588 void gen_opf(int op
)
1590 int a
, ft
, fc
, swapped
, r
;
1592 (vtop
->type
.t
& VT_BTYPE
) == VT_LDOUBLE
? RC_ST0
: RC_XMM0
; /* to avoid xmm1 handling for now */
1594 /* convert constants to memory references */
1595 if ((vtop
[-1].r
& (VT_VALMASK
| VT_LVAL
)) == VT_CONST
) {
1600 if ((vtop
[0].r
& (VT_VALMASK
| VT_LVAL
)) == VT_CONST
)
1603 /* must put at least one value in the floating point register */
1604 if ((vtop
[-1].r
& VT_LVAL
) &&
1605 (vtop
[0].r
& VT_LVAL
)) {
1611 /* swap the stack if needed so that t1 is the register and t2 is
1612 the memory reference */
1613 if (vtop
[-1].r
& VT_LVAL
) {
1617 if ((vtop
->type
.t
& VT_BTYPE
) == VT_LDOUBLE
) {
1618 if (op
>= TOK_ULT
&& op
<= TOK_GT
) {
1619 /* load on stack second operand */
1620 load(TREG_ST0
, vtop
);
1621 save_reg(TREG_RAX
); /* eax is used by FP comparison code */
1622 if (op
== TOK_GE
|| op
== TOK_GT
)
1624 else if (op
== TOK_EQ
|| op
== TOK_NE
)
1627 o(0xc9d9); /* fxch %st(1) */
1628 o(0xe9da); /* fucompp */
1629 o(0xe0df); /* fnstsw %ax */
1631 o(0x45e480); /* and $0x45, %ah */
1632 o(0x40fC80); /* cmp $0x40, %ah */
1633 } else if (op
== TOK_NE
) {
1634 o(0x45e480); /* and $0x45, %ah */
1635 o(0x40f480); /* xor $0x40, %ah */
1637 } else if (op
== TOK_GE
|| op
== TOK_LE
) {
1638 o(0x05c4f6); /* test $0x05, %ah */
1641 o(0x45c4f6); /* test $0x45, %ah */
1648 /* no memory reference possible for long double operations */
1649 load(TREG_ST0
, vtop
);
1673 o(0xde); /* fxxxp %st, %st(1) */
1678 if (op
>= TOK_ULT
&& op
<= TOK_GT
) {
1679 /* if saved lvalue, then we must reload it */
1682 if ((r
& VT_VALMASK
) == VT_LLOCAL
) {
1684 r
= get_reg(RC_INT
);
1686 v1
.r
= VT_LOCAL
| VT_LVAL
;
1692 if (op
== TOK_EQ
|| op
== TOK_NE
) {
1695 if (op
== TOK_LE
|| op
== TOK_LT
)
1697 if (op
== TOK_LE
|| op
== TOK_GE
) {
1698 op
= 0x93; /* setae */
1700 op
= 0x97; /* seta */
1705 o(0x7e0ff3); /* movq */
1706 gen_modrm(1, r
, vtop
->sym
, fc
);
1708 if ((vtop
->type
.t
& VT_BTYPE
) == VT_DOUBLE
) {
1711 o(0x2e0f); /* ucomisd %xmm0, %xmm1 */
1714 if ((vtop
->type
.t
& VT_BTYPE
) == VT_DOUBLE
) {
1717 o(0x2e0f); /* ucomisd */
1718 gen_modrm(0, r
, vtop
->sym
, fc
);
1723 vtop
->c
.i
= op
| 0x100;
1725 /* no memory reference possible for long double operations */
1726 if ((vtop
->type
.t
& VT_BTYPE
) == VT_LDOUBLE
) {
1727 load(TREG_XMM0
, vtop
);
1747 if ((ft
& VT_BTYPE
) == VT_LDOUBLE
) {
1748 o(0xde); /* fxxxp %st, %st(1) */
1751 /* if saved lvalue, then we must reload it */
1753 if ((r
& VT_VALMASK
) == VT_LLOCAL
) {
1755 r
= get_reg(RC_INT
);
1757 v1
.r
= VT_LOCAL
| VT_LVAL
;
1763 /* movq %xmm0,%xmm1 */
1766 load(TREG_XMM0
, vtop
);
1767 /* subsd %xmm1,%xmm0 (f2 0f 5c c1) */
1768 if ((ft
& VT_BTYPE
) == VT_DOUBLE
) {
1777 if ((ft
& VT_BTYPE
) == VT_DOUBLE
) {
1784 gen_modrm(0, r
, vtop
->sym
, fc
);
1792 /* convert integers to fp 't' type. Must handle 'int', 'unsigned int'
1793 and 'long long' cases. */
1794 void gen_cvt_itof(int t
)
1796 if ((t
& VT_BTYPE
) == VT_LDOUBLE
) {
1799 if ((vtop
->type
.t
& VT_BTYPE
) == VT_LLONG
) {
1800 /* signed long long to float/double/long double (unsigned case
1801 is handled generically) */
1802 o(0x50 + (vtop
->r
& VT_VALMASK
)); /* push r */
1803 o(0x242cdf); /* fildll (%rsp) */
1804 o(0x08c48348); /* add $8, %rsp */
1805 } else if ((vtop
->type
.t
& (VT_BTYPE
| VT_UNSIGNED
)) ==
1806 (VT_INT
| VT_UNSIGNED
)) {
1807 /* unsigned int to float/double/long double */
1808 o(0x6a); /* push $0 */
1810 o(0x50 + (vtop
->r
& VT_VALMASK
)); /* push r */
1811 o(0x242cdf); /* fildll (%rsp) */
1812 o(0x10c48348); /* add $16, %rsp */
1814 /* int to float/double/long double */
1815 o(0x50 + (vtop
->r
& VT_VALMASK
)); /* push r */
1816 o(0x2404db); /* fildl (%rsp) */
1817 o(0x08c48348); /* add $8, %rsp */
1821 save_reg(TREG_XMM0
);
1823 o(0xf2 + ((t
& VT_BTYPE
) == VT_FLOAT
));
1824 if ((vtop
->type
.t
& (VT_BTYPE
| VT_UNSIGNED
)) ==
1825 (VT_INT
| VT_UNSIGNED
) ||
1826 (vtop
->type
.t
& VT_BTYPE
) == VT_LLONG
) {
1830 o(0xc0 + (vtop
->r
& VT_VALMASK
)); /* cvtsi2sd */
1831 vtop
->r
= TREG_XMM0
;
1835 /* convert from one floating point type to another */
1836 void gen_cvt_ftof(int t
)
1844 if (bt
== VT_FLOAT
) {
1845 gv(RC_XMM0
); /* to avoid rewriting to handle xmm1 for now */
1846 if (tbt
== VT_DOUBLE
) {
1847 o(0xc0140f); /* unpcklps */
1848 o(0xc05a0f); /* cvtps2pd */
1849 } else if (tbt
== VT_LDOUBLE
) {
1850 /* movss %xmm0,-0x10(%rsp) */
1853 o(0xf02444d9); /* flds -0x10(%rsp) */
1856 } else if (bt
== VT_DOUBLE
) {
1857 gv(RC_XMM0
); /* to avoid rewriting to handle xmm1 for now */
1858 if (tbt
== VT_FLOAT
) {
1859 o(0xc0140f66); /* unpcklpd */
1860 o(0xc05a0f66); /* cvtpd2ps */
1861 } else if (tbt
== VT_LDOUBLE
) {
1862 /* movsd %xmm0,-0x10(%rsp) */
1865 o(0xf02444dd); /* fldl -0x10(%rsp) */
1870 if (tbt
== VT_DOUBLE
) {
1871 o(0xf0245cdd); /* fstpl -0x10(%rsp) */
1872 /* movsd -0x10(%rsp),%xmm0 */
1875 vtop
->r
= TREG_XMM0
;
1876 } else if (tbt
== VT_FLOAT
) {
1877 o(0xf0245cd9); /* fstps -0x10(%rsp) */
1878 /* movss -0x10(%rsp),%xmm0 */
1881 vtop
->r
= TREG_XMM0
;
1886 /* convert fp to int 't' type */
1887 void gen_cvt_ftoi(int t
)
1889 int ft
, bt
, size
, r
;
1892 if (bt
== VT_LDOUBLE
) {
1893 gen_cvt_ftof(VT_DOUBLE
);
1903 r
= get_reg(RC_INT
);
1904 if (bt
== VT_FLOAT
) {
1906 } else if (bt
== VT_DOUBLE
) {
1911 orex(size
== 8, r
, 0, 0x2c0f); /* cvttss2si or cvttsd2si */
1912 o(0xc0 + (REG_VALUE(r
) << 3));
1916 /* computed goto support */
1923 /* end of x86-64 code generator */
1924 /*************************************************************/
1925 #endif /* ! TARGET_DEFS_ONLY */
1926 /******************************************************/