Mercurial > hg > CbC > old > device
changeset 242:c68f618b71f9
ia32 long long done. some error remains.
author | kono |
---|---|
date | Tue, 04 May 2004 09:51:28 +0900 |
parents | 96b5ee862a41 |
children | c311c26e006a |
files | mc-code-ia32.c test/code-gen.c |
diffstat | 2 files changed, 44 insertions(+), 38 deletions(-) [+] |
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"); }
--- a/test/code-gen.c Tue May 04 03:15:43 2004 +0900 +++ b/test/code-gen.c Tue May 04 09:51:28 2004 +0900 @@ -1232,6 +1232,7 @@ u1 = 632423423; u2= 32394234; ii2 = -33; uu2 = 33; + u = 0; i = i1 + i2; printf("ltosop 1 %lld\n",i); @@ -1247,17 +1248,23 @@ printf("ltosop 6 %lld\n",i); i = i1 ^ i2; printf("ltosop 7 %lld\n",i); + printf("ltosop uuu -2 %llu=%llu/%llu\n",u,u1,u2); i = i1 << i2; printf("ltosop 8 %lld\n",i); + printf("ltosop uuu -1 %llu=%llu/%llu\n",u,u1,u2); i = i1 >> i2; + printf("ltosop uuu 0 %llu=%llu/%llu\n",u,u1,u2); printf("ltosop 9 %lld\n",i); i = i1 % i2; + printf("ltosop uuu 0.0 %llu=%llu/%llu\n",u,u1,u2); printf("ltosop 10 %lld\n",i); + printf("ltosop uuu 1 %llu=%llu/%llu\n",u,u1,u2); u = u1 + u2; printf("ltosop u 1 %llu\n",u); u = u1 - u2; printf("ltosop u 2 %llu\n",u); + printf("ltosop uuu 2 %llu=%llu/%llu\n",u,u1,u2); u = u1 / u2; printf("ltosop u 3 %llu\n",u); u = u1 * u2; @@ -1296,6 +1303,7 @@ i = i1 % ii2; printf("litosop 10 %lld\n",i); + printf("litosop uuu %llu=%llu+%u\n",u,u1,uu2); u = u1 + uu2; printf("litosop u 1 %llu\n",u); u = u1 - uu2; @@ -1480,7 +1488,7 @@ float i; i = 2342342342LL; d = i; - printf("code_d2ll %lld\n",d); + printf("code_f2ll %lld\n",d); } // code_f2ull(int creg) void @@ -1490,7 +1498,7 @@ float i; i = 2342342342LL; d = i; - printf("code_d2ll %llu\n",d); + printf("code_f2ull %llu\n",d); } // code_ll2d(int creg) void @@ -1500,7 +1508,7 @@ double i; d = 2342342342LL; i = d; - printf("code_d2ll %g\n",i); + printf("code_ll2d %g\n",i); } // code_ll2f(int creg) void @@ -1510,7 +1518,7 @@ float i; d = 2342342342LL; i = d; - printf("code_d2ll %g\n",i); + printf("code_ll2f %g\n",i); } // code_ull2d(int creg) void @@ -1520,7 +1528,7 @@ double i; d = 2342342342LL; i = d; - printf("code_d2ll %g\n",i); + printf("code_ull2f %g\n",i); } // code_ull2f(int creg) void @@ -1530,7 +1538,7 @@ float i; d = 2342342342LL; i = d; - printf("code_d2ll %g\n",i); + printf("code_ull2f %g\n",i); } #endif