changeset 222:3d214303bae9

*** empty log message ***
author kono
date Mon, 26 Apr 2004 08:58:34 +0900
parents ceae585186d9
children 1ac647873577
files mc-code-powerpc.c mc-codegen.c mc.h test/long.c
diffstat 4 files changed, 83 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-powerpc.c	Mon Apr 26 05:35:33 2004 +0900
+++ b/mc-code-powerpc.c	Mon Apr 26 08:58:34 2004 +0900
@@ -80,8 +80,8 @@
 
 #define RET_REGISTER 3
 #define RET_FREGISTER (1+FREG_OFFSET)
+#define RET_LREGISTER_H 3    /* high word */
 #define RET_LREGISTER_L 4    /* low word */
-#define RET_LREGISTER_H 3    /* high word */
 #define RET_LREGISTER LREG_OFFSET
 
 int MAX_INPUT_REGISTER_VAR = 11-MIN_TMP_REG;
@@ -137,9 +137,9 @@
 int use_int0() { 
     int i = creg;
     if (!is_int_reg(i)) {
+	if (lreg) { free_register(lreg); lreg = 0; }
 	if (!ireg) ireg = get_register();
-	else if (ireg!=i) free_register(i);
-	if (lreg) { free_register(lreg); lreg = 0; }
+	// else if (ireg!=i) free_register(i);
 	i = ireg;
     }
     if (!regs[i]) regs[i]=USING_REG;
@@ -147,6 +147,29 @@
     return i;
 }
 
+#if LONGLONG_CODE
+#define  use_longlong(reg) if (reg==USE_CREG) reg=use_longlong0()
+
+static
+int use_longlong0() {
+    int i = creg;
+    if (!is_longlong_reg(i)) {
+	if (ireg) { free_register(ireg); ireg=0; }
+	if (!lreg) lreg = get_lregister();
+	// else if (lreg!=i) free_register(i);
+	i = lreg;
+    }
+    if (!regv_l(i)) regv_l(i) = get_register();
+    if (!regv_h(i)) regv_h(i) = get_register();
+    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;
+    creg = i;
+    return i;
+}
+#endif
+
+
 #if FLOAT_CODE
 #define  use_float(d,reg) if (reg==USE_CREG) reg=d?use_double0():use_float0()
 static
@@ -177,26 +200,6 @@
 }
 #endif
 
-#if LONGLONG_CODE
-#define  use_longlong(reg) if (reg==USE_CREG) reg=use_longlong0()
-
-static
-int use_longlong0() {
-    int i = creg;
-    if (!is_longlong_reg(i)) {
-	if (!lreg) lreg = get_lregister();
-	else if (lreg!=i) free_register(i);
-	if (ireg) { free_register(ireg); ireg=0; }
-	i = lreg;
-    }
-    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;
-    creg = i;
-    return i;
-}
-#endif
-
 
 #if FLOAT_CODE
 static
@@ -668,6 +671,8 @@
     if (is_longlong_reg(i)) {
 	regs[regv_l(i)]=0;
 	regs[regv_h(i)]=0;
+	regv_l(i)=0;
+	regv_h(i)=0;
     }
 }
 
@@ -697,8 +702,8 @@
 	    if (i<0||i+1>=MAX_INPUT_REGISTER_VAR) return 0;
 	    i = i+MIN_TMP_REG;
 	}
-	regv_l(ll)=i;
-	regv_h(ll)=i+1;
+	regv_h(ll)=i;
+	regv_l(ll)=i+1;
     } else { error(-1); ll=LREG_OFFSET+2; }
     return list3(LREGISTER,ll,(int)n);
 }
@@ -768,7 +773,7 @@
 #if LONGLONG_CODE
     for(i=0;i<REAL_MAX_LREGISTER;i++) { regs[i+LREG_OFFSET]=0; }
     lreg = 0;
-    set_lreg(LREG_LREGISTER,0);
+    // set_lreg(LREG_LREGISTER,0);
 #endif
     for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; }
     for(i=0;i<MAX_FREGISTER;i++) { regs[i+FREG_OFFSET]=0; }
@@ -1478,13 +1483,13 @@
 {
     if (!is_float_reg(reg)) error(-1);
     if (reg!=creg) {
-	if (reg!=freg) {
+	if (freg && reg!=freg) {
 	    free_register(freg);
 	    if (mode) {
 		printf("\tfmr %s,%s\n",fregister_name(reg),fregister_name(freg));
 	    }
 	}
-	if (creg!=ireg) free_register(creg);
+	// if (creg!=ireg) free_register(creg);
 	regs[reg]=USING_REG;
     }
     creg = freg = reg;
@@ -1493,11 +1498,14 @@
 void
 set_lreg(int reg,int mode)
 {
+    if (reg==RET_LREGISTER) {
+	regv_l(reg) = RET_LREGISTER_L;
+	regv_h(reg) = RET_LREGISTER_H;
+    }
     if (!is_longlong_reg(reg)) error(-1);
-    if (regv_l(reg)==0) regv_l(reg)=get_register();
-    if (regv_h(reg)==0) regv_h(reg)=get_register();
     if (reg!=creg) {
-	if (reg!=lreg) {
+	free_register(creg);
+	if (lreg && reg!=lreg) {
 	    free_register(lreg);
 	    if (mode) {
 		printf("\tmr %s,%s\n",
@@ -1507,10 +1515,10 @@
 	    }
 	}
 	regs[reg]=USING_REG;
+	clear_ptr_cache_reg(regv_l(reg));
 	regs[regv_l(reg)]=USING_REG;
+	clear_ptr_cache_reg(regv_h(reg));
 	regs[regv_h(reg)]=USING_REG;
-	if (creg!=ireg) free_register(creg);
-	free_register(creg);
     }
     creg = lreg = reg;
 }
@@ -1649,7 +1657,7 @@
 
     /* now all input register vars are free */
     code_save_stacks();
-    set_lreg(LREG_LREGISTER,0);
+    // set_lreg(LREG_LREGISTER,0);
     set_freg(FREG_FREGISTER,0);
     set_ireg(CREG_REGISTER,0);
 
@@ -1902,12 +1910,19 @@
 code_lrindirect(int e1, int reg, int offset, int us)
 {
     char *crn;
+    int creg0;
+
     g_expr(e1);
     if (!is_int_reg(creg)) error(-1);
-    crn=register_name(creg);
+    crn=register_name(creg0=creg);
     use_longlong(reg);
-    printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset,crn);
-    printf("\tlwz %s,%d(%s)\n",lregister_name_high(reg),offset+size_of_int,crn);
+    if (creg0!=regv_h(reg)) {
+	printf("\tlwz %s,%d(%s)\n",lregister_name_high(reg),offset,crn);
+	printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset+size_of_int,crn);
+    } else {
+	printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),offset+size_of_int,crn);
+	printf("\tlwz %s,%d(%s)\n",lregister_name_high(reg),offset,crn);
+    }
     return us?ULONGLONG:LONGLONG;
 }
 #endif
@@ -2235,7 +2250,7 @@
 void
 code_enter1(int args)
 {
-    set_lreg(LREG_LREGISTER,0);
+    // set_lreg(LREG_LREGISTER,0);
     set_ireg(CREG_REGISTER,0);
     set_freg(FREG_FREGISTER,0);
 }
@@ -3778,12 +3793,12 @@
 {
     int v;
     if (car(e)==LCONST) {
-	if (!(-32766<lcaddr(e)&&lcaddr(e)<32767)) return 0;
+	if (!(-32766<lcadr(e)&&lcadr(e)<32767)) return 0;
 	v = lcaddr(e);
     } else if (car(e)==CONST) {
-	if (!(-32766<caddr(e)&&caddr(e)<32767)) return 0;
+	if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0;
 	v = caddr(e);
-    }
+    } else return 0;
     
     switch(op) {
     case LSHIFT:
@@ -3814,8 +3829,8 @@
     crn_h = lregister_name_high(creg);
     crn_l = lregister_name_low(creg);
 
-    if (car(e)==LCONST) v = lcaddr(e);
-    else if (car(e)==CONST) v = caddr(e);
+    if (car(e)==LCONST) v = lcadr(e);
+    else if (car(e)==CONST) v = cadr(e);
 
     switch(op) {
     case LLSHIFT:
@@ -3847,11 +3862,11 @@
 	free_register(greg);
 	return;
     case LADD:
-	printf("\taddi %s,%s,lo16(%d)\n",crn_l,crn_l,v);
+	printf("\taddic %s,%s,lo16(%d)\n",crn_l,crn_l,v);
 	printf("\taddze %s,%s\n",crn_h,crn_h);
 	break;
     case LSUB:
-	printf("\taddi %s,%s,lo16(-%d)\n",crn_l,crn_l,v);
+	printf("\taddic %s,%s,lo16(-%d)\n",crn_l,crn_l,v);
 	printf("\taddme %s,%s\n",crn_h,crn_h);
 	break;
     case LBOR:
@@ -4029,7 +4044,7 @@
 code_lpreinc(int e1,int e2,int reg)
 {
     char *xrn,*drn_h,*drn_l;
-    int dreg;
+    int dreg,xreg;
     int dir=caddr(e1);
     if (car(e2)==LREGISTER) {
 	use_longlong(reg);
@@ -4044,7 +4059,7 @@
     } 
     g_expr(e2);
     if(!is_int_reg(creg)) error(-1);
-    xrn = register_name(creg);
+    emit_push();
     if (reg==USE_CREG) {
 	dreg=get_lregister(); if (!dreg) error(-1);
 	drn_h = lregister_name_high(dreg);
@@ -4054,12 +4069,15 @@
 	drn_h = lregister_name_high(reg);
 	drn_l = lregister_name_low(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",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);
+    emit_pop_free(xreg);
 }
 
 void
@@ -4067,7 +4085,7 @@
 {
     char *xrn,*drn_h,*drn_l;
     char *nrn_h,*nrn_l;
-    int dreg,nreg;
+    int dreg,nreg,xreg;
     int dir=caddr(e1);
     if (car(e2)==LREGISTER) {
 	use_longlong(reg);
@@ -4080,7 +4098,7 @@
     } 
     g_expr(e2);
     if(!is_int_reg(creg)) error(-1);
-    xrn = register_name(creg);
+    emit_push();
     nreg=get_lregister(); if (!nreg) error(-1);
     nrn_h = lregister_name_high(nreg);
     nrn_l = lregister_name_low(nreg);
@@ -4093,12 +4111,15 @@
 	drn_h = lregister_name_high(reg);
 	drn_l = lregister_name_low(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);
+    emit_pop_free(xreg);
     free_register(nreg);
 }
 
--- a/mc-codegen.c	Mon Apr 26 05:35:33 2004 +0900
+++ b/mc-codegen.c	Mon Apr 26 08:58:34 2004 +0900
@@ -353,8 +353,6 @@
     case FCMP: case FCMPGE:
 	dmachinop(e1,0);
 	return FLOAT;
-    case DCOND:
-    case FCOND:
 #endif
 #if LONGLONG_CODE
     case LMUL: case LUMUL:
@@ -365,6 +363,9 @@
 	lmachinop(e1);
 	return INT;
 #endif
+    case LCOND:
+    case DCOND:
+    case FCOND:
     case COND:        /* a?0:1 should consider non-brach instruction */
         d = (car(e1)==LCOND?LONGLONG:
 		car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT);
--- a/mc.h	Mon Apr 26 05:35:33 2004 +0900
+++ b/mc.h	Mon Apr 26 08:58:34 2004 +0900
@@ -11,7 +11,7 @@
 #endif
 
 #define FLOAT_CODE 1
-#define LONGLONG_CODE 0
+#define LONGLONG_CODE 1
 
 #define SIZE_INT   4
 
--- a/test/long.c	Mon Apr 26 05:35:33 2004 +0900
+++ b/test/long.c	Mon Apr 26 08:58:34 2004 +0900
@@ -64,15 +64,19 @@
      m = i*j-7+k;
      printf("%lld %lld %llu\n",i,k,m);
      printf("%lld %lld %llu\n",i,1231234234233LL,m);
+     printf("0x%llx 0x%llx 0x%llx\n",i,k,m);
+     printf("0x%llx 0x%llx 0x%llx\n",i,1231234234233LL,m);
 
      g0 = -2343423423424234234LL;
      g0++; --g0;
      ++g0; g0--;
      printf("g0=%lld\n",g0);
+     printf("g0=0x%llx\n",g0);
      g1 = -2343423423424234234LL;
      g1++; --g1;
      ++g1; g1--;
      printf("g1=%lld\n",g1);
+     printf("g1=0x%llx\n",g1);
 
      sg0 = 2343423423424234234LL;
      sg0++; --sg0;
@@ -132,6 +136,8 @@
 
      printf("k=%lld\n",k);
      printf("m=%lld\n",m);
+     printf("k=0x%llx\n",k);
+     printf("m=0x%llx\n",m);
      printf("a[33]=%lld\n",a[33]);
      printf("b[33]=%lld\n",b[33]);
      printf("a[33]=%lld\n",++a[33]);
@@ -157,8 +163,10 @@
 
      ii = f(i,j,k,m,a[33]); 
      printf("f()=%lld\n",ii);
+     printf("f()=0x%llx\n",ii);
      ii = g(i,j,k,m,a[33]); 
-     printf("f()=%lld\n",ii);
+     printf("g()=%lld\n",ii);
+     printf("g()=0x%llx\n",ii);
      test3();
   return 0;  
 }