changeset 408:b4375f895fd5

ARM struct copy, alloca fix
author kono
date Mon, 18 Oct 2004 23:44:38 +0900
parents dafb9110d70b
children b72682778d75
files .gdbinit Changes mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c
diffstat 6 files changed, 74 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Mon Oct 18 08:33:00 2004 +0900
+++ b/.gdbinit	Mon Oct 18 23:44:38 2004 +0900
@@ -1,6 +1,6 @@
 tb main
 # run  -s test/arg.c
-run  -s mc-parse.c
+# run  -s mc-parse.c
 # run  -s mc-codegen.c
 # run  -s nkf203/nkf.c
 # run  -s -ob01.s mc-switch.c
@@ -8,6 +8,7 @@
 # run  -s test/const.c
 # run  -s test/basic.c
 # run -s test/code-gen-all.c
+run -s test/tmp7.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	Mon Oct 18 08:33:00 2004 +0900
+++ b/Changes	Mon Oct 18 23:44:38 2004 +0900
@@ -6113,4 +6113,10 @@
 
 self compile が通らない。他のテストを優先するべきか。
 
-
+Mon Oct 18 20:25:16 JST 2004
+
+emit_copy の offset の扱いが一貫してないらしい。
+あと、 powerpc でr3,r4,r5 を使った状態でmemmoveが呼ばれるみたい。
+
+うーん、やっぱり構造体をレジスタに割り振るのってかなりめんどう
+なのね。特にネストする関数では...
--- a/mc-code-arm.c	Mon Oct 18 08:33:00 2004 +0900
+++ b/mc-code-arm.c	Mon Oct 18 23:44:38 2004 +0900
@@ -16,6 +16,7 @@
     "/Developer/Zaurus-X-gcc/opt/Embedix/tools/arm-linux/include",
     "/Developer/Zaurus-X-gcc/opt/Embedix/tools/arm-linux/include/linux",
     "/home/zaurus/develop/include",
+    "/home/zaurus/develop/include/linux",
     "/usr/include",
     0};
 
@@ -497,6 +498,7 @@
 #define __THORW\n\
 #define __attribute__(a)\n\
 #define __inline__\n\
+#define size_t int\n\
 #define wchar_t int\n\
 ";
 
@@ -1925,8 +1927,7 @@
 	}
 	clear_ptr_cache();
 	code_save_stacks();
-	code_register(from,2);
-	code_register(to,1);
+	parallel_rassign(list3(1,list3(2,0,from),to));
 	code_const(length,3);
         /* overrap must be allowed */
 	inc_inst(1);
@@ -1955,8 +1956,9 @@
 struct_push(int e4,int t,int arg)
 {
     int length,count;
-    int dreg,sreg; char *drn,*crn,*srn;
+    int dreg = -1,sreg; char *drn,*crn,*srn;
     int arg_disp = cadr(arg);
+    int on_register,arg_reg;
     g_expr(e4);
     if (!is_int_reg(creg)) error(-1);
     length=size(t);
@@ -1964,35 +1966,53 @@
         length += SIZE_OF_INT - (length%SIZE_OF_INT);
     }
     crn = register_name(creg);
-    count = 0;
-    dreg = 1-CALLER_ARG(arg_disp-ARG_LVAR_OFFSET)/SIZE_OF_INT;
+    on_register = 0;
+    // arg_reg = 1-CALLER_ARG(arg_disp-ARG_LVAR_OFFSET)/SIZE_OF_INT;
+    arg_reg = (arg_disp-ARG_LVAR_OFFSET)/SIZE_OF_INT + 1;
     while (arg_disp>=ARG_LVAR_OFFSET && CALLER_ARG(arg_disp-ARG_LVAR_OFFSET)<0) {
 	/* some part will be in registers */
-	printf("\tldr\t%s, [%s, #%d]\n", register_name(dreg), crn,count);
-	count += SIZE_OF_INT; length-=SIZE_OF_INT; arg_disp+= SIZE_OF_INT;
-	dreg ++;
-    }
-    if (!(length>0)) return length/SIZE_OF_INT;
-    dreg = get_register(); if (!dreg) error(-1);
-    drn = register_name(dreg);
-    if (length<MAX_COPY_LEN) {
-        sreg = get_register(); if (!sreg) error(-1);
-        srn = register_name(sreg);
-        code_lvar(arg_disp,dreg);
-        for(count=0;count<length;count+=SIZE_OF_INT) {
-	    inc_inst(2);
-            printf("\tldr\t%s, [%s, #%d]\n",srn,crn,count);
-            printf("\tstr\t%s, [%s, #%d]\n",srn,drn,count);
-        }
-        free_register(sreg);
-        free_register(dreg);
-        return length/SIZE_OF_INT;
-    } else {
-        code_lvar(arg_disp,dreg);
-        /* downward direction copy */
-        emit_copy(creg,dreg,length,0,0,1);
-    }
-    free_register(dreg);
+	on_register ++; 
+	length-=SIZE_OF_INT; arg_disp+= SIZE_OF_INT;
+    }
+    if (length>0) {
+	dreg = get_register(); if (!dreg) error(-1);
+	drn = register_name(dreg);
+	if (length<MAX_COPY_LEN) {
+	    sreg = get_register(); if (!sreg) error(-1);
+	    srn = register_name(sreg);
+	    code_lvar(arg_disp,dreg);
+	    for(count=0;count<length;count+=SIZE_OF_INT) {
+		inc_inst(2);
+		printf("\tldr\t%s, [%s, #%d]\n",srn,crn,count+on_register*SIZE_OF_INT);
+		printf("\tstr\t%s, [%s, #%d]\n",srn,drn,count);
+	    }
+	    free_register(sreg);
+	    if (on_register) {
+		if (creg<=MAX_INPUT_REGISTER_VAR) {
+		    code_register(creg,REG_ip);
+		    crn = register_name(REG_ip);
+		}
+	    }
+	} else {
+	    code_lvar(arg_disp,dreg);
+	    /* downward direction copy */
+	    if (on_register) {
+		sreg = new_lvar(SIZE_OF_INT);
+		code_assign_lvar(sreg,creg,0);
+		code_add(creg,on_register*SIZE_OF_INT,creg);
+		emit_copy(creg,dreg,length,0,0,1);
+		code_rlvar(sreg,REG_ip);
+		crn = register_name(REG_ip);
+		free_lvar(sreg);
+	    } else {
+		emit_copy(creg,dreg,length,0,0,1);
+	    }
+	}
+	if (dreg!=-1) free_register(dreg);
+    }
+    for (count=0,arg_reg; on_register-->0; arg_reg++,count+=SIZE_OF_INT) {
+	printf("\tldr\t%s, [%s, #%d]\n", register_name(arg_reg), crn,count);
+    }
     return length/SIZE_OF_INT;
 }
 
@@ -2076,6 +2096,7 @@
 	if (is_float_reg(reg)) {
 	    set_freg(reg,mode);
 	}
+	regs[reg]=USING_REG;
 	return;
     }
     if (reg==RET_DREGISTER) {
@@ -2181,6 +2202,7 @@
 	case FUNCTION: case CONV: case RSTRUCT: case STASS: case ALLOCA:
 	case DIV : case UDIV : case MOD : case UMOD :
 	case LDIV: case LUDIV: case LMOD: case LUMOD:
+	case LMUL: case LUMUL:
 	case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
 	case DDIV: case DADD: case DSUB: case DMUL: case DMINUS:
 	case DPOSTINC : case DPREINC : case DASSOP :
@@ -2412,7 +2434,6 @@
 	inc_inst(3);
 	printf("\tmov\tlr, pc\n");
 	printf("\tmov\tpc, %s\n",register_name(cadr(jmp)));
-	printf("\tldmea\tfp, {fp, sp, pc}\n");
     }
 }
 
@@ -2495,6 +2516,7 @@
 		    car(e3)=arg;
 		    reg_arg_list = list2(arg,reg_arg_list);
 		    if (car(arg)==REGISTER) use_input_reg(cadr(arg),1);
+		    else car(e3) = rvalue_t(arg,INT);
 		}
 	    }
 	    stargs = list4(e3,stargs,nargs,reg_arg);
@@ -2636,7 +2658,7 @@
     crn = register_name(reg);
     grn = register_name(g);
     inc_inst(2);
-    printf("\trsb\tsp, %s, sp, %s\n",crn, grn);
+    printf("\trsb\tsp, %s, sp\n",crn, grn);
     printf("\tmov\t%s, sp\n",crn);
     free_register(g);
 }
@@ -2940,7 +2962,7 @@
 	drn = register_name(dx = get_register());
 	printf("\tmul\t%s, %s, %s\n",drn,crn,orn);
 	if (creg0==USE_CREG) {
-	    set_ireg(dx,0);
+	    set_ireg(dx,0); dx = -1;
 	} else {
 	    printf("\tmov\t%s, %s\n",crn,drn);
 	}
@@ -4062,7 +4084,7 @@
 	printf("\tcmp\t%s, #0\n",crn);
         printf("\tbge\t1f\n");
 	freg1 = get_dregister(1);
-	code_dconst(dlist2(DCONST,2.147483648e9),freg1,1);
+	code_dconst(dlist2(DCONST,4.29496729600000000000e9),freg1,1);
 	frn = register_name(creg);
 	lrn = register_name(freg1);
 	printf("\tadfd\t%s, %s, %s\n",frn,frn,lrn);
--- a/mc-code-ia32.c	Mon Oct 18 08:33:00 2004 +0900
+++ b/mc-code-ia32.c	Mon Oct 18 23:44:38 2004 +0900
@@ -1134,6 +1134,8 @@
 	} else {
 	    printf("\tmovl $%d,%%ecx\n",length/4);
 	    fix = (length/4)*4;
+	    //if (offset)
+	    //	printf("\taddl $%d,%%edi\n",offset);
 	    printf("\tcld\n\trep\n\tmovsl\n");
 	    if(length%4) {
 		emit_copy(from,to,length,offset+length/SIZE_OF_INT,0,det);
--- a/mc-code-mips.c	Mon Oct 18 08:33:00 2004 +0900
+++ b/mc-code-mips.c	Mon Oct 18 23:44:38 2004 +0900
@@ -1583,6 +1583,9 @@
 	code_save_stacks();
 	printf("\tli $6,%d\n",length);
 	printf("\tmove $5,%s\n",frn);
+	//if (offset) 
+	//    printf("\taddu $4,%s,%d\n",trn,offset);
+	//else
 	printf("\tmove $4,%s\n",trn);
         /* overrap must be allowed */
 	printf("\tjal %s\n",memmove);
@@ -2139,6 +2142,7 @@
 		    car(e3)=arg;
 		    reg_arg_list = list2(arg,reg_arg_list);
 		    if (car(arg)==REGISTER) use_input_reg(cadr(arg),1);
+                    else car(e3) = rvalue_t(arg,INT);
 		}
 	    }
 	    stargs = list4(e3,stargs,nargs,reg_arg);
--- a/mc-code-powerpc.c	Mon Oct 18 08:33:00 2004 +0900
+++ b/mc-code-powerpc.c	Mon Oct 18 23:44:38 2004 +0900
@@ -1588,6 +1588,8 @@
 	printf("\tli r5,%d\n",length);
 	printf("\tmr r4,%s\n",frn);
 	printf("\tmr r3,%s\n",trn);
+	//if (offset)
+	//    code_add(3,offset,3);
         /* overrap must be allowed */
 	printf("\tbl L_%s$stub\n",memmove);
 	extern_define(memmove,0,FUNCTION,1);
@@ -2046,6 +2048,7 @@
 		    car(e3)=arg;
 		    reg_arg_list = list2(arg,reg_arg_list);
 		    if (car(arg)==REGISTER) use_input_reg(cadr(arg),1);
+                    else car(e3) = rvalue_t(arg,INT);
 		}
 	    }
 	    stargs = list4(e3,stargs,nargs,reg_arg);