changeset 240:b59364f5b030

*** empty log message ***
author kono
date Mon, 03 May 2004 21:34:23 +0900
parents 1849e0079f08
children 96b5ee862a41
files mc-code-ia32.c mc-code-powerpc.c mc-codegen.c
diffstat 3 files changed, 72 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-ia32.c	Mon May 03 19:28:35 2004 +0900
+++ b/mc-code-ia32.c	Mon May 03 21:34:23 2004 +0900
@@ -185,12 +185,12 @@
     if (!lreg) {
 	code_save_stacks();
 	// make edx,eax free
-	use_register(creg,REG_EBX,0);
-	use_register(dreg,REG_ECX,0);
+	use_register(creg,REG_EBX,regv[creg]);
+	use_register(dreg,REG_ECX,regv[dreg]);
 	for(i=0;i<reg_var;i++)
 	    use_register(regvar[i],REG_ESI+i,1);
     } 
-    lreg = reg;
+    creg = lreg = reg;
     return lreg;
 }
 
@@ -339,7 +339,7 @@
 	regv[h]=regv[l]=REG_VAR;
 	regv[REAL_MAX_REGISTER]=1;
 	reg_var=2; regvar[0]=h; regvar[1]=l;
-	return list2(LREGISTER,REAL_MAX_REGISTER);
+	return list2(LREGISTER,REG_L);
     }
     return list2(LVAR,new_lvar(size_of_longlong));
 }
@@ -1100,11 +1100,19 @@
 	t=caddr(e3);
 	e4 = car(e3);
 	if(scalar(t)) {
-	    g_expr(e4);
-	    printf("\tpushl %s\n",register_name(creg,0));
+	    if (car(e4)==REGISTER) {
+		printf("\tpushl %s\n",register_name(cadr(e4),0));
+	    } else {
+		g_expr(e4);
+		printf("\tpushl %s\n",register_name(creg,0));
+	    }
 	} else if (t==LONGLONG||t==ULONGLONG) {
-	    g_expr(e4);
-	    printf("\tpushl %%edx\n\tpushl %%eax\n");
+	    if (car(e4)==LREGISTER) {
+		printf("\tpushl %s\n\tpushl %s\n",l_edx(cadr(e4)),l_eax(cadr(e4)));
+	    } else {
+		g_expr(e4);
+		printf("\tpushl %%edx\n\tpushl %%eax\n");
+	    }
 	} else if (t==DOUBLE) {
 	    g_expr(e4);
 	    printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n");
@@ -1248,20 +1256,21 @@
     use_longlong(reg);
     if((reg==REG_L&&rname[creg]==REG_ESI)||(rname[creg]==REG_EAX)) {
 	printf("\tmovl %d(%s),%s\n",offset+size_of_int,crn,l_edx(reg));
-	printf("\tmovl %d(%s),%s\n",offset,crn,l_edx(reg));
+	printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg));
     } else {
 	printf("\tmovl %d(%s),%s\n",offset,crn,l_eax(reg));
-	printf("\tmovl %d(%s),%s\n",offset+size_of_int,crn,l_eax(reg));
+	printf("\tmovl %d(%s),%s\n",offset+size_of_int,crn,l_edx(reg));
     }
 }
 
 int
 code_lrindirect(int e1, int reg, int offset, int us)
 {
+    int reg0;
     g_expr(e1);
-    regv[creg]=1;
+    regv[reg0=creg]=1;
     use_longlong(reg);
-    lload(creg,offset,reg);
+    lload(reg0,offset,reg);
     return LONGLONG;
 }
 #endif
@@ -1422,8 +1431,9 @@
 }
 
 int
-code_const_op_p(int op,int v)
+code_const_op_p(int op,int e)
 {
+    if (car(e)!=CONST) return 0;
     if (op==DIV||op==UDIV||op==MOD||op==UMOD) return 0;
     else return 1;
 }
@@ -1434,6 +1444,7 @@
     char *crn;
     use_int(reg);
     crn = register_name(reg,0);
+    orn = cadr(orn);
 
     switch(op) {
     case LSHIFT:
@@ -2301,16 +2312,15 @@
     printf("\tj%s\t_%d\n",s,l1);
 }
 
-void lrexpr(int e1, int e2,int l1, int op,int cond)
+void
+lrexpr(int e1, int e2,int l1, int op,int cond)
 {
     int e3;
     g_expr(e1);
     emit_lpush();
     g_expr(e2);
-    e3 = emit_lpop();
-    // reg = use_longlong0(USE_CREG);
-
-    printf("\tsubl %%edx,4(%%esp)\n");
+    ltosop(LSUB,USE_CREG,(e3==emit_lpop()));
+    printf("\tpopl %%eax\n\tpopl %%edx\n");  // emit_pop_free
     switch(op) {
     case LOP+GT:
         pcond(code_gt(cond),l1); break;
@@ -2331,28 +2341,6 @@
     default:
         error(-1);
     }
-    printf("\tsubl %%eax,(%%esp)\n");
-    switch(op) {
-    case LOP+GT:
-        pcond(code_gt(cond),l1); break;
-    case LOP+GE:
-        pcond(code_ge(cond),l1); break;
-    case LOP+EQ:
-        pcond(code_eq(cond),l1); break;
-    case LOP+NEQ:
-        pcond(code_eq(!cond),l1); break;
-    case LOP+LT:
-        pcond(code_ge(!cond),l1); break;
-    case LOP+LE:
-        pcond(code_gt(!cond),l1); break;
-    case LOP+UGT:
-        pcond(code_ugt(cond),l1); break;
-    case LOP+UGE:
-        pcond(code_uge(cond),l1); break;
-    default:
-        error(-1);
-    }
-    emit_lpop_free(e3);
 }
 
 int emit_lpop()
@@ -2364,7 +2352,7 @@
 {
     use_longlong(reg);
     if (reg!=REG_L) {
-	printf("\tmovl %%esi,%s\n",l_edx(reg));
+	printf("\tmovl %%esi,%s\n",l_eax(reg));
 	printf("\tmovl %%edi,%s\n",l_edx(reg));
     }
 }
@@ -2470,7 +2458,8 @@
 
 #define check_lreg() if (reg==REG_L) code_lassign_lregister(REG_LCREG,reg)
 
-void ltosop(int op,int reg,int e2)
+void
+ltosop(int op,int reg,int e2)
 {
     char *opl,*oph,*call;
     int lb;
@@ -2497,7 +2486,7 @@
     case LRSHIFT:
 	printf("\tmovl %%ecx,4(%%esp)\n");
 	printf("\tpopl %%ecx\n");
-        printf("\tshrdl %%eax,%%edx\n");
+        printf("\tshrdl %%edx,%%eax\n");
         printf("\tsarl %%cl,%%eax\n");
         printf("\ttestb $32,%%cl\n");
 	printf("\tje\t_%d\n",(lb=fwdlabel()));
@@ -2510,7 +2499,7 @@
     case LURSHIFT:
 	printf("\tmovl %%ecx,4(%%esp)\n");
 	printf("\tpopl %%ecx\n");
-        printf("\tshrdl %%eax,%%edx\n");
+        printf("\tshrdl %%edx,%%eax\n");
         printf("\tshrl %%cl,%%eax\n");
         printf("\ttestb $32,%%cl\n");
 	printf("\tje\t_%d\n",(lb=fwdlabel()));
@@ -2555,7 +2544,6 @@
     if (opl) {
 	printf("\t%s (%%esp),%%eax\n\t%s 4(%%esp),%%edx\n",opl,oph);
 	check_lreg();
-	emit_lpop_free(e2);
     } else if (call) {
 	printf("\tpushl %%edx\n");
 	printf("\tpushl %%eax\n");
@@ -2568,7 +2556,11 @@
 }
 
 int code_lconst_op_p(int op,int e) {
-    long long l = lcadr(e);
+    long long l;
+    if (car(e)==CONST) l = cadr(e);
+    else if (car(e)==LCONST) l = lcadr(e);
+    else return 0;
+
     switch(op) {
     case LLSHIFT:
     case LULSHIFT:
@@ -2588,8 +2580,16 @@
 
 void loprtc(int op,int reg,int e) {
     char *opl,*oph;
-    int vl = code_l1(lcadr(e));
-    int vh = code_l2(lcadr(e));
+    int vl;
+    int vh;
+    long long l;
+
+    if (car(e)==CONST) l = cadr(e);
+    else if (car(e)==LCONST) l = lcadr(e);
+    else error(-1);
+
+    vl = code_l1(l);
+    vh = code_l2(l);
 
     use_longlong(reg);
     opl = 0;
@@ -2636,10 +2636,16 @@
 
 void code_i2ll(int reg)
 {
-    if (virtual(REG_EAX)!=creg)
-	printf("\tmovl %s,%%eax\n",register_name(creg,0));
-    use_longlong(reg);
+    int reg0 = USE_CREG;
+    use_register(creg,REG_EAX,1);
+    regv[creg]=0;
+    use_longlong(reg0);
     printf("\tcltd\n");
+    if (reg==REG_L) {
+	code_lassign_lregister(reg0,reg);
+	reg0 = reg;
+    }
+    lreg = creg = reg0;
 }
 
 void code_i2ull(int reg)
@@ -2649,10 +2655,16 @@
 
 void code_u2ll(int reg)
 {
-    if (virtual(REG_EAX)!=creg)
-	printf("\tmovl %s,%%eax\n",register_name(creg,0));
-    use_longlong(reg);
+    int reg0 = USE_CREG;
+    use_register(creg,REG_EAX,1);
+    regv[creg]=0;
+    use_longlong(reg0);
     printf("\txorl %%edx,%%edx\n");
+    if (reg==REG_L) {
+	code_lassign_lregister(reg0,reg);
+	reg0 = reg;
+    }
+    lreg = creg = reg0;
 }
 
 void code_u2ull(int reg)
--- a/mc-code-powerpc.c	Mon May 03 19:28:35 2004 +0900
+++ b/mc-code-powerpc.c	Mon May 03 21:34:23 2004 +0900
@@ -2165,7 +2165,9 @@
 int 
 code_const_op_p(int op,int v)
 {
+    if (car(v)!=CONST) return 0;
     if (op==BAND||op==DIV||op==UDIV||op==MOD||op==UMOD) return 0;
+    v = cadr(v);
     return (-32766<v&&v<32767);
 }
 
@@ -2175,6 +2177,7 @@
     char *crn;
     use_int(creg);
     crn = register_name(creg);
+    v = cadr(v);
     
     switch(op) {
     case LSHIFT:
--- a/mc-codegen.c	Mon May 03 19:28:35 2004 +0900
+++ b/mc-codegen.c	Mon May 03 21:34:23 2004 +0900
@@ -1068,14 +1068,14 @@
 void
 machinop(int e1)
 {
-    int e2,e3,op,v;
+    int e2,e3,op;
 
     e2 = cadr(e1);
     op = car(e1);
     e3 = caddr(e1);
-    if (car(e3)==CONST && code_const_op_p(op,v=cadr(e3))) {
+    if (code_const_op_p(op,e3)) {
 	g_expr(e2);
-	oprtc(op,USE_CREG,v);
+	oprtc(op,USE_CREG,e3);
 	return;
     }
     g_expr(e3);