changeset 594:f49c825920c4 fix-ltosop

tosop optimize buf fix
author kono
date Sat, 21 Jan 2006 15:00:29 +0900
parents c139d4d9307c
children cfd1eba00ce6
files mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c stdio.h
diffstat 7 files changed, 76 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-arm.c	Fri Jan 20 18:48:45 2006 +0900
+++ b/mc-code-arm.c	Sat Jan 21 15:00:29 2006 +0900
@@ -2973,6 +2973,11 @@
     inc_inst(1);
 }
 
+int
+tosop_operand_safe_p(int op)
+{
+    return 1;
+}
 
 void
 tosop(int op,int creg,int oreg)
@@ -4456,7 +4461,6 @@
     }
 }
 
-
 void
 dtosop_d(int op,int reg,int e1)
 { 
--- a/mc-code-ia32.c	Fri Jan 20 18:48:45 2006 +0900
+++ b/mc-code-ia32.c	Sat Jan 21 15:00:29 2006 +0900
@@ -1579,6 +1579,18 @@
     emit_pop_free(xreg);
 }
 
+int
+tosop_operand_safe_p(op)
+{
+    switch(op) {
+    case ADD: case SUB: case CMP:
+    case BAND: case EOR: case BOR:
+    case MUL: case UMUL:
+	return 1;
+    default: return 0;
+    }
+}
+
 void
 tosop(int op,int reg,int oreg)
 {
@@ -1619,9 +1631,12 @@
     case ADD:
 	printf("\taddl %s,%s\n",orn,crn);
 	break;
-    case SUB: case CMP:
+    case SUB: 
 	printf("\tsubl %s,%s\n",orn,crn);
 	break;
+    case CMP:
+	printf("\tcmpl %s,%s\n",orn,crn);
+	break;
     case BAND: 
 	printf("\tandl %s,%s\n",orn,crn);
 	break;
--- a/mc-code-mips.c	Fri Jan 20 18:48:45 2006 +0900
+++ b/mc-code-mips.c	Sat Jan 21 15:00:29 2006 +0900
@@ -2498,7 +2498,7 @@
 
     use_int(creg);
     xreg = emit_pop(0);       /* pop e3 value */
-#if 1
+
     set_ireg(edx,0);
     ld_indexx(byte,0,creg,ireg,sign);
     tosop(op,ireg,xreg);
@@ -2507,18 +2507,18 @@
     printf("\t%s %s,0(%s)\n",cstore(byte),crn,drn);
     free_register(edx);
     emit_pop_free(xreg);
-#else
-    printf("## assop\n\tmove %s,%s\n",register_name(edx),register_name(creg));
-    ld_indexx(byte,0,edx,creg,sign);
-    tosop(op,creg,xreg);
-    crn = register_name(creg);
-    drn = register_name(edx);
-    printf("\t%s %s,0(%s)\n",cstore(byte),crn,drn);
-    free_register(edx);
-    emit_pop_free(xreg);
-#endif
-}
-
+}
+
+int
+tosop_operand_safe_p(int op)
+{
+    switch(op) {
+    case CMPGE: case CMP: case UCMPGE:
+	return CMP;  // creg is not safe
+    default:
+    return 1;
+    }
+}
 
 void
 tosop(int op,int creg,int oreg)
@@ -3968,7 +3968,6 @@
     }
 }
 
-
 void
 dtosop(int op,int reg,int e1)
 { 
--- a/mc-code-powerpc.c	Fri Jan 20 18:48:45 2006 +0900
+++ b/mc-code-powerpc.c	Sat Jan 21 15:00:29 2006 +0900
@@ -2454,48 +2454,12 @@
     printf("\t%s %s,0(%s)\n",cstore(byte),
 	register_name(ireg),register_name(xreg));
     emit_pop_free(xreg);
-
-#if 0
-    char *xrn,*crn,*drn;
-    int xreg;
-    int edx = get_register(); if(!edx) error(-1);
-    //  (*creg) op = pop()
-
-    use_int(creg);
-    xrn = register_name(xreg = emit_pop(0));       /* pop e3 value */
-#if 1
-    set_ireg(edx,0);
-    ld_indexx(byte,0,creg,ireg,sign);
-    use_reg(creg); // to clear ptr cache
-    tosop(op,ireg,xreg);
-    crn = register_name(ireg);
-    drn = register_name(creg);
-    if (byte==1) {
-	printf("\tstb %s,0(%s)\n",crn,drn);
-    } else if (byte==SIZE_OF_SHORT) {
-	printf("\tsth %s,0(%s)\n",crn,drn);
-    } else {
-	printf("\tstw %s,0(%s)\n",crn,drn);
-    }
-    free_register(creg);
-    emit_pop_free(xreg);
-#else
-    printf("## assop\n\tmr %s,%s\n",register_name(edx),register_name(creg));
-    ld_indexx(byte,0,edx,creg,sign);
-    tosop(op,creg,xreg);
-    crn = register_name(creg);
-    drn = register_name(edx);
-    if (byte==1) {
-	printf("\tstb %s,0(%s)\n",crn,drn);
-    } else if (byte==SIZE_OF_SHORT) {
-	printf("\tsth %s,0(%s)\n",crn,drn);
-    } else {
-	printf("\tstw %s,0(%s)\n",crn,drn);
-    }
-    free_register(edx);
-    emit_pop_free(xreg);
-#endif
-#endif
+}
+
+int
+tosop_operand_safe_p(int op)
+{
+    return 1;
 }
 
 void
--- a/mc-code.h	Fri Jan 20 18:48:45 2006 +0900
+++ b/mc-code.h	Sat Jan 21 15:00:29 2006 +0900
@@ -119,6 +119,7 @@
 extern void code_register_assop(int e2,int reg,int op,int byte);
 extern void code_assop(int op,int reg,int byte,int sign);
 extern void tosop(int op,int reg,int oreg);
+extern int tosop_operand_safe_p(int);
 extern void code_opening(char *filename);
 extern void code_closing();
 extern int rexpr(int e1, int l1, int cond,int t);
--- a/mc-codegen.c	Fri Jan 20 18:48:45 2006 +0900
+++ b/mc-codegen.c	Sat Jan 21 15:00:29 2006 +0900
@@ -1554,13 +1554,19 @@
 	return;
     }
     if ((op==CMP||op==UCMP) && car(e3)==REGISTER && car(e2)==REGISTER) {
-	tosop(op,cadr(e2),cadr(e3));
-	return;
+	if (tosop_operand_safe_p(op)==1) {
+	    // both operands are safe
+	    tosop(op,cadr(e2),cadr(e3));
+	    return;
+	}
     }
     if (car(e3)==REGISTER) {
-	g_expr(e2);
-	tosop(op,USE_CREG,cadr(e3));
-	return;
+	if (tosop_operand_safe_p(op)) {
+	    // operand are safe
+	    g_expr(e2);
+	    tosop(op,USE_CREG,cadr(e3));
+	    return;
+	}
     }
     g_expr(e3);
     emit_push();
@@ -1583,15 +1589,19 @@
     case DCMPGE: case DCMPEQ: case DCMPNEQ: case DCMP:
     case FCMPGE: case FCMPEQ: case FCMPNEQ: case FCMP:
 	if ((car(e3)==DREGISTER||car(e3)==FREGISTER) && 
-	   ((car(e2)==DREGISTER||car(e2)==FREGISTER))) {
-	    dtosop(op,cadr(e2),cadr(e3));
-	    return;
+	   ((car(e2)==DREGISTER||car(e2)==FREGISTER))) { 
+	    if (tosop_operand_safe_p(op)==1) {
+		dtosop(op,cadr(e2),cadr(e3));
+		return;
+	    }
 	}
     }
     if (car(e3)==DREGISTER||car(e3)==FREGISTER) {
-	g_expr(e2);
-	dtosop(op,USE_CREG,cadr(e3));
-	return;
+	if (tosop_operand_safe_p(op)) {
+	    g_expr(e2);
+	    dtosop(op,USE_CREG,cadr(e3));
+	    return;
+	}
     }
     g_expr(e3);
     emit_dpush(d);
@@ -1616,8 +1626,7 @@
 	loprtc(op,USE_CREG,e3);
 	return;
     }
-    if (car(e3)==LREGISTER) {
-	// ltosop should not destory its operand (register e3)
+    if (car(e3)==LREGISTER && tosop_operand_safe_p(op)) {
 	g_expr(e2);
 	ltosop(op,USE_CREG,cadr(e3));
 	return;
--- a/stdio.h	Fri Jan 20 18:48:45 2006 +0900
+++ b/stdio.h	Sat Jan 21 15:00:29 2006 +0900
@@ -1,14 +1,26 @@
-#ifndef __micro_c__
+#ifndef __micro_c___
+#ifndef __ARM_ARCH_4__
 #include "/usr/include/stdio.h"
+#else /* __ARM_ARCH_4__ */
+// #include "/usr/include/stdio.h"
+#include "/home/zaurus/develop/include/stdio.h"
+#endif /* __ARM_ARCH_4__ */
 long long strtoll(const char *, char **, int);
+#ifndef __ARM_ARCH_4__
 void * malloc(size_t size);
 void * realloc(void *ptr, size_t size);
+#else /* __ARM_ARCH_4__ */
+char *malloc(int);
+void * realloc(void *ptr, int size);
+#endif /* __ARM_ARCH_4__ */
 #else
 
 // typedef int size_t;
 #define size_t int
 
+#ifndef __ARM_ARCH_4__
 void * malloc(size_t size);
+#endif /* ! __ARM_ARCH_4__ */
 long long strtoll(const char *, char **, int);
 void * realloc(void *ptr, size_t size);