changeset 272:40266d044d97

MIPS continue...
author kono
date Wed, 19 May 2004 23:44:38 +0900
parents e1a96bdbe527
children 87b9cfc86a10
files Changes mc-code-mips.c mc-parse.c
diffstat 3 files changed, 67 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Wed May 19 21:15:04 2004 +0900
+++ b/Changes	Wed May 19 23:44:38 2004 +0900
@@ -4339,3 +4339,8 @@
 となるのはなんでだろう? 37 が overwrite されているのか。
 でも、37のポジションは正しいんだよな。37自体はレジスタには
 乗ってないし。
+
+Wed May 19 22:15:33 JST 2004
+
+しかし、がんがんバグは取れていくわけだけど、なんか、
+微妙にわけわからないバグが残っているな。
--- a/mc-code-mips.c	Wed May 19 21:15:04 2004 +0900
+++ b/mc-code-mips.c	Wed May 19 23:44:38 2004 +0900
@@ -78,15 +78,15 @@
 
 #define REG_fp   1
 #define REG_sp   30
-#define REG_VAR_BASE 23
+#define REG_VAR_BASE 21
 #define REG_VAR_MIN  16
 #define MIN_TMP_REG 4
 #define MAX_TMP_REG 11
 
 #define PTRC_REG 3
 
-#define FREG_VAR_BASE 31
-#define FREG_VAR_MIN  20
+#define FREG_VAR_BASE 21
+#define FREG_VAR_MIN  16
 #define MIN_TMP_FREG 0
 #define MAX_TMP_FREG 11
 
@@ -115,6 +115,7 @@
 #define regv_l(i)  regv_l0[(i)-LREG_OFFSET]
 
 #define RET_REGISTER 2
+#define REGISTER_OPERAND  4
 #define RET_FREGISTER FREG_OFFSET
 #define FREGISTER_OPERAND  (FREG_OFFSET +12)
 
@@ -2393,7 +2394,7 @@
 	break;
     case DIV: case UDIV: case MOD: case UMOD:
         printf("\t%s $0,%s,%s\n",(op==UDIV||op==UMOD)?"divu":"div",crn,orn);
-        printf("\t%s %s\n",(op==MOD||op==UMOD)?"mflo":"mfhi",crn);
+        printf("\t%s %s\n",(op==MOD||op==UMOD)?"mfhi":"mflo",crn);
         printf("\t.set    noreorder\n");
         printf("\tbeql    %s,$0,1f\n",orn);
         printf("\tbreak   7\n");
@@ -3130,6 +3131,7 @@
 	set_dreg(RET_DREGISTER,1);
 	printf("\tli.d $6,%g\n",0.0);
         extern_conv("dpcmp");
+	cmpreg = 2;
 	return;
     }
     grn =  register_name(greg = get_dregister(d));
@@ -3137,6 +3139,7 @@
     printf("\tmtc1 $0,%s\n",grn);
     printf("\tc.eq.s %s,%s\n",grn,frn);
     free_register(greg);
+    cmpreg = CMP_C1T;
     return;
 }
 
@@ -3280,7 +3283,7 @@
 void
 code_i2d(int reg)
 { 
-    set_ireg(RET_REGISTER,1);
+    set_ireg(REGISTER_OPERAND,1);
     code_save_stacks();
     clear_ptr_cache();
     extern_conv("litodp");
@@ -3304,7 +3307,7 @@
 void
 code_u2d(int reg)
 { 
-    set_ireg(RET_REGISTER,1);
+    set_ireg(REGISTER_OPERAND,1);
     code_save_stacks();
     clear_ptr_cache();
     extern_conv("litodp");
@@ -3380,9 +3383,11 @@
 void
 code_i2f(int reg) {
      int n = new_lvar(SIZE_OF_FLOAT);
-     code_assign_lvar(n,ireg,SIZE_OF_INT);
+     use_int(reg);
+     code_assign_lvar(n,reg,0);
+     reg = USE_CREG;
      use_float(0,reg);
-     code_drlvar(n,reg,0);
+     code_drlvar(n,0,reg);
      printf("\tcvt.s.w %s,%s\n",register_name(freg),register_name(freg));
 }
 
@@ -3392,10 +3397,10 @@
      int reg0,reg1;
      int lb1,lb2;
      char *frn,*r0,*r1;
-     code_assign_lvar(n,ireg,SIZE_OF_INT);
+     code_assign_lvar(n,ireg,0);
      printf("\tbltz    %s,$L_%d\n",r0=register_name(ireg),lb1=fwdlabel());
      use_float(0,reg);
-     code_drlvar(n,reg,0);
+     code_drlvar(n,0,reg);
      r0= register_name(reg0 = get_register());
      r1= register_name(reg1 = get_register());
      frn = fregister_name(reg);
@@ -3520,6 +3525,7 @@
 double_lib(char *opc,int reg,int e1)
 {
     longlong_lib(opc,reg,e1);
+    set_dreg(RET_DREGISTER,0);
 }
 
 void
@@ -3598,17 +3604,11 @@
 	printf("# dassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx));
 	edx = edx0;
       }
-      printf("\tlw %s,0(%s)\n",lregister_name_high(reg),
-	     register_name(edx));
-      printf("\tlw %s,%d(%s)\n",lregister_name_low(reg),
-	     SIZE_OF_INT,register_name(edx));
+      lload(edx,reg,0);
       free_register(edx);
       dtosop(op,reg,xreg);
       edx = emit_pop(0);
-      printf("\tsw %s,0(%s)\n",lregister_name_high(reg),
-	     register_name(edx));
-      printf("\tsw %s,%d(%s)\n",lregister_name_low(reg),
-	     SIZE_OF_INT,register_name(edx));
+      code_lassign(edx,lreg);
       free_register(edx);
       emit_lpop_free(xreg);
       set_double(reg);
@@ -3807,25 +3807,25 @@
 	}
     }
     switch(op) {
-    case FOP+GT: op1=FOP+CMP; break;
-    case DOP+GT: op1=DOP+CMP; break;
-    case FOP+GE: op1=FOP+CMPGE; break;
-    case DOP+GE: op1=DOP+CMPGE; break;
-    case FOP+EQ: op1=FOP+CMPEQ; break;
-    case DOP+EQ: op1=DOP+CMP; break;
+    case FOP+GT:  op1=FOP+CMP;   break;
+    case FOP+GE:  op1=FOP+CMPGE; break;
+    case FOP+EQ:  op1=FOP+CMPEQ; break;
     case FOP+NEQ: op1=FOP+CMPEQ; break;
-    case DOP+NEQ: op1=DOP+CMP; break;
+    case DOP+GT:  op1=DOP+CMP;   break;
+    case DOP+GE:  op1=DOP+CMPGE; break;
+    case DOP+EQ:  op1=DOP+CMP;   break;
+    case DOP+NEQ: op1=DOP+CMP;   break;
     default: error(-1);
     }
     g_expr(list3(op1,e2,e1));
     switch(op) {
-	case DOP+GT:	printf("\tbgez\t$2,$L_%d\n",l1);break;
+	case DOP+GT:	printf("\tblez\t$2,$L_%d\n",l1);break;
+	case DOP+GE:	printf("\tbltz\t$2,$L_%d\n",l1);break;
+	case DOP+EQ:	printf("\tbeq\t$2,$0,$L_%d\n",l1);break;
+	case DOP+NEQ:	printf("\tbne\t$2,$0,$L_%d\n",l1);break;
 	case FOP+GT:	printf("\tbc1t\t$L_%d\n",l1);break;
-	case DOP+GE:	printf("\tbgtz\t$2,$L_%d\n",l1);break;
 	case FOP+GE:	printf("\tbc1t\t$L_%d\n",l1);break;
-	case DOP+EQ:	printf("\tbeq\t$2,$0,$L_%d\n",l1);break;
 	case FOP+EQ:	printf("\tbc1t\t$L_%d\n",l1);break;
-	case DOP+NEQ:	printf("\tbne\t$2,$0,$L_%d\n",l1);break;
         case FOP+NEQ:	printf("\tbc1f\t$L_%d\n",l1);break;
     }
 }
@@ -4177,8 +4177,13 @@
     crn_h = lregister_name_high(creg);
     crn_l = lregister_name_low(creg);
     r = get_ptr_cache((NMTBL*)cadr(e1));
+#if ENDIAN==0
+    printf("\tlw %s,%d(%s)\n",crn_h,SIZE_OF_INT,register_name(r));
+    printf("\tlw %s,0(%s)\n",crn_l,register_name(r));
+#else
     printf("\tlw %s,0(%s)\n",crn_h,register_name(r));
     printf("\tlw %s,%d(%s)\n",crn_l,SIZE_OF_INT,register_name(r));
+#endif
 }
 
 void
@@ -4314,6 +4319,7 @@
     set_lreg(LREGISTER_OPERAND,1);
     set_lreg_operand(oreg,1);
     extern_conv("__divdi3");
+    set_lreg(RET_LREGISTER,0);
 }
 
 static void
@@ -4324,6 +4330,7 @@
     set_lreg(LREGISTER_OPERAND,1);
     set_lreg_operand(oreg,1);
     extern_conv("__udivdi3");
+    set_lreg(RET_LREGISTER,0);
 }
 
 static void
@@ -4334,6 +4341,7 @@
     set_lreg(LREGISTER_OPERAND,1);
     set_lreg_operand(oreg,1);
     extern_conv("__moddi3");
+    set_lreg(RET_LREGISTER,0);
 }
 
 static void
@@ -4344,9 +4352,10 @@
     set_lreg(LREGISTER_OPERAND,1);
     set_lreg_operand(oreg,1);
     extern_conv("__umoddi3");
-}
-
-#define check_lreg(reg) if (reg!=lreg) { lmove(reg,lreg); }
+    set_lreg(RET_LREGISTER,0);
+}
+
+#define check_lreg(reg) if (use && reg!=lreg) { lmove(reg,lreg); }
 
 void
 ltosop(int op,int reg,int oreg)
@@ -4400,9 +4409,9 @@
 	break;
     case LSUB:
         drn = register_name(dx = get_register());
-	printf("\tsltu %s,%s,%s\n",drn,orn_l,crn_l);
-	printf("\tsubu %s,%s,%s\n",crn_l,orn_l,crn_l);
-	printf("\tsubu %s,%s,%s\n",crn_h,orn_h,crn_h);
+	printf("\tsltu %s,%s,%s\n",drn,crn_l,orn_l);
+	printf("\tsubu %s,%s,%s\n",crn_l,crn_l,orn_l);
+	printf("\tsubu %s,%s,%s\n",crn_h,crn_h,orn_h);
 	printf("\tsubu %s,%s,%s\n",crn_h,crn_h,drn);
 	break;
     case LCMP:
@@ -4547,18 +4556,22 @@
 	free_register(greg);
 	return;
     case LSUB:
-        drn = register_name(dx = get_register());
-	printf("\tsltu %s,%s,%d\n",drn,crn_l,-v);
-	printf("\tsubu %s,%s,%d\n",crn_l,crn_l,v);
-	printf("\tsubu %s,%s,1\n",crn_h,crn_h);
-	printf("\taddu %s,%s,%s\n",crn_h,crn_h,drn);
-	break;
+	v = -v;
     case LADD:
-        drn = register_name(dx = get_register());
-	printf("\tsltu %s,%s,%d\n",drn,crn_l,v);
-	printf("\taddu %s,%s,%d\n",crn_l,crn_l,v);
-	printf("\taddu %s,%s,%s\n",crn_h,crn_h,drn);
-	break;
+	if (v<0) {
+	    drn = register_name(dx = get_register());
+	    printf("\tsubu %s,%s,%d\n",crn_l,crn_l,v);
+	    printf("\tsltu %s,%s,%d\n",drn,crn_l,-v);
+	    printf("\tsubu %s,%s,1\n",crn_h,crn_h);
+	    printf("\taddu %s,%s,%s\n",crn_h,crn_h,drn);
+	    break;
+	} else {
+	    drn = register_name(dx = get_register());
+	    printf("\tsltu %s,%s,%d\n",drn,crn_l,v);
+	    printf("\taddu %s,%s,%d\n",crn_l,crn_l,v);
+	    printf("\taddu %s,%s,%s\n",crn_h,crn_h,drn);
+	    break;
+	}
     case LBOR:
 	printf("\tori %s,%s,lo16(%d)\n",crn_l,crn_l,v);
 	break;
@@ -4704,7 +4717,7 @@
 {
     set_lreg(LREGISTER_OPERAND,1);
     extern_conv("__floatdidf");
-    set_freg(RET_FREGISTER,0);
+    set_dreg(RET_DREGISTER,0);
     if (reg!=USE_CREG&&reg!=RET_FREGISTER)
 	use_float(1,reg);
 }
--- a/mc-parse.c	Wed May 19 21:15:04 2004 +0900
+++ b/mc-parse.c	Wed May 19 23:44:38 2004 +0900
@@ -2053,10 +2053,10 @@
     if (car(e2)==DCONST)  return dlist2(FCONST,dcadr(e2));
     if(type==FLOAT) return e2;
     if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2F);
-    if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2D);
+    if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2F);
     if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2F);
     if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2F);
-    if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2D);
+    if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2F);
     error(TYERR); return dlist2(DCONST,1.0);
 #else
     error(TYERR); return list2(CONST,0);