Mercurial > hg > CbC > old > device
changeset 626:5bd74f52df62
Intel continue...
author | kono |
---|---|
date | Tue, 10 Oct 2006 01:57:12 +0900 |
parents | 4b4c6b1ea69a |
children | 65eb070e731c |
files | Changes mc-code-ia32.c |
diffstat | 2 files changed, 165 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Oct 07 20:24:41 2006 +0900 +++ b/Changes Tue Oct 10 01:57:12 2006 +0900 @@ -8896,11 +8896,12 @@ ということは、デフォルトでレジスタが二つ潰れるわけね。 +で、ptr_cache は使うの? ううーん... 使っても害はないはず。 +ptr_cache は get_register() が絶対失敗しないことに依存している +んだよね。 + そして、浮動小数点の計算は、すべて mmx(sse2) らしい。ぶぅ。 mmx は 8 個レジスタがあるわけね。 - - - - - +もしかすると、修正は以外に少ないかも。 +
--- a/mc-code-ia32.c Sat Oct 07 20:24:41 2006 +0900 +++ b/mc-code-ia32.c Tue Oct 10 01:57:12 2006 +0900 @@ -29,6 +29,11 @@ #include "mc-codegen.h" #include "mc-code.h" +#ifdef __APPLE__ +#define USE_SSE2 +#define USE_PIC +#endif + #if defined(__GNUC__) && __GNUC__ >= 4 #include "mc-include.c" @@ -273,7 +278,9 @@ static int code_disp_label; static int func_disp_label; -// static int goffset_label; +#ifdef __APPLE__ +static int goffset_label; +#endif static int lvar(int l) @@ -908,10 +915,14 @@ use_int(creg); #ifdef __APPLE__ if (cadr(e1)) { - printf("\tmovl $_%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), + printf("\tmovl L_%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label, + register_name(creg,0)); + printf("\taddl $%d,%s\n", cadr(e1), register_name(creg,0)); } else { - printf("\tmovl $_%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0)); + printf("\tmovl L_%s-_%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label,register_name(creg,0)); } #else if (cadr(e1)) { @@ -929,10 +940,20 @@ use_int(creg); #ifdef __APPLE__ if (cadr(e1)) { - printf("\tmovl _%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), + printf("\tmovl L_%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label, + register_name(creg,0)); + printf("\tmovl %d(%s),%s\n", + cadr(e1), register_name(creg,0), register_name(creg,0)); - } else - printf("\tmovl _%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0)); + } else { + printf("\tmovl L_%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label, + register_name(creg,0)); + printf("\tmovl %d(%s),%s\n", + cadr(e1), register_name(creg,0), + register_name(creg,0)); + } #else if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), @@ -954,11 +975,20 @@ use_int(creg); #ifdef __APPLE__ if (cadr(e1)) { - printf("\t%s _%s+%d,%s\n",cload(sign,sz), - ((NMTBL*)caddr(e1))->nm,cadr(e1),register_name(creg,0)); - } else - printf("\t%s _%s,%s\n",cload(sign,sz), - ((NMTBL*)caddr(e1))->nm,register_name(creg,0)); + printf("\tmovl L_%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label, + register_name(creg,0)); + printf("\t%s %d(%s),%s\n",cload(sign,sz), + cadr(e1), register_name(creg,0), + register_name(creg,0)); + } else { + printf("\tmovl L_%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label, + register_name(creg,0)); + printf("\t%s %d(%s),%s\n",cload(sign,sz), + cadr(e1), register_name(creg,0), + register_name(creg,0)); + } #else if (cadr(e1)) { printf("\t%s %s+%d,%s\n",cload(sign,sz), @@ -1036,7 +1066,8 @@ code_fname(NMTBL *n,int creg) { use_int(creg); #ifdef __APPLE__ - printf("\tmovl $_%s,%s\n",n->nm,register_name(creg,0)); + printf("\tleal _%s-_%d(%%ebx),%s\n", + n->nm,goffset_label,register_name(creg,0)); #else printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0)); #endif @@ -1045,7 +1076,12 @@ void code_label_value(int label,int reg) { use_int(reg); +#ifdef __APPLE__ + printf("\tleal _%d-_%d(%%ebx),%s\n", + label,goffset_label,register_name(reg,0)); +#else printf("\tleal _%d,%s\n",label,register_name(reg,0)); +#endif } void @@ -1190,16 +1226,19 @@ code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { use_int(reg); #ifdef __APPLE__ + printf("\tmovl L_%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e1))->nm, + goffset_label, + register_name(reg,0)); if (cadr(e1)) { if (sz==1) - printf("\tcmpb $0,_%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); + printf("\tcmpb $0,%d(%s)\n",cadr(e1),register_name(reg,0)); else if (sz==SIZE_OF_SHORT) - printf("\tcmpw $0,_%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); + printf("\tcmpw $0,%d(%s)\n",cadr(e1),register_name(reg,0)); } else { if (sz==1) - printf("\tcmpb $0,_%s\n",((NMTBL*)caddr(e1))->nm); + printf("\tcmpb $0,(%s)\n",register_name(reg,0)); else if (sz==SIZE_OF_SHORT) - printf("\tcmpw $0,_%s\n",((NMTBL*)caddr(e1))->nm); + printf("\tcmpw $0,(%s)\n",register_name(reg,0)); } #else if (cadr(e1)) { @@ -1283,7 +1322,13 @@ } else { text_mode(0); } +#ifdef __APPLE__ + printf("\tmovl _%d-%d(%%ebx),%s\n",lb, + goffset_label, + register_name(creg,0)); +#else printf("\tlea _%d,%s\n",lb,register_name(creg,0)); +#endif set_attr(n,LABEL,lb); } @@ -1633,10 +1678,17 @@ if (byte) { use_data_reg(creg,1); } else { use_int(creg); } #ifdef __APPLE__ + int dreg = get_register(); + printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, + goffset_label, + register_name(dreg,0)); if (cadr(e2)) - printf("\t%s %s,_%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2)); + printf("\t%s %s,%d(%s)\n",move(byte),register_name(creg,byte), + cadr(e2),register_name(dreg,0)); else - printf("\t%s %s,_%s\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm); + printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte), + register_name(dreg,0)); + free_register(dreg); #else if (cadr(e2)) printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2)); @@ -2045,12 +2097,11 @@ func_disp_label=fwdlabel(); printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label); #ifdef __APPLE__ -#if 0 - printf("\tcalli\t___i686.get_pc_thunk.cx\n"); + printf("\tcalli\t___i686.get_pc_thunk.bx\n"); printf("_%d:\n",labelno); goffset_label = labelno; labelno++; -#endif + regs[REG_EBX] = 1; #endif control=1; @@ -2512,10 +2563,16 @@ void code_dassign_gvar(int e2,int freg,int d) { #ifdef __APPLE__ + int dreg; + dreg = get_register(); + printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, + goffset_label, + register_name(dreg,0)); if (cadr(e2)) - printf("\t%s _%s+%d\n",fstore(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); + printf("\t%s %d(%s)\n",fstore(d),cadr(e2),register_name(dreg,0)); else - printf("\t%s _%s\n",fstore(d),((NMTBL*)caddr(e2))->nm); + printf("\t%s (%s)\n",fstore(d),register_name(dreg,0)); + free_register(dreg); #else if (cadr(e2)) printf("\t%s %s+%d\n",fstore(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); @@ -2581,7 +2638,11 @@ } else { text_mode(0); } +#ifdef __APPLE__ + printf("\tfldl _%d-_%d(%%ebx)\n",lb,goffset_label); +#else printf("\tfldl _%d\n",lb); +#endif } void @@ -2662,10 +2723,16 @@ void code_drgvar(int e2,int d,int freg) { #ifdef __APPLE__ + int dreg; + dreg = get_register(); + printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, + goffset_label, + register_name(dreg,0)); if (cadr(e2)) - printf("\t%s _%s+%d\n",fload(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); + printf("\t%s %d(%s)\n",fload(d),cadr(e2),register_name(dreg,0)); else - printf("\t%s _%s\n",fload(d),((NMTBL*)caddr(e2))->nm); + printf("\t%s (%s)\n",fload(d),register_name(dreg,0)); + free_register(dreg); #else if (cadr(e2)) printf("\t%s %s+%d\n",fload(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); @@ -2683,10 +2750,16 @@ void code_cmp_drgvar(int e2,int reg,int d,int label,int cond) { #ifdef __APPLE__ + int dreg; + dreg = get_register(); + printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, + goffset_label, + register_name(dreg,0)); if (cadr(e2)) - printf("\tfcomp _%s+%d\n",((NMTBL*)caddr(e2))->nm,cadr(e2)); + printf("\tfcomp %d(%s)\n",cadr(e2),register_name(dreg,0)); else - printf("\tfcomp _%s\n",((NMTBL*)caddr(e2))->nm); + printf("\tfcomp (%s)\n",register_name(dreg,0)); + free_register(dreg); #else if (cadr(e2)) printf("\tfcomp %s+%d\n",((NMTBL*)caddr(e2))->nm,cadr(e2)); @@ -3042,13 +3115,21 @@ use_int(e2); crn = register_name(e2,0); #ifdef __APPLE__ + int dreg; + char *drn; + dreg = get_register(); + drn = register_name(dreg,0); + printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, + goffset_label, drn); + if (cadr(e1)) { - printf("\tmovl _%s+%d,%s\n",n,cadr(e1),crn); - printf("\torl _%s+%d,%s\n",n,cadr(e1)+4,crn); + printf("\tmovl %d(%s),%s\n",cadr(e1),drn,crn); + printf("\torl %d(%s),%s\n",cadr(e1)+4,drn,crn); } else { - printf("\tmovl _%s,%s\n",n,crn); - printf("\torl _%s+4,%s\n",n,crn); + printf("\tmovl (%s),%s\n",drn,crn); + printf("\torl 4(%s),%s\n",drn,crn); } + free_register(dreg); #else if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",n,cadr(e1),crn); @@ -3092,13 +3173,21 @@ use_longlong(e2); #if ENDIAN_L==0 #ifdef __APPLE__ + int dreg; + char *drn; + dreg = get_register(); + drn = register_name(dreg,0); + printf("\tmovl _%s-%d(%%ebx),%s\n",((NMTBL*)caddr(e2))->nm, + goffset_label, + register_name(dreg,0)); if (cadr(e1)) { - printf("\tmovl %s,_%s+%d\n",l_eax(e2),n,cadr(e1)); - printf("\tmovl %s,_%s+%d\n",l_edx(e2),n,cadr(e1)+4); + printf("\tmovl %s,%d(%s)\n",l_eax(e2),cadr(e1),drn); + printf("\tmovl %s,%d(%s)\n",l_edx(e2),cadr(e1)+4,drn); } else { - printf("\tmovl %s,_%s\n",l_eax(e2),n); - printf("\tmovl %s,_%s+4\n",l_edx(e2),n); + printf("\tmovl %s,(%s)\n",l_eax(e2),drn); + printf("\tmovl %s,4(%s)\n",l_edx(e2),drn); } + free_register(dreg); #else if (cadr(e1)) { printf("\tmovl %s,%s+%d\n",l_eax(e2),n,cadr(e1)); @@ -3155,12 +3244,14 @@ use_longlong(e2); #if ENDIAN_L==0 #ifdef __APPLE__ + printf("\tmovl _%s-%d(%%ebx),%s\n",n, + goffset_label,l_edx(e2)); if (cadr(e1)) { - printf("\tmovl _%s+%d,%s\n",n,cadr(e1),l_eax(e2)); - printf("\tmovl _%s+%d,%s\n",n,cadr(e1)+4,l_edx(e2)); + printf("\tmovl %d(%s),%s\n",cadr(e1),l_edx(e2),l_eax(e2)); + printf("\tmovl %d(%s),%s\n",cadr(e1)+4,l_edx(e2),l_edx(e2)); } else { - printf("\tmovl _%s,%s\n",n,l_eax(e2)); - printf("\tmovl _%s+4,%s\n",n,l_edx(e2)); + printf("\tmovl (%s),%s\n",l_edx(e2),l_eax(e2)); + printf("\tmovl 4(%s),%s\n",l_edx(e2),l_edx(e2)); } #else if (cadr(e1)) { @@ -3615,28 +3706,49 @@ printf("\tcmpl\t$%d,%s\n",max-min,crn); printf("\tja\t_%d\n",dlabel); if (delta==1) { +#ifdef __APPLE__ + printf("\tmovl\t_%d-%d(%%ebx,%s,4)\n",l,goffset_label,crn); + printf("\tjmp\t*%s\n",crn); +#else printf("\tjmp\t*_%d(,%s,4)\n",l,crn); +#endif return; } use_register(creg,REG_EAX,1); + crn = register_name(creg,0); switch(delta) { case 2: printf("\tmovl\t$1,%%edx\n"); printf("\tandl\t%%eax,%%edx\n"); printf("\tjne\t_%d\n",dlabel); +#ifdef __APPLE__ + printf("\tmovl\t_%d-%d(%%ebx,%s,2)\n",l,goffset_label,crn); + printf("\tjmp\t*%s\n",crn); +#else printf("\tjmp\t*_%d(,%%eax,2)\n",l); break; +#endif case 4: printf("\tmovl\t$3,%%edx\n"); printf("\tandl\t%%eax,%%edx\n"); printf("\tjne\t_%d\n",dlabel); +#ifdef __APPLE__ + printf("\tmovl\t_%d-%d(%%ebx,%s)\n",l,goffset_label,crn); + printf("\tjmp\t*%s\n",crn); +#else printf("\tjmp\t*_%d(%%eax)\n",l); break; +#endif default: printf("\tmovl $%d,%%ecx\n",delta); printf("\txor %%edx,%%edx\n\tdivl %%ecx\n"); printf("\tandl\t%%edx,%%edx\n"); printf("\tjne\t_%d\n",dlabel); +#ifdef __APPLE__ + printf("\tmovl\t_%d-%d(%%ebx,%s,4)\n",l,goffset_label,crn); + printf("\tjmp\t*%s\n",crn); +#else printf("\tjmp\t*_%d(,%%eax,4)\n",l); break; +#endif } } @@ -3682,9 +3794,17 @@ } else if (car(rstr)==CONST) { printf("%d",cadr(rstr)); } else if (car(rstr)==FNAME) { +#ifdef __APPLE + printf("_%s-_%d",(char*)cadr(rstr),goffset_label); +#else printf("%s",(char*)cadr(rstr)); +#endif } else if (car(rstr)==STRING) { +#ifdef __APPLE + printf("_%d-_%d",cadr(rstr),goffset_label); +#else printf("_%d",cadr(rstr)); +#endif } else { error(-1); }