changeset 390:15cf97ce7db1

*** empty log message ***
author kono
date Sat, 04 Sep 2004 14:15:41 +0900
parents 68fb244e0e3c
children a460a3f118d1
files .gdbinit Changes mc-code-arm.c
diffstat 3 files changed, 78 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Fri Sep 03 23:27:04 2004 +0900
+++ b/.gdbinit	Sat Sep 04 14:15:41 2004 +0900
@@ -1,12 +1,12 @@
 tb main
 # run  -s test/arg.c
 # run  -s mc-parse.c
-run  -s mc-codegen.c
+# run  -s mc-codegen.c
 # run  -s nkf203/nkf.c
 # run  -s -ob01.s mc-switch.c
 # run  -s l.c
 # run  -s test/bitfield.c
-# run -s test/code-gen-all.c
+run -s test/code-gen-all.c
 define regs 
 printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
 printf "r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
--- a/Changes	Fri Sep 03 23:27:04 2004 +0900
+++ b/Changes	Sat Sep 04 14:15:41 2004 +0900
@@ -5949,3 +5949,5 @@
 Thu Sep  2 20:46:56 JST 2004
 
 そういえば Input register をtmpに使わないのはなんで?
+
+順調にバグ取りは進んではいるんだけど...
--- a/mc-code-arm.c	Fri Sep 03 23:27:04 2004 +0900
+++ b/mc-code-arm.c	Sat Sep 04 14:15:41 2004 +0900
@@ -1289,7 +1289,7 @@
     for(sign=1;sign>=-1;sign-=2) {
 	int d;
         if (sign==1) { d = c; } else { d = mode==CMP?-c:~c; }
-	if (mask8(d,0)||d==0) {
+	if (mask8(d,0)==d||d==0) {
 	    min_stage=1; min_stage=1; msign = sign;
 		mim = d;mjm = 0;mkm = 0;
 	    break;
@@ -1552,8 +1552,8 @@
 code_not(int creg) {
     use_int(creg);
     inc_inst(1);
-    printf("\tmvn\t%s, %s, %s\n", 
-	register_name(creg), register_name(creg),register_name(creg));
+    printf("\tmvn\t%s, %s\n", 
+	register_name(creg), register_name(creg));
 }
 
 
@@ -1651,17 +1651,26 @@
 }
 
 static int rexpr_bool(int e1, int reg);
+static int lrexpr_bool(int e1, int reg);
 
 void
 code_bool(int e1,int reg) {
-
-
+    int e2,e3;
+    char *xrn;
     if (rexpr_bool(e1, reg)) return;
-    b_expr(e1,1,0,1);  /* including > < ... */
-    use_int(reg);
-    inc_inst(2);
-    printf("\tmovne\t%s, #0\n", register_name(reg));
-    printf("\tmoveq\t%s, #1\n", register_name(reg));
+    if (lrexpr_bool(e1, reg)) return;
+    b_expr(e1,1,e2=fwdlabel(),1);  /* including > < ... */
+    if (use) {
+        use_int(reg);
+        xrn = register_name(reg);
+        printf("\tmov\t%s, #0\n",xrn);
+        jmp(e3=fwdlabel());
+        fwddef(e2);
+        printf("\tmov\t%s, #1\n",xrn);
+        fwddef(e3);
+    } else {
+        fwddef(e2);
+    }
 }
 
 char *
@@ -1823,9 +1832,9 @@
 	}
 	clear_ptr_cache();
 	code_save_stacks();
-	code_register(from,0);
-	code_register(to,1);
-	code_const(length,2);
+	code_register(from,1);
+	code_register(to,2);
+	code_const(length,3);
         /* overrap must be allowed */
 	inc_inst(1);
 	printf("\tbl\t%s\n",memmove);
@@ -2688,7 +2697,7 @@
     tosop(op,ireg,xreg);
     crn = register_name(ireg);
     drn = register_name(creg);
-    printf("\t%s\t%s, [%s, #0]",cstore(byte),crn,drn);
+    printf("\t%s\t%s, [%s, #0]\n",cstore(byte),crn,drn);
     free_register(edx);
     emit_pop_free(xreg);
     inc_inst(1);
@@ -2700,7 +2709,8 @@
 {
     int dx = -1;
     int ox = -1;
-    char *orn,*crn;
+    char *orn,*crn,*drn;
+    int creg0 = creg;
     // creg = creg op oreg
 
     use_int(creg);
@@ -2719,11 +2729,11 @@
 	if(ox!=-1) free_register(ox);
 	return;
     case RSHIFT:
-	shift("sra",creg,oreg);
+	shift("asr",creg,oreg);
 	if(ox!=-1) free_register(ox);
 	return;
     case URSHIFT:
-	shift("asr",creg,oreg);
+	shift("lsr",creg,oreg);
 	if(ox!=-1) free_register(ox);
 	return;
     }
@@ -2757,7 +2767,13 @@
     case MUL:
     case UMUL:
 	inc_inst(1);
-	printf("\tmul\t%s, %s, %s\n",crn,crn,orn);
+	drn = register_name(dx = get_register());
+	printf("\tmul\t%s, %s, %s\n",drn,crn,orn);
+	if (creg0==USE_CREG) {
+	    set_ireg(dx,0);
+	} else {
+	    printf("\tmov\t%s, %s\n",crn,drn);
+	}
 	break;
     case DIV:
 	code_int_lib("__divsi3",creg,oreg); break;
@@ -2844,7 +2860,7 @@
     use_int(creg);
     crn = register_name(creg);
     inc_inst(1);
-    printf("\tmov\t%s, %s, %s %s\n",crn,crn,op,rrn);
+    printf("\tmov\t%s, %s, %s  %s\n",crn,crn,op,rrn);
 }
 
 void
@@ -2940,8 +2956,8 @@
 	inc_inst(1);
     } else if (mode==COND_VALUE) {
 	rn0 =		register_name(r0);
-	printf("\tmov%s\t%s, #0\n",ncc,rn2);
-	printf("\tmov%s\t%s, #1\n",cc,rn2);
+	printf("\tmov%s\t%s, #0\n",ncc,rn0);
+	printf("\tmov%s\t%s, #1\n",cc,rn0);
 	inc_inst(2);
     } else error(-1);
 }
@@ -2962,7 +2978,7 @@
     e2 = emit_pop(1);
     reg0 = ireg;
     use_int(reg);
-    pcond(op, reg,e2,reg0,1,0,COND_VALUE);
+    pcond(op, reg0,e2,reg,1,0,COND_VALUE);
     emit_pop_free(e2);
     return 1;
 }
@@ -2977,7 +2993,7 @@
     emit_push();
     g_expr(caddr(e1));
     e2 = emit_pop(1);
-    pcond(op, e2,e2,ireg,cond,l1,COND_BRANCH);
+    pcond(op, ireg,e2,0,cond,l1,COND_BRANCH);
     emit_pop_free(e2);
 }
 
@@ -3013,7 +3029,7 @@
     int i;
     inc_inst(1);
     printf("\tstmfd\tsp!, {");
-    for (i=reg_var_num(0);i>reg_var_num(reg_save);i--) {
+    for (i=reg_var_num(reg_save)-1;i<=reg_var_num(0);i++) {
 	    printf("%s, ",register_name(i));
 	disp -= SIZE_OF_INT;
     }
@@ -3037,7 +3053,7 @@
     }
     inc_inst(1);
     printf("\tldmea\tfp, {");
-    for (i=reg_var_num(0);i>reg_var_num(reg_save);i--) {
+    for (i=reg_var_num(reg_save)-1;i<=reg_var_num(0);i++) {
 	    printf("%s, ",register_name(i));
 	disp -= SIZE_OF_INT;
     }
@@ -3268,7 +3284,7 @@
 
     lb=fwdlabel();
     // should put on different segement
-    printf("\t.rdata\n\t.align 2\n");
+    printf(".section\t.rodata\n\t.align 2\n");
     printf(".L%d:\n",lb);
     output_mode = RODATA_EMIT_MODE;
     return lb;
@@ -3559,7 +3575,7 @@
 	if (freg!=e2) {
 	    if (is_int_reg(e2)) error(-1);
 	    inc_inst(1);
-	    printf("\t%s\t%s,%s\n",movef(d),
+	    printf("\t%s\t%s, %s\n",movef(d),
 		fregister_name(freg),fregister_name(e2));
 	}
     }
@@ -3909,7 +3925,7 @@
     } else {
 	frn = register_name(freg);
 	inc_inst(1);
-	printf("\tmvfd\t%s,%s\n",frn,frn);
+	printf("\tmvfd\t%s, %s\n",frn,frn);
     }
     return;
 }
@@ -4607,11 +4623,17 @@
 
 /* 64bit int part */
 
+int
+lrexpr_bool(int e1, int reg)
+{       
+    return 0;
+}
+
 void
 lrexpr(int e1, int e2,int l1, int op,int cond)
 {
     int reg,regh,regl,e3h,e3l;
-    int e3,l2,cr0=-1;
+    int e3,l2;
     g_expr(e1);
     emit_lpush();
     g_expr(e2);
@@ -4619,31 +4641,28 @@
     if (!is_longlong_reg(creg)) error(-1);
     reg = lreg;
     l2 = fwdlabel();
-    if (!(op==LOP+EQ||op==LOP+NEQ))
-	cr0 = get_register();
     regh = regv_h(reg); regl = regv_l(reg);
     e3h =  regv_h(e3);  e3l = regv_l(e3);
     switch(op) {
     case LOP+GT: case LOP+GE:
-	pcond(GT,  cr0,e3h,regh,1,cond?l1:l2,COND_BRANCH);
-	pcond(NEQ, cr0,e3h,regh,1,cond?l2:l1,COND_BRANCH);
+	pcond(GT,  e3h,regh,0,1,cond?l1:l2,COND_BRANCH);
+	pcond(NEQ, e3h,regh,0,1,cond?l2:l1,COND_BRANCH);
         break;
     case LOP+UGT: case LOP+UGE:
-	pcond(UGT, cr0,e3h,regh,1,cond?l1:l2,COND_BRANCH);
-	pcond(NEQ, cr0,e3h,regh,1,cond?l2:l1,COND_BRANCH);
+	pcond(UGT, e3h,regh,0,1,cond?l1:l2,COND_BRANCH);
+	pcond(NEQ, e3h,regh,0,1,cond?l2:l1,COND_BRANCH);
         break;
     case LOP+EQ:
-	pcond(EQ, cr0,regh,e3h,0,cond?l2:l1,COND_BRANCH);
+	pcond(EQ, regh,e3h,0,0,cond?l2:l1,COND_BRANCH);
         break;
     case LOP+NEQ:
-	pcond(EQ, cr0,regh,e3h,0,cond?l1:l2,COND_BRANCH);
+	pcond(EQ, regh,e3h,0,0,cond?l1:l2,COND_BRANCH);
         break;
     default:
         error(-1);
     }
-    pcond(op%LOP,cr0,e3l,regl,cond,l1,COND_BRANCH);
+    pcond(op%LOP,e3l,regl,0,cond,l1,COND_BRANCH);
     fwddef(l2);  
-    if (cr0!=-1) free_register(cr0);
     emit_lpop_free(e3);
 }
 
@@ -4976,7 +4995,10 @@
     crn_l = lregister_name_low(creg);
 
     if (car(e)==LCONST) { v = lcadr(e); vh = lcadr(e)>>32; }
-    else if (car(e)==CONST) v = cadr(e);
+    else if (car(e)==CONST) {
+	v = cadr(e);
+	vh = (v<0)?-1:0;
+    }
 
     switch(op) {
     case LMUL: case LUMUL:
@@ -4986,10 +5008,10 @@
 	greg = get_register();
 	grn = register_name(greg);
 	inc_inst(4);
-	printf("\tmov\t%s, %s lsl #%d\n",crn_h,crn_h,v);
-	printf("\tmov\t%s, %s lsr #%d\n",grn,crn_l,32-v);
+	printf("\tmov\t%s, %s, lsl #%d\n",crn_h,crn_h,v);
+	printf("\tmov\t%s, %s, lsr #%d\n",grn,crn_l,32-v);
 	printf("\torr\t%s, %s,%s\n",crn_h,crn_h,grn);
-	printf("\tmov\t%s, %s lsl #%d\n",crn_l,crn_l,v);
+	printf("\tmov\t%s, %s, lsl #%d\n",crn_l,crn_l,v);
 	free_register(greg);
 	return;
     case LDIV:
@@ -4998,10 +5020,10 @@
 	greg = get_register();
 	grn = register_name(greg);
 	inc_inst(4);
-	printf("\tmov\t%s, %s lsr #%d\n",crn_l,crn_l,v);
-	printf("\tmov\t%s, %s lsl #%d\n",grn,crn_h,32-v);
+	printf("\tmov\t%s, %s, lsr #%d\n",crn_l,crn_l,v);
+	printf("\tmov\t%s, %s, lsl #%d\n",grn,crn_h,32-v);
 	printf("\torr\t%s, %s,%s\n",crn_l,crn_l,grn);
-	printf("\tmov\t%s, %s asr #%d\n",crn_h,crn_h,v);
+	printf("\tmov\t%s, %s, asr #%d\n",crn_h,crn_h,v);
 	free_register(greg);
 	return;
     case LUDIV:
@@ -5010,10 +5032,10 @@
 	greg = get_register();
 	grn = register_name(greg);
 	inc_inst(4);
-	printf("\tmov\t%s, %s lsl #%d\n",grn,crn_h,32-v);
-	printf("\tmov\t%s, %s lsr #%d\n",crn_l,crn_l,v);
+	printf("\tmov\t%s, %s, lsl #%d\n",grn,crn_h,32-v);
+	printf("\tmov\t%s, %s, lsr #%d\n",crn_l,crn_l,v);
 	printf("\torr\t%s, %s,%s\n",crn_l,grn,crn_l);
-	printf("\tmov\t%s, %s lsr #%d\n",crn_h,crn_h,v);
+	printf("\tmov\t%s, %s, lsr #%d\n",crn_h,crn_h,v);
 	free_register(greg);
 	return;
     case LADD:
@@ -5078,7 +5100,7 @@
     inc_inst(2);
     if (reg0!=regv_l(lreg))
 	printf("\tmov\t%s, %s\n",crn_l,crn);
-    printf("\tmov\t%s, %s asr #31\n",crn_h,crn_l);
+    printf("\tmov\t%s, %s, asr #31\n",crn_h,crn_l);
 }
 
 void
@@ -5226,12 +5248,12 @@
     if (v>0) {
 	printf("\tadds\t%s, %s, #%d\n", 
 		lregister_name_low(rreg),lregister_name_low(dreg), v);
-	printf("\tadc\t%s %s, #0\n", 
+	printf("\tadc\t%s, %s, #0\n", 
 		lregister_name_high(rreg),lregister_name_high(dreg));
     } else {
 	printf("\tsubs\t%s, %s, #%d\n", 
 		lregister_name_low(rreg),lregister_name_low(dreg), -v);
-	printf("\tsbc\t%s %s, #0\n", 
+	printf("\tsbc\t%s, %s, #0\n", 
 		lregister_name_high(rreg),lregister_name_high(dreg));
     }
 }