Mercurial > hg > CbC > old > device
changeset 247:0252050601bd
mips write all code, checking compiler error begin.
author | kono |
---|---|
date | Tue, 11 May 2004 01:41:14 +0900 |
parents | 0dcc0ec81ed2 |
children | b4a57dd14801 |
files | mc-code-mips.c |
diffstat | 1 files changed, 84 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-mips.c Mon May 10 21:12:55 2004 +0900 +++ b/mc-code-mips.c Tue May 11 01:41:14 2004 +0900 @@ -2111,10 +2111,7 @@ case UMUL: printf("\tmultu %s,%s,%s\n",crn,crn,orn); break; - case DIV: - printf("\tdivw %s,%s,%s\n",crn,crn,orn); - break; - case UDIV: case MOD: case UMOD: + case DIV: case UDIV: case MOD: case UMOD: printf("\t%s $0,%s,%s\n",(op==UDIV||op==UMOD)?"divu":"div",crn,orn); printf("\t%s %s\n",(op==MOD||op==UMOD)?"mflo":"mfhi",crn); printf("\t.set noreorder\n"); @@ -3936,28 +3933,23 @@ drn_l = lregister_name_low(dx); drn_h = lregister_name_high(dx); /* - drn_l = l32( crn_l * orn_l); - drn_h = h32( crn_l * orn_l); - orn_l = l32( crn_h * orn_l); - drn_h = drn_h + orn_l; - crn_l = l32( crn_l * orn_h); - crn_h = drn_h + crn_l; + drn_l 4 = l32( crn_l * orn_l); 6, 2 + drn_h 5 = h32( crn_l * orn_l); + orn_l 6 = l32( crn_h * orn_l); 7, 3 + drn_h 5 = drn_h + orn_l; 5, 6 + crn_l 2 = l32( crn_l * orn_h); 2, 6 + crn_h 5 = drn_h + crn_l; 5, 2 crn_l = drn_l; */ - printf("\tlw $5,96($fp)\n"); - printf("\tsra $4,$5,31\n"); - printf("\tlw $2,96($fp)\n"); - printf("\tmove $3,$4\n"); - printf("\tlw $6,48($fp)\n"); - printf("\tmultu $6,$2\n"); - printf("\tmfhi $5\n"); - printf("\tmflo $4\n"); - printf("\tlw $7,48($fp)\n"); - printf("\tmult $6,$7,$3\n"); - printf("\taddu $5,$5,$6\n"); - printf("\tlw $6,52($fp)\n"); - printf("\tmult $2,$2,$6\n"); - printf("\taddu $5,$5,$2\n"); + printf("\tsra %s,%s,31\n",drn_l,orn_l); + printf("\tmultu %s,%s\n",crn_l,orn_l); + printf("\tmfhi %s\n",drn_h); + printf("\tmflo %s\n",drn_l); + printf("\tmult %s,%s,%s\n",orn_l,crn_h,orn_l); + printf("\taddu %s,%s,%s\n",drn_h,drn_h,orn_l); + printf("\tmult %s,%s,%s\n",crn_l,crn_l,orn_h); + printf("\taddu %s,%s,%s\n",crn_h,drn_h,crn_l); + printf("\tmove %s,%s\n",crn_l,drn_l); break; case LDIV: code_ldiv_lib(oreg); // ___divdi3$stub @@ -4031,40 +4023,44 @@ greg = get_register(); use_reg(greg); grn = register_name(greg); - printf("\tsrwi %s,%s,%d\n",grn,crn_l,32-v); - printf("\tslwi %s,%s,%d\n",crn_h,crn_h,v); + printf("\tsll %s,%s,%d\n",grn,crn_l,32-v); + printf("\tsrl %s,%s,%d\n",crn_h,crn_h,v); printf("\tor %s,%s,%s\n",crn_h,grn,crn_h); - printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v); + printf("\tsll %s,%s,%d\n",crn_l,crn_l,v); free_register(greg); return; case LRSHIFT: greg = get_register(); use_reg(greg); grn = register_name(greg); - printf("\tsrwi %s,%s,%d\n",grn,crn_l,v); - printf("\tinsrwi %s,%s,%d,0\n",grn,crn_h,v); - printf("\tsrawi %s,%s,%d\n",crn_h,crn_h,v); - printf("\tmr %s,%s\n",crn_l,grn); + printf("\tsrl %s,%s,%d\n",grn,crn_l,v); + printf("\tsll %s,%s,%d\n",grn,crn_h,32-v); + printf("\tor %s,%s,%d\n",grn,grn,grn); + printf("\tsra %s,%s,%d\n",crn_h,crn_h,v); free_register(greg); return; case LURSHIFT: greg = get_register(); use_reg(greg); grn = register_name(greg); - printf("\tslwi %s,%s,%d\n",grn,crn_h,32-v); - printf("\tsrwi %s,%s,%d\n",crn_l,crn_l,v); + printf("\tsll %s,%s,%d\n",grn,crn_h,32-v); + printf("\tsrl %s,%s,%d\n",crn_l,crn_l,v); printf("\tor %s,%s,%s\n",crn_l,grn,crn_l); - printf("\tsrwi %s,%s,%d\n",crn_h,crn_h,v); + printf("\tsrl %s,%s,%d\n",crn_h,crn_h,v); free_register(greg); return; case LSUB: - v = -v; + drn = register_name(dx = get_register()); + printf("\tsltu %s,%s,%d\n",drn,crn_l,-v); + printf("\tsubu %s,%s,%d\n",crn_l,crn_l,v); + printf("\tsubu %s,%s,1\n",crn_h,crn_h); + printf("\taddu %s,%s,%s\n",crn_h,crn_h,drn); + break; case LADD: - printf("\taddic %s,%s,%d\n",crn_l,crn_l,v); - if (v<0) - printf("\taddme %s,%s\n",crn_h,crn_h); - else - printf("\taddze %s,%s\n",crn_h,crn_h); + drn = register_name(dx = get_register()); + printf("\tsltu %s,%s,%d\n",drn,crn_l,v); + printf("\taddu %s,%s,%d\n",crn_l,crn_l,v); + printf("\taddu %s,%s,%s\n",crn_h,crn_h,drn); break; case LBOR: printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v); @@ -4072,6 +4068,7 @@ default: error(-1); } + if (dx!=-1) free_register(dx); } @@ -4103,8 +4100,8 @@ crn_h = lregister_name_high(lreg); crn_l = lregister_name_low(lreg); if (reg0!=regv_l(lreg)) - printf("\tmr %s,%s\n",crn_l,crn); - printf("\tsrawi %s,%s,31\n",crn_h,crn_l); + printf("\tmove %s,%s\n",crn_l,crn); + printf("\tsra %s,%s,31\n",crn_h,crn_l); } void @@ -4123,7 +4120,7 @@ crn_h = lregister_name_high(lreg); crn_l = lregister_name_low(lreg); if (reg0!=regv_l(lreg)) - printf("\tmr %s,%s\n",crn_l,crn); + printf("\tmove %s,%s\n",crn_l,crn); printf("\tli %s,0\n",crn_h); } @@ -4141,7 +4138,7 @@ crn_l = lregister_name_low(reg0=lreg); use_int(reg); if (ireg!=regv_l(reg0)) - printf("\tmr %s,%s\n",register_name(ireg),crn_l); + printf("\tmove %s,%s\n",register_name(ireg),crn_l); } void @@ -4178,7 +4175,7 @@ void code_d2ull(int reg) { - set_freg(RET_FREGISTER,1); + set_dreg(DREGISTER_OPERAND,1); extern_conv("__fixunsdfdi"); set_lreg(RET_LREGISTER,0); if (reg!=USE_CREG&®!=RET_LREGISTER) @@ -4208,7 +4205,7 @@ void code_ll2d(int reg) { - set_lreg(RET_LREGISTER,1); + set_lreg(LREGISTER_OPERAND,1); extern_conv("__floatdidf"); set_freg(RET_FREGISTER,0); if (reg!=USE_CREG&®!=RET_FREGISTER) @@ -4219,7 +4216,7 @@ void code_ll2f(int reg) { - set_lreg(RET_LREGISTER,1); + set_lreg(LREGISTER_OPERAND,1); extern_conv("__floatdisf"); set_freg(RET_FREGISTER,0); if (reg!=USE_CREG&®!=RET_FREGISTER) @@ -4241,23 +4238,34 @@ #endif static char * -addze(int dir) +ladd(int dreg,int dir) { - return dir>0?"ze":"me"; + int xreg; + char *dl=lregister_name_low(dreg); + char *dh=lregister_name_high(dreg); + char *xrn=register_name(xreg=get_register()); + if (dir>0) { + printf("\tsltu %s,%s,1\n", xrn,dl,dir); + printf("\taddu %s,%s,%d\n", dl,dl,dir); + printf("\taddu %s,%s,%d\n", dh,dh,xrn); + } else { + printf("\tsltu %s,%s,1\n", xrn,dl,-dir); + printf("\tsubu %s,%s,%d\n", dl,dl,dir); + printf("\tsubu %s,%s,1\n", dh,dh); + printf("\taddu %s,%s,%d\n", dh,dh,xrn); + } + free_register(xreg); } void code_lpreinc(int e1,int e2,int reg) { char *xrn,*drn_h,*drn_l; - int dreg,xreg; + int dreg=-1,xreg=-1; int dir=caddr(e1); if (car(e2)==LREGISTER) { - use_longlong(reg); - printf("\taddic %s,%s,%d\n", - lregister_name_low(cadr(e2)),lregister_name_low(cadr(e2)), dir); - printf("\tadd%s %s,%s\n", addze(dir), - lregister_name_high(cadr(e2)),lregister_name_high(cadr(e2))); + use_longlong(reg); + ladd(cadr(e2),dir); if (cadr(reg)!=cadr(e2)) { lmove(cadr(reg),cadr(e2)); } @@ -4277,13 +4285,15 @@ } xreg = emit_pop(0); xrn = register_name(xreg); - printf("\tlwz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); - printf("\tlwz %s,0(%s)\n",drn_h,xrn); - printf("\taddic %s,%s,%d\n",drn_l,drn_l,dir); - printf("\tadd%s %s,%s\n",addze(dir),drn_h,drn_h); - printf("\tstw %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); - printf("\tstw %s,0(%s)\n",drn_h,xrn); + dreg = get_register(); + drn_l = register_name(dreg); + printf("\tlz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); + printf("\tlz %s,0(%s)\n",drn_h,xrn); + ladd(dreg,dir); + printf("\tst %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); + printf("\tst %s,0(%s)\n",drn_h,xrn); emit_pop_free(xreg); + if (dreg!=-1) free_register(dreg); } void @@ -4296,10 +4306,7 @@ if (car(e2)==LREGISTER) { use_longlong(reg); lmove(cadr(reg),cadr(e2)); - printf("\taddic %s,%s,%d\n", - lregister_name_low(cadr(e2)),lregister_name_low(cadr(e2)), dir); - printf("\tadd%s %s,%s\n", addze(dir), - lregister_name_high(cadr(e2)),lregister_name_high(cadr(e2))); + ladd(cadr(e2),dir); return; } g_expr(e2); @@ -4316,15 +4323,15 @@ } else { drn_h = lregister_name_high(reg); drn_l = lregister_name_low(reg); + dreg = reg; } xreg = emit_pop(0); xrn = register_name(xreg); - printf("\tlwz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); - printf("\tlwz %s,0(%s)\n",drn_h,xrn); - printf("\taddic %s,%s,%d\n",nrn_l,drn_l,dir); - printf("\tadd%s %s,%s\n",addze(dir),nrn_h,drn_h); - printf("\tstw %s,%d(%s)\n",nrn_l,SIZE_OF_INT,xrn); - printf("\tstw %s,0(%s)\n",nrn_h,xrn); + printf("\tlw %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn); + printf("\tlw %s,0(%s)\n",drn_h,xrn); + ladd(dreg,dir); + printf("\tsw %s,%d(%s)\n",nrn_l,SIZE_OF_INT,xrn); + printf("\tsw %s,0(%s)\n",nrn_h,xrn); emit_pop_free(xreg); free_register(nreg); } @@ -4343,19 +4350,20 @@ use_longlong(reg); if (regv_l(lreg)==edx || regv_h(lreg)==edx) { edx0 = get_register(); if(!edx0) error(-1); - printf("# lassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx)); + printf("# lassop\n\tmove %s,%s\n",register_name(edx0), + register_name(edx)); edx = edx0; } - printf("\tlwz %s,0(%s)\n",lregister_name_high(reg), + printf("\tlw %s,0(%s)\n",lregister_name_high(reg), register_name(edx)); - printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg), + printf("\tlw %s,%d(%s)\n",lregister_name_low(reg), SIZE_OF_INT,register_name(edx)); free_register(edx); ltosop(op,reg,xreg); edx = emit_pop(0); - printf("\tstw %s,0(%s)\n",lregister_name_high(reg), + printf("\tsw %s,0(%s)\n",lregister_name_high(reg), register_name(edx)); - printf("\tstw %s,%d(%s)\n",lregister_name_low(reg), + printf("\tsw %s,%d(%s)\n",lregister_name_low(reg), SIZE_OF_INT,register_name(edx)); free_register(edx); emit_lpop_free(xreg);