changeset 279:3e8ba7024d25 mips-almost-done

MIPS struct fix (all test except 2 passed.)
author kono
date Sat, 22 May 2004 13:00:03 +0900
parents 5b50813d0c45
children affb054fe920
files Changes mc-code-mips.c test/long.c
diffstat 3 files changed, 54 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sat May 22 00:57:50 2004 +0900
+++ b/Changes	Sat May 22 13:00:03 2004 +0900
@@ -4388,3 +4388,8 @@
 
 slt/beq ってのが、うまく動いてないみたいね。
 
+
+Sat May 22 12:49:55 JST 2004
+
+なんか構造体の先頭はレジスタに置くみたいね... いいけど。
+$5,$6,$7 か。
--- a/mc-code-mips.c	Sat May 22 00:57:50 2004 +0900
+++ b/mc-code-mips.c	Sat May 22 13:00:03 2004 +0900
@@ -1541,39 +1541,37 @@
     free_register(dreg);
 }
 
-static int
-struct_push(int e4,int t,int arg) 
+int
+struct_push(int e4,int t,int arg)
 {
     int length,count;
     int dreg,sreg; char *drn,*crn,*srn;
     g_expr(e4);
     if (!is_int_reg(creg)) error(-1);
-    length=size(t); 
+    length=size(t);
     if(length%SIZE_OF_INT) {
-	length += SIZE_OF_INT - (length%SIZE_OF_INT);
+        length += SIZE_OF_INT - (length%SIZE_OF_INT);
     }
     dreg = get_register(); if (!dreg) error(-1);
     drn = register_name(dreg);
     crn = register_name(creg);
     if (length<MAX_COPY_LEN) {
-	sreg = get_register(); if (!sreg) error(-1);
-	srn = register_name(sreg);
-	code_lvar(cadr(arg),sreg);
-	for(count=0;length<MAX_COPY_LEN;count++,length-=SIZE_OF_INT) {
-	    if (length==0) {
-		free_register(sreg);
-		free_register(dreg);
-		return count;
-	    } else {
-		printf("\tlw %s,%d(%s)\n",drn,length-SIZE_OF_INT,crn);
-		printf("\tsw %s,%d(%s)\n",drn,-SIZE_OF_INT,srn);
-	    }
-	}
+        sreg = get_register(); if (!sreg) error(-1);
+        srn = register_name(sreg);
+        code_lvar(cadr(arg),dreg);
+        for(count=0;count<length;count+=SIZE_OF_INT) {
+            printf("\tlw %s,%d(%s)\n",srn,count,crn);
+            printf("\tsw %s,%d(%s)\n",srn,count,drn);
+        }
+        free_register(sreg);
+        free_register(dreg);
+        return length/SIZE_OF_INT;
+    } else {
+        code_lvar(cadr(arg),dreg);
+        /* downward direction copy */
+        emit_copy(creg,dreg,length,0,0,1);
     }
-    code_lvar(cadr(arg),dreg);
-    /* downward direction copy */
-    emit_copy(creg,dreg,length,0,0,1);
-    if (dreg) free_register(dreg);
+    free_register(dreg);
     return length/SIZE_OF_INT;
 }
 
@@ -1862,7 +1860,7 @@
     switch(car(e2)) {
     case FCONST:
 	value = dcadr(e2);
-        printf("\tli.s %s,%g\n",frn,value);
+        printf("\tli.s %s,%12.12g\n",frn,value);
 	break;
     case FRGVAR:
 	r = get_ptr_cache((NMTBL*)cadr(e2));
@@ -3057,8 +3055,12 @@
 #if LONGLONG_CODE
     } else if(t==LONGLONG||t==ULONGLONG) {       
 	ll = lcadr(e);
+#if (ENDIAN==0)
+	printf("\t.long\t0x%x,0x%x\n",code_l1(ll),code_l2(ll));
+#else
 	printf("\t.long\t0x%x,0x%x\n",code_l2(ll),code_l1(ll));
 #endif
+#endif
 #if FLOAT_CODE
     } else if(t==DOUBLE) {       
 	d = dcadr(e);
@@ -3199,6 +3201,8 @@
 
 #define  set_double(freg) if (regs[freg]) {regs[freg]=USING_DREG;}
 
+static void dconst(int l,int h,double value);
+
 void
 code_cmp_dregister(int e2,int d)
 {
@@ -3209,9 +3213,10 @@
     if (d) {
         code_save_stacks();
 	clear_ptr_cache();
-	set_dreg(RET_DREGISTER,1);
-	printf("\tli.d $6,%10.10g\n",0.0);
+	set_dreg(DREGISTER_OPERAND,0);
+	dconst(DREGISTER_OPERAND_1_L,DREGISTER_OPERAND_1_H,0.0);
         extern_conv("dpcmp");
+	set_dreg(RET_DREGISTER,0);
 	cmpreg = 2;
 	return;
     }
@@ -3306,8 +3311,19 @@
     return *j;
 }
 
+static void
+dconst(int l,int h,double value)
+{
+#if ENDIAN==0
+	printf("\tli %s,0x%x\n",register_name(l),code_d1(value));
+	printf("\tli %s,0x%x\n",register_name(h),code_d2(value));
+#else
+	printf("\tli %s,0x%x\n",register_name(h),code_d1(value));
+	printf("\tli %s,0x%x\n",register_name(l),code_d2(value));
+#endif
+}
+
 void
-
 code_dconst(int e2,int freg,int d)
 { 
     double value = dcadr(e2);
@@ -3315,16 +3331,10 @@
 
     use_float(d,freg);
     if (d) {
-#if ENDIAN==0
-	printf("\tli %s,0x%x\n",lregister_name_low(freg),code_d1(value));
-	printf("\tli %s,0x%x\n",lregister_name_high(freg),code_d2(value));
-#else
-	printf("\tli %s,0x%x\n",lregister_name_high(freg),code_d1(value));
-	printf("\tli %s,0x%x\n",lregister_name_low(freg),code_d2(value));
-#endif
+	dconst(regv_l(freg),regv_h(freg),value);
     } else {
         frn = fregister_name(freg);
-        printf("\tli.s %s,%g\n",frn,value);
+        printf("\tli.s %s,%10.10g\n",frn,value);
     }
 }
 
@@ -3396,7 +3406,7 @@
     extern_conv("litodp");
     code_rlvar(tmp,REGISTER_OPERAND);
     printf("\tbgez\t%s,1f\n",register_name(REGISTER_OPERAND));
-    code_double_lib_c("dpadd",RET_DREGISTER,RET_DREGISTER,4.294967296e9);
+    code_double_lib_c("dpadd",RET_DREGISTER,RET_DREGISTER,4.29496729600000000000e9);
     printf("1:\n");
     set_dreg(RET_DREGISTER,0);
     if (reg!=USE_CREG) {
@@ -3628,7 +3638,7 @@
     code_save_stacks();
     clear_ptr_cache();
     set_dreg_operand(from,1);
-    printf("\tli.d $6,%10.10g\n",value);
+    dconst(DREGISTER_OPERAND_1_L,DREGISTER_OPERAND_1_H,value);
     extern_conv(lib);
     set_dreg(RET_DREGISTER,0);
     if (to!=RET_DREGISTER) {
@@ -4817,7 +4827,7 @@
         printf("\tsubu %s,%s,%d\n",rrn_l,crn_l,-v);
         printf("\tsltu %s,%s,%d\n",drn,rrn_l,v);
         printf("\tsubu %s,%s,1\n",rrn_h,crn_h);
-        printf("\tsubu %s,%s,%s\n",rrn_h,rrn_h,drn);
+        printf("\taddu %s,%s,%s\n",rrn_h,rrn_h,drn);
     } else {
         printf("\taddu %s,%s,%d\n",rrn_l,crn_l,v);
         printf("\tsltu %s,%s,%d\n",drn,rrn_l,v);
--- a/test/long.c	Sat May 22 00:57:50 2004 +0900
+++ b/test/long.c	Sat May 22 13:00:03 2004 +0900
@@ -6,9 +6,10 @@
 unsigned long long b[100];
 unsigned long long c[100];
 
-long long data[] = {2342342342304234LL,2342342340234234LL, -2342342342340234LL};
+long long data[] = {2342342342304234LL,2342342340234234LL, 
+	-234234342340234LL, -2342342342340234LL };
 unsigned long long udata[] = {2342342334234LL,23423423434234LL,
-   -234234234234234LL};
+   -23423423234234LL, -234234234234234LL};
 
 long long f(long long i,unsigned long long j,unsigned long long k,long long m,long long a); 
 unsigned