Mercurial > hg > CbC > old > device
diff mc-code-ia32.c @ 242:c68f618b71f9
ia32 long long done. some error remains.
author | kono |
---|---|
date | Tue, 04 May 2004 09:51:28 +0900 |
parents | 96b5ee862a41 |
children | c311c26e006a |
line wrap: on
line diff
--- a/mc-code-ia32.c Tue May 04 03:15:43 2004 +0900 +++ b/mc-code-ia32.c Tue May 04 09:51:28 2004 +0900 @@ -173,7 +173,7 @@ static void code_save_stacks(); #define use_int(reg) if (reg==-1) reg=use_int0() -static int use_int0() { lreg = 0; if (!is_int_reg(creg)) creg = virtual(REG_EBX); return creg; } +static int use_int0() { lreg = 0; if (!is_int_reg(creg)) { creg = virtual(REG_EBX); regs[creg]=1;} return creg; } #define use_longlong(reg) reg=use_longlong0(reg) static int @@ -1641,7 +1641,7 @@ void code_leave(char *name) { - disp&= -size_of_int; + disp &= -size_of_int; printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset); printf("_%d:\n",labelno); printf("\t.size\t%s,_%d-%s\n",name,labelno,name); @@ -2321,7 +2321,7 @@ emit_lpush(); g_expr(e2); ltosop(LSUB,USE_CREG,(e3==emit_lpop())); - printf("\tpopl %%eax\n\tpopl %%edx\n"); // emit_pop_free +// printf("\tpopl %%eax\n\tpopl %%edx\n"); // emit_pop_free switch(op) { case LOP+GT: pcond(code_gt(cond),l1); break; @@ -2417,11 +2417,11 @@ void code_lassign_lregister(int e2,int reg) { - + // e2 = reg use_longlong(reg); if (e2!=reg) { - printf("\tmovl %s,%s\n",l_eax(e2),l_eax(reg)); - printf("\tmovl %s,%s\n",l_edx(e2),l_edx(reg)); + printf("\tmovl %s,%s\n",l_eax(reg),l_eax(e2)); + printf("\tmovl %s,%s\n",l_edx(reg),l_edx(e2)); } } @@ -2457,7 +2457,7 @@ printf("\tmovl %d(%%ebp),%s\n",lvar(e1)+4,l_edx(e2)); } -#define check_lreg() if (reg==REG_L) code_lassign_lregister(REG_LCREG,reg) +#define check_lreg(reg) if (reg==REG_L) code_lassign_lregister(reg,REG_LCREG) void ltosop(int op,int reg,int e2) @@ -2482,7 +2482,7 @@ printf("\txorl %%eax,%%eax\n"); fwddef(lb); printf("\tpopl %%ecx\n"); - check_lreg(); + check_lreg(reg); return; case LRSHIFT: printf("\tmovl %%ecx,4(%%esp)\n"); @@ -2495,7 +2495,7 @@ printf("\tsarl $31,%%edx\n"); fwddef(lb); printf("\tpopl %%ecx\n"); - check_lreg(); + check_lreg(reg); return; case LURSHIFT: printf("\tmovl %%ecx,4(%%esp)\n"); @@ -2508,7 +2508,7 @@ printf("\txorl %%edx,%%edx\n"); fwddef(lb); printf("\tpopl %%ecx\n"); - check_lreg(); + check_lreg(reg); return; } switch(op) { @@ -2522,6 +2522,7 @@ printf("\tpushl %%edx\n"); printf("\tpushl %%eax\n"); printf("\tpushl %%ecx\n"); + // 0 saved ecx // 4 c_l // 8 c_h // 12 o_l @@ -2534,7 +2535,8 @@ printf("\timull 12(%%esp),%%ecx\n"); // c_h*o_l->%ecx printf("\taddl %%ecx,%%edx\n"); // %edx+%ecx->%edx printf("\tpopl %%ecx\n"); - printf("\taddl $16,%%esp\n"); + // printf("\taddl $8,%%esp\n"); + printf("\tlea 16(%%esp),%%esp\n"); return; case LDIV: call="__divdi3"; break; case LUDIV: call="__udivdi3"; break; @@ -2544,13 +2546,15 @@ } if (opl) { printf("\t%s (%%esp),%%eax\n\t%s 4(%%esp),%%edx\n",opl,oph); - check_lreg(); + printf("\tlea 8(%%esp),%%esp\n"); + check_lreg(reg); } else if (call) { printf("\tpushl %%edx\n"); printf("\tpushl %%eax\n"); printf("\tcall %s\n",call); - printf("\taddl $8,%%esp\n"); - check_lreg(); + // printf("\taddl $8,%%esp\n"); + printf("\tlea 16(%%esp),%%esp\n"); + check_lreg(reg); } else { error(-1); } @@ -2600,17 +2604,17 @@ case LULSHIFT: printf("\tshldl $%d,%%eax,%%edx\n",vl); printf("\tsall $%d,%%eax\n",vl); - check_lreg(); + check_lreg(reg); return; case LRSHIFT: - printf("\tshrdl $%d,%%eax,%%edx\n",vl); - printf("\tsarl $%d,%%eax\n",vl); - check_lreg(); + printf("\tshrdl $%d,%%edx,%%eax\n",vl); + printf("\tsarl $%d,%%edx\n",vl); + check_lreg(reg); return; case LURSHIFT: - printf("\tshrdl $%d,%%eax,%%edx\n",vl); - printf("\tshrl $%d,%%eax\n",vl); - check_lreg(); + printf("\tshrdl $%d,%%edx,%%eax\n",vl); + printf("\tshrl $%d,%%edx\n",vl); + check_lreg(reg); return; } switch(op) { @@ -2622,12 +2626,12 @@ default: error(-1); } printf("\t%s $%d,%%eax\n\t%s $%d,%%edx\n",opl,vl,oph,vh); - check_lreg(); + check_lreg(reg); } void emit_lpop_free(int e1) { - printf("\taddl $8,%%esp\n"); +// printf("\taddl $8,%%esp\n"); } void emit_lpush() @@ -2642,10 +2646,7 @@ regv[creg]=0; use_longlong(reg0); printf("\tcltd\n"); - if (reg==REG_L) { - code_lassign_lregister(reg0,reg); - reg0 = reg; - } + check_lreg(reg); lreg = creg = reg0; } @@ -2661,10 +2662,7 @@ regv[creg]=0; use_longlong(reg0); printf("\txorl %%edx,%%edx\n"); - if (reg==REG_L) { - code_lassign_lregister(reg0,reg); - reg0 = reg; - } + check_lreg(reg); lreg = creg = reg0; } @@ -2730,7 +2728,7 @@ { use_longlong(reg); printf("\tsubl $16,%%esp\n"); - printf("\tfstpl (%%esp)\n"); + printf("\tfstps (%%esp)\n"); printf("\tcall __fixunssfdi\n"); printf("\taddl $16,%%esp\n"); }