History

x86-64: use r8,r9 as load/store registers

grischka committed 16 years ago

Commit 0e5c0ee1 parent cda8c411 file · +74 −43Browse files

Unified · Split

x86_64-gen.c+74−43
@@ -23,7 +23,7 @@ · 22 unmodified lines
23#ifdef TARGET_DEFS_ONLY23#ifdef TARGET_DEFS_ONLY
24 24
25/* number of available registers */25/* number of available registers */
26#define NB_REGS 526#define NB_REGS 10
27#define NB_ASM_REGS 827#define NB_ASM_REGS 8
28 28
29/* a register can belong to several classes. The classes must be29/* a register can belong to several classes. The classes must be
@@ -34,6 +34,8 @@ · 4 unmodified lines
34#define RC_RAX 0x000434#define RC_RAX 0x0004
35#define RC_RCX 0x000835#define RC_RCX 0x0008
36#define RC_RDX 0x001036#define RC_RDX 0x0010
37#define RC_R8 0x0100
38#define RC_R9 0x0200
37#define RC_XMM0 0x002039#define RC_XMM0 0x0020
38#define RC_ST0 0x0040 /* only for long double */40#define RC_ST0 0x0040 /* only for long double */
39#define RC_IRET RC_RAX /* function return: integer register */41#define RC_IRET RC_RAX /* function return: integer register */
@@ -45,16 +47,17 @@ enum { · 5 unmodified lines
45 TREG_RAX = 0,47 TREG_RAX = 0,
46 TREG_RCX = 1,48 TREG_RCX = 1,
47 TREG_RDX = 2,49 TREG_RDX = 2,
50 TREG_XMM0 = 3,
51 TREG_ST0 = 4,
52
48 TREG_RSI = 6,53 TREG_RSI = 6,
49 TREG_RDI = 7,54 TREG_RDI = 7,
50 TREG_R8 = 8,55 TREG_R8 = 8,
51 TREG_R9 = 9,56 TREG_R9 = 9,
57
52 TREG_R10 = 10,58 TREG_R10 = 10,
53 TREG_R11 = 11,59 TREG_R11 = 11,
54 60
55 TREG_XMM0 = 3,
56 TREG_ST0 = 4,
57
58 TREG_MEM = 0x10,61 TREG_MEM = 0x10,
59};62};
60 63
@@ -107,6 +110,13 @@ ST_DATA const int reg_classes[NB_REGS] = { · 46 unmodified lines
107 /* edx */ RC_INT | RC_RDX,110 /* edx */ RC_INT | RC_RDX,
108 /* xmm0 */ RC_FLOAT | RC_XMM0,111 /* xmm0 */ RC_FLOAT | RC_XMM0,
109 /* st0 */ RC_ST0,112 /* st0 */ RC_ST0,
113#if NB_REGS == 10
114 0,
115 0,
116 0,
117 RC_R8,
118 RC_R9,
119#endif
110};120};
111 121
112static unsigned long func_sub_sp_offset;122static unsigned long func_sub_sp_offset;
@@ -286,7 +296,7 @@ static void gen_modrm_impl(int op_reg, int r, Sym *sym, int c, int is_got) · 173 unmodified lines
286 g(0x00 | op_reg | REG_VALUE(r));296 g(0x00 | op_reg | REG_VALUE(r));
287 }297 }
288 } else {298 } else {
289 g(0x00 | op_reg | (r & VT_VALMASK));299 g(0x00 | op_reg | REG_VALUE(r));
290 }300 }
291}301}
292 302
@@ -364,62 +374,78 @@ void load(int r, SValue *sv) · 71 unmodified lines
364 } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {374 } else if ((ft & VT_BTYPE) == VT_LDOUBLE) {
365 o(0xdb); /* fldt */375 o(0xdb); /* fldt */
366 r = 5;376 r = 5;
367 } else if ((ft & VT_TYPE) == VT_BYTE) {
368 o(0xbe0f); /* movsbl */
369 } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
370 o(0xb60f); /* movzbl */
371 } else if ((ft & VT_TYPE) == VT_SHORT) {
372 o(0xbf0f); /* movswl */
373 } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) {
374 o(0xb70f); /* movzwl */
375 } else if (is64_type(ft)) {
376 gen_modrm64(0x8b, r, fr, sv->sym, fc);
377 return;
378 } else {377 } else {
379 o(0x8b); /* movl */378 int x;
379 if ((ft & VT_TYPE) == VT_BYTE) {
380 x = 0xbe0f; /* movsbl */
381 } else if ((ft & VT_TYPE) == (VT_BYTE | VT_UNSIGNED)) {
382 x = 0xb60f; /* movzbl */
383 } else if ((ft & VT_TYPE) == VT_SHORT) {
384 x = 0xbf0f; /* movswl */
385 } else if ((ft & VT_TYPE) == (VT_SHORT | VT_UNSIGNED)) {
386 x = 0xb70f; /* movzwl */
387 } else if (is64_type(ft)) {
388 gen_modrm64(0x8b, r, fr, sv->sym, fc);
389 return;
390 } else {
391 x = 0x8b; /* movl */
392 }
393 if (REX_BASE(r) || (!(fr & ~0x0f) && REX_BASE(fr)))
394 o(0x40 + REX_BASE(fr) + (REX_BASE(r) << 2));
395 o(x);
380 }396 }
381 gen_modrm(r, fr, sv->sym, fc);397 gen_modrm(r, fr, sv->sym, fc);
382 } else {398 } else {
383 if (v == VT_CONST) {399 if (v == VT_CONST) {
384 if (fr & VT_SYM) {400 if (fr & VT_SYM) {
385#ifdef TCC_TARGET_PE401#ifdef TCC_TARGET_PE
386 o(0x8d48);402 o(0x8d48 + (REX_BASE(r) << 2));
387 o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */403 o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
388 gen_addrpc32(fr, sv->sym, fc);404 gen_addrpc32(fr, sv->sym, fc);
389#else405#else
390 if (sv->sym->type.t & VT_STATIC) {406 if (sv->sym->type.t & VT_STATIC) {
391 o(0x8d48);407 o(0x8d48 + REX_BASE(r));
392 o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */408 o(0x05 + REG_VALUE(r) * 8); /* lea xx(%rip), r */
393 gen_addrpc32(fr, sv->sym, fc);409 gen_addrpc32(fr, sv->sym, fc);
394 } else {410 } else {
395 o(0x8b48);411 o(0x8b48 + REX_BASE(r));
396 o(0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */412 o(0x05 + REG_VALUE(r) * 8); /* mov xx(%rip), r */
397 gen_gotpcrel(r, sv->sym, fc);413 gen_gotpcrel(r, sv->sym, fc);
398 }414 }
399#endif415#endif
400 } else if (is64_type(ft)) {416 } else if (is64_type(ft)) {
401 o(0x48);417 o(0x48 + REX_BASE(r));
402 o(0xb8 + REG_VALUE(r)); /* mov $xx, r */418 o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
403 gen_le64(sv->c.ull);419 gen_le64(sv->c.ull);
404 } else {420 } else {
421 if (REX_BASE(r))
422 o(0x41);
405 o(0xb8 + REG_VALUE(r)); /* mov $xx, r */423 o(0xb8 + REG_VALUE(r)); /* mov $xx, r */
406 gen_le32(fc);424 gen_le32(fc);
407 }425 }
408 } else if (v == VT_LOCAL) {426 } else if (v == VT_LOCAL) {
409 o(0x48 | REX_BASE(r));427 o(0x48 | (REX_BASE(r) << 2));
410 o(0x8d); /* lea xxx(%ebp), r */428 o(0x8d); /* lea xxx(%ebp), r */
411 gen_modrm(r, VT_LOCAL, sv->sym, fc);429 gen_modrm(r, VT_LOCAL, sv->sym, fc);
412 } else if (v == VT_CMP) {430 } else if (v == VT_CMP) {
413 oad(0xb8 + r, 0); /* mov $0, r */431 if (REX_BASE(r))
432 o(0x41);
433 oad(0xb8 + REG_VALUE(r), 0); /* mov $0, r */
434 if (REX_BASE(r))
435 o(0x41);
414 o(0x0f); /* setxx %br */436 o(0x0f); /* setxx %br */
415 o(fc);437 o(fc);
416 o(0xc0 + r);438 o(0xc0 + REG_VALUE(r));
417 } else if (v == VT_JMP || v == VT_JMPI) {439 } else if (v == VT_JMP || v == VT_JMPI) {
418 t = v & 1;440 t = v & 1;
419 oad(0xb8 + r, t); /* mov $1, r */441 if (REX_BASE(r))
420 o(0x05eb); /* jmp after */442 o(0x41);
443 oad(0xb8 + REG_VALUE(r), t); /* mov $1, r */
444 o(0x05eb + (REX_BASE(r) << 8)); /* jmp after */
421 gsym(fc);445 gsym(fc);
422 oad(0xb8 + r, t ^ 1); /* mov $0, r */446 if (REX_BASE(r))
447 o(0x41);
448 oad(0xb8 + REG_VALUE(r), t ^ 1); /* mov $0, r */
423 } else if (v != r) {449 } else if (v != r) {
424 if (r == TREG_XMM0) {450 if (r == TREG_XMM0) {
425 assert(v == TREG_ST0);451 assert(v == TREG_ST0);
@@ -438,7 +464,7 @@ void load(int r, SValue *sv) · 12 unmodified lines
438 } else {464 } else {
439 o(0x48 | REX_BASE(r) | (REX_BASE(v) << 2));465 o(0x48 | REX_BASE(r) | (REX_BASE(v) << 2));
440 o(0x89);466 o(0x89);
441 o(0xc0 + r + v * 8); /* mov v, r */467 o(0xc0 + REG_VALUE(r) + REG_VALUE(v) * 8); /* mov v, r */
442 }468 }
443 }469 }
444 }470 }
@@ -505,9 +531,7 @@ void store(int r, SValue *v) · 60 unmodified lines
505 o(op64);531 o(op64);
506 o(3 + (r << 3));532 o(3 + (r << 3));
507 } else if (op64) {533 } else if (op64) {
508 if (fr == VT_CONST ||534 if (fr == VT_CONST || fr == VT_LOCAL || (v->r & VT_LVAL)) {
509 fr == VT_LOCAL ||
510 (v->r & VT_LVAL)) {
511 gen_modrm64(op64, r, v->r, v->sym, fc);535 gen_modrm64(op64, r, v->r, v->sym, fc);
512 } else if (fr != r) {536 } else if (fr != r) {
513 /* XXX: don't we really come here? */537 /* XXX: don't we really come here? */
@@ -515,9 +539,7 @@ void store(int r, SValue *v) · 1 unmodified line
515 o(0xc0 + fr + r * 8); /* mov r, fr */539 o(0xc0 + fr + r * 8); /* mov r, fr */
516 }540 }
517 } else {541 } else {
518 if (fr == VT_CONST ||542 if (fr == VT_CONST || fr == VT_LOCAL || (v->r & VT_LVAL)) {
519 fr == VT_LOCAL ||
520 (v->r & VT_LVAL)) {
521 gen_modrm(r, v->r, v->sym, fc);543 gen_modrm(r, v->r, v->sym, fc);
522 } else if (fr != r) {544 } else if (fr != r) {
523 /* XXX: don't we really come here? */545 /* XXX: don't we really come here? */
@@ -591,7 +613,6 @@ void gfunc_call(int nb_args) · 67 unmodified lines
591 }613 }
592 614
593 args_size = (nb_reg_args < REGN ? REGN : nb_reg_args) * PTR_SIZE;615 args_size = (nb_reg_args < REGN ? REGN : nb_reg_args) * PTR_SIZE;
594 save_regs(0); /* save used temporary registers */
595 616
596 /* for struct arguments, we need to call memcpy and the function617 /* for struct arguments, we need to call memcpy and the function
597 call breaks register passing arguments we are preparing.618 call breaks register passing arguments we are preparing.
@@ -627,12 +648,14 @@ void gfunc_call(int nb_args) · 29 unmodified lines
627 if (func_scratch < args_size)648 if (func_scratch < args_size)
628 func_scratch = args_size;649 func_scratch = args_size;
629 650
651 for (i = 0; i < REGN; ++i)
652 save_reg(arg_regs[i]);
653
630 gen_reg = nb_reg_args;654 gen_reg = nb_reg_args;
631 for(i = 0; i < nb_args; i++) {655 for(i = 0; i < nb_args; i++) {
632 bt = (vtop->type.t & VT_BTYPE);656 bt = (vtop->type.t & VT_BTYPE);
633 if (bt == VT_STRUCT || bt == VT_LDOUBLE) {657 if (bt == VT_STRUCT || bt == VT_LDOUBLE) {
634 ; /* done */658 ; /* done */
635
636 } else if (is_sse_float(vtop->type.t)) {659 } else if (is_sse_float(vtop->type.t)) {
637 gv(RC_FLOAT); /* only one float register */660 gv(RC_FLOAT); /* only one float register */
638 j = --gen_reg;661 j = --gen_reg;
@@ -641,31 +664,39 @@ void gfunc_call(int nb_args) · 2 unmodified lines
641 /* movq %xmm0, j*8(%rsp) */664 /* movq %xmm0, j*8(%rsp) */
642 gen_offs_sp(0x2444d6, 0, j*8);665 gen_offs_sp(0x2444d6, 0, j*8);
643 } else {666 } else {
644 d = arg_regs[j];
645 /* movaps %xmm0, %xmmN */667 /* movaps %xmm0, %xmmN */
646 o(0x280f);668 o(0x280f);
647 o(0xc0 + (j << 3));669 o(0xc0 + (j << 3));
670 d = arg_regs[j];
648 /* mov %xmm0, %rxx */671 /* mov %xmm0, %rxx */
649 o(0x66);672 o(0x66);
650 o(0x7e0f48 + (d >= 8));673 o(0x7e0f48 + REX_BASE(d));
651 o(0xc0 + (d & 7));674 o(0xc0 + REG_VALUE(d));
652 }675 }
653 } else {676 } else {
654 r = gv(RC_INT);
655 j = --gen_reg;677 j = --gen_reg;
656 if (j >= REGN) {678 if (j >= REGN) {
679 r = gv(RC_INT);
657 o(0x48);680 o(0x48);
658 gen_offs_sp(0x244489, r, j*8);681 gen_offs_sp(0x244489, r, j*8);
659 } else {682 } else {
660 d = arg_regs[j];683 d = arg_regs[j];
661 if (d != r) {684 if (d < NB_REGS) {
662 o(0x8948 + (d >= 8));685 gv(reg_classes[d] & ~RC_INT);
663 o(0xc0 + r*8 + (d & 7));686 } else {
687 r = gv(RC_INT);
688 if (d != r) {
689 o(0x8948 + REX_BASE(d));
690 o(0xc0 + r*8 + REG_VALUE(d));
691 }
664 }692 }
693
665 }694 }
666 }695 }
667 vtop--;696 vtop--;
668 }697 }
698
699 save_regs(0);
669 gcall_or_jmp(0);700 gcall_or_jmp(0);
670 vtop--;701 vtop--;
671}702}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t