changeset 585:a5b902b20300 ia32-no-rname

ia32 reconfigure end (correct?)
author kono
date Wed, 18 Jan 2006 12:26:48 +0900
parents ef6e0e05137f
children 3fb4081164bd
files Changes mc-code-ia32.c mc-inline.c
diffstat 3 files changed, 59 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Wed Jan 18 02:16:53 2006 +0900
+++ b/Changes	Wed Jan 18 12:26:48 2006 +0900
@@ -8508,3 +8508,12 @@
 
 酒飲んでないけど、頭が廻らん。
 
+Wed Jan 18 11:42:18 JST 2006
+
+あと、もう少し。code-stringの後の .text のalignはいらんだろ。
+
+なんか、creg に reg_var を割り振るように直してしまったが、
+だいたい動いているんだけど、かなり怪しい。その方がコード
+は良いんだが.... これは read only creg なんだよね。
+
+
--- a/mc-code-ia32.c	Wed Jan 18 02:16:53 2006 +0900
+++ b/mc-code-ia32.c	Wed Jan 18 12:26:48 2006 +0900
@@ -268,7 +268,7 @@
 #define REG_EDI   6
 #define REG_EBP   7
 #define REG_ESP   8
-#define is_int_reg(reg) (1<=reg&&reg<REG_EBP)
+#define is_int_reg(reg) (REG_EAX<=reg&&reg<REG_EBP)
 #define REG_LCREG     9
 #define REG_L     10
 #define REG_fp REG_EBP
@@ -280,7 +280,7 @@
 #define RET_DREGISTER
 #define RET_LREGISTER   REG_LCREG
 #define RET_REGISTER    REG_EAX
-
+#define CREG_REGISTER   REG_EAX
 
 static char *reg_name[8+1]; 
 static char *reg_name_l[4+1];
@@ -398,13 +398,12 @@
 static int
 use_longlong0(int reg)
 {
-    int i = creg;
+    int i = reg==USING_REG?creg:reg;
     if (ireg) { if (regs[ireg]!=REG_VAR) free_register(ireg); ireg=0; }
     if (!lreg||!regs[lreg]) {
 	code_save_stacks();
-	lreg = (reg==USE_CREG)?REG_LCREG:reg;
-        i = lreg;
     }
+    i = lreg = (reg==USE_CREG)?REG_LCREG:reg;
     if (!regs[i]) regs[i]=USING_REG;
     if (!regs[regv_l(i)]) regs[regv_l(i)]=USING_REG;
     if (!regs[regv_h(i)]) regs[regv_h(i)]=USING_REG;
@@ -505,6 +504,10 @@
 
 void
 code_gexpr(int e){
+    if ((is_int_reg(creg))&&regs[creg]==REG_VAR)
+	creg = ireg = 0;
+    else if ((creg==REG_L)&&regs[creg]==REG_VAR)
+	creg = lreg = 0;
 }
 
 int 
@@ -526,7 +529,7 @@
             return reg;
         }
     }
-    error(-1);
+    error(RGERR);
     return -1;    /* 空いている場所がないなら、それを表す -1 を返す */
 }
 
@@ -623,7 +626,7 @@
     h = REG_ESI;
     l = REG_EDI;
     if (regs[h]==0&&regs[l]==0) {
-	regs[h]=regs[l]=REG_VAR;
+	regs[h]=regs[l]=REG_VAR; regs[REG_L]=REG_VAR;
 	reg_var=2; 
 	return list2(LREGISTER,REG_L);
     }
@@ -1223,19 +1226,19 @@
     case 0:     break;
     case 1: case -1:
 	drn = register_name(dreg = get_data_register(),1);
-        printf("\tmovb %s,%d(%s)\n",drn,offset,frn);
+        printf("\tmovb %d(%s),%s\n",offset,frn,drn);
         printf("\tmovb %s,%d(%s)\n",drn,offset,trn);
 	free_register(dreg);
         break;
     case 2: case -2:
 	drn = register_name(dreg = get_data_register(),2);
-        printf("\tmovw %s,%d(%s)\n",drn,offset,frn);
+        printf("\tmovw %d(%s),%s\n",offset,frn,drn);
         printf("\tmovw %s,%d(%s)\n",drn,offset,trn);
 	free_register(dreg);
         break;
     case 4: case -4:
 	drn = register_name(dreg = get_register(),0);
-        printf("\tmovl %s,%d(%s)\n",drn,offset,frn);
+        printf("\tmovl %d(%s),%s\n",offset,frn,drn);
         printf("\tmovl %s,%d(%s)\n",drn,offset,trn);
 	free_register(dreg);
         break;
@@ -1271,7 +1274,9 @@
 	if (length<0) {
 	    printf("\tmovl $%d,%%ecx\n",-length/4);
 	    printf("\taddl $%d,%%esi\n",-length-4);
-	    printf("\taddl $%d,%%edi\n",-length-4);
+	    printf("\taddl $%d,%%edi\n",-length-4
+		+(to==REG_ESP?4*4:0)
+		);
 	    printf("\tstd\n\trep\n\tmovsl\n");
 	    printf("\tpopl %%ecx\n");
 	    printf("\tpopl %%edi\n");
@@ -1283,6 +1288,8 @@
 	    }
 	} else {
 	    printf("\tmovl $%d,%%ecx\n",length/4);
+	    if (to==REG_ESP)
+		printf("\taddl $%d,%%edi\n",4*4);
 	    printf("\tcld\n\trep\n\tmovsl\n");
 	    printf("\tpopl %%ecx\n");
 	    printf("\tpopl %%edi\n");
@@ -1415,10 +1422,7 @@
 	use_longlong0(USE_CREG);
     } else if (ret_type==VOID) {
     } else {
-	if (!is_int_reg(creg)) {
-	    lreg=0; creg=REG_EAX;
-	}
-	use_register(creg,REG_EAX,0);
+	set_ireg(RET_REGISTER,0);
     }
     stack_depth = stack_depth_save;
     return ret_type;
@@ -1433,12 +1437,13 @@
     g_expr(list3(BAND,list3(ADD,e1,list2(CONST,15)),list2(CONST,~15))); 
     use_int(reg);
     if (stack_depth>0) {
-
+	edx = get_register();
 	crn = register_name(reg,0);
 	drn = register_name(edx,0);
 	printf("\tmovl %%esp,%s\n",drn);
 	printf("\tsubl %s,%%esp\n",crn);
 	printf("\tmovl %%esp,%s\n",crn);
+	free_register(edx);
 	emit_copy(edx,creg,stack_depth,0,1,1);
 	printf("\taddl $%d,%s\n",stack_depth,register_name(creg,0));
 
@@ -1594,24 +1599,6 @@
     emit_pop_free(xreg);
 }
 
-#if 0
-    int xreg;
-    int edx;
-    use_int(reg);
-    xreg = emit_pop(0);       /* pop e3 value */
-    regs[xreg]=1;
-    edx = get_register();
-    printf("\tmovl %s,%s  # assop \n",register_name(reg,0),register_name(edx,0));
-    ld_indexx(byte,0,edx,reg,sign);
-    tosop(op,reg,xreg);
-    printf("\t%s %s,(%s)\n",move(byte),register_name(reg,byte),register_name(edx,0));
-
-    emit_pop_free(xreg);
-    free_register(edx);
-}
-#endif
-
-
 void
 tosop(int op,int reg,int oreg)
 {
@@ -1619,6 +1606,9 @@
     char *orn,*crn;
     // creg = creg op oreg
 
+#if 0
+    int q;
+#endif
     use_int(reg);
 
     if(oreg==-1) {
@@ -1669,13 +1659,20 @@
 	break;
     case DIV:
     case UDIV:
+#if 0
+	q = list3(REG_EAX,0,reg);
+	q = list3(REG_ECX,q,oreg);
+	parallel_rassign(q);
+	orn = "%ecx";
+#else
 	use_register(reg,REG_EAX,1);
 	if (oreg==REG_EAX) oreg=reg;
-	else if (oreg==REG_EDX) {
+	if (oreg==REG_EDX) {
 	    use_register(oreg,REG_ECX,1);
 	    oreg = REG_ECX;
 	}
 	orn = register_name(oreg,0);
+#endif
 	if (op==DIV)
 	    printf("\tcltd\n\tidivl %s\n",orn);
 	else 
@@ -1685,13 +1682,20 @@
 	break;
     case MOD:
     case UMOD:
+#if 0
+	q = list3(REG_EAX,0,reg);
+	q = list3(REG_ECX,q,oreg);
+	parallel_rassign(q);
+	orn = "%ecx";
+#else
 	use_register(reg,REG_EAX,1);
 	if (oreg==REG_EAX) oreg=reg;
-	else if (oreg==REG_EDX) {
+	if (oreg==REG_EDX) {
 	    use_register(oreg,REG_ECX,1);
 	    oreg = REG_ECX;
 	}
 	orn = register_name(oreg,0);
+#endif
 	if (op==MOD)
 	    printf("\tcltd\n\tidivl %s\n",orn);
 	else 
@@ -1700,7 +1704,7 @@
 	set_ireg(reg,1);
 	break;
     }
-    if(ox) free_register(ox);
+    if(ox && ox!=ireg) free_register(ox);
 }
 
 int
@@ -1814,7 +1818,7 @@
 code_cmpdimm(int e, int csreg,int label,int cond)
 {
     /* used in dosiwtch() */
-    use_register(creg,csreg,0);
+    set_ireg(csreg,0);
     printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
     jcond(label,cond);
 }
@@ -2020,6 +2024,12 @@
 	use_longlong(reg);
 	return reg;
     } else {
+        if (reg==USE_CREG) {
+            if (regs[CREG_REGISTER]==0) {
+                set_ireg(CREG_REGISTER,is_int_reg(creg)&&regs[creg]==USING_REG);
+                return CREG_REGISTER;
+            }
+        }
 	use_int(reg);
 	return reg;
     }
@@ -2030,7 +2040,7 @@
     if (type==FLOAT||type==DOUBLE) {
     } else if (type==LONGLONG||type==ULONGLONG) {
     } else {
-	use_register(creg,reg,mode);
+	set_ireg(reg,mode);
     }
 }
 
--- a/mc-inline.c	Wed Jan 18 02:16:53 2006 +0900
+++ b/mc-inline.c	Wed Jan 18 12:26:48 2006 +0900
@@ -412,6 +412,7 @@
 extern void
 st_comment(int e1){
     glineno++;
+    printf("## %d ",glineno);
     gen_comment((char *)caddr(e1));
 }