changeset 382:832e1f6bba82

ARM wrote all code. Check compile error.
author kono
date Mon, 19 Jul 2004 16:30:11 +0900
parents 5a9a27fadb9b
children 9a3d897d58fd
files mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-switch.c
diffstat 6 files changed, 99 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-arm.c	Mon Jul 19 15:16:26 2004 +0900
+++ b/mc-code-arm.c	Mon Jul 19 16:30:11 2004 +0900
@@ -4876,26 +4876,24 @@
 int
 code_lconst_op_p(int op,int e)
 {
-    int v;
+    long long v;
     if (car(e)==LCONST) {
-	if (!(-32766<lcadr(e)&&lcadr(e)<32767)) return 0;
 	v = lcadr(e);
     } else if (car(e)==CONST) {
-	if (!(-32766<cadr(e)&&cadr(e)<32767)) return 0;
 	v = cadr(e);
     } else return 0;
     
     switch(op) {
-    case LLSHIFT:
-    case LULSHIFT:
-    case LRSHIFT:
-    case LURSHIFT:
-	return  (0<v&&v<31);
+    case LMUL: case LUMUL: case LDIV: case LUDIV:
+	return ilog(v);
+    case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
+	return 0<v&&v<=32;
     case LADD:
     case LSUB:
-	return 1;
     case LBOR:
-	return  (v>0);
+    case LEOR: case LBOR: case LBAND:
+	return is_stage1_const(v,0);
+	    && is_stage1_const(v>>32,0);
     default:
 	return 0;
     }
@@ -4908,61 +4906,70 @@
     char *crn_l;
     char *grn,*drn;
     int v;
+    int vh;
     int greg,dx=-1;
 
     use_longlong(creg);
     crn_h = lregister_name_high(creg);
     crn_l = lregister_name_low(creg);
 
-    if (car(e)==LCONST) v = lcadr(e);
+    if (car(e)==LCONST) { v = lcadr(e); vh = lcadr(e)>>32; }
     else if (car(e)==CONST) v = cadr(e);
 
     switch(op) {
+    case LMUL: case LUMUL:
+        v=ilog(v);
     case LLSHIFT:
     case LULSHIFT:
 	greg = get_register();
 	grn = register_name(greg);
-	printf("\tsll %s,%s,%d\n",crn_h,crn_h,v);
-	printf("\tsrl %s,%s,%d\n",grn,crn_l,32-v);
-	printf("\tor %s,%s,%s\n",crn_h,crn_h,grn);
-	printf("\tsll %s,%s,%d\n",crn_l,crn_l,v);
+	printf("\tmov\t%s, %s lsl #%d\n",crn_h,crn_h,v);
+	printf("\tmov\t%s, %s lsr #%d\n",grn,crn_l,32-v);
+	printf("\torr\t%s, %s,%s\n",crn_h,crn_h,grn);
+	printf("\tmov\t%s, %s lsl #%d\n",crn_l,crn_l,v);
 	free_register(greg);
 	return;
+    case LDIV:
+        v=ilog(v);
     case LRSHIFT:
 	greg = get_register();
 	grn = register_name(greg);
-	printf("\tsrl %s,%s,%d\n",crn_l,crn_l,v);
-	printf("\tsll %s,%s,%d\n",grn,crn_h,32-v);
-	printf("\tor  %s,%s,%s\n",crn_l,crn_l,grn);
-	printf("\tsra %s,%s,%d\n",crn_h,crn_h,v);
+	printf("\tmov\t%s, %s lsr #%d\n",crn_l,crn_l,v);
+	printf("\tmov\t%s, %s lsl #%d\n",grn,crn_h,32-v);
+	printf("\torr\t%s, %s,%s\n",crn_l,crn_l,grn);
+	printf("\tmov\t%s, %s asr #%d\n",crn_h,crn_h,v);
 	free_register(greg);
 	return;
+    case LUDIV:
+        v=ilog(v);
     case LURSHIFT:
 	greg = get_register();
 	grn = register_name(greg);
-	printf("\tsll %s,%s,%d\n",grn,crn_h,32-v);
-	printf("\tsrl %s,%s,%d\n",crn_l,crn_l,v);
-	printf("\tor %s,%s,%s\n",crn_l,grn,crn_l);
-	printf("\tsrl %s,%s,%d\n",crn_h,crn_h,v);
+	printf("\tmov\t%s, %s lsl #%d\n",grn,crn_h,32-v);
+	printf("\tmov\t%s, %s lsr #%d\n",crn_l,crn_l,v);
+	printf("\torr\t%s, %s,%s\n",crn_l,grn,crn_l);
+	printf("\tmov\t%s, %s lsr #%d\n",crn_h,crn_h,v);
 	free_register(greg);
 	return;
+    case LADD:
+        printf("\tadds\t%s, %s, #%d\n",crn_l,crn_l,v);
+        printf("\tadc\t%s, %s, #%d\n",crn_h,crn_h,vh);
+	break;
     case LSUB:
-	v = -v;
-    case LADD:
-	drn = register_name(dx = get_register());
-	if (v<0) {
-	    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);
-	} else {
-	    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);
-	}
+        printf("\tsubs\t%s, %s, #%d\n",crn_l,crn_l,v);
+        printf("\tsbc\t%s, %s, #%d\n",crn_h,crn_h,vh);
+	break;
+    case LBAND: 
+	printf("\tand\t%s, %s, #%d\n",crn_l,crn_l,v);
+	printf("\tand\t%s, %s, #%d\n",crn_h,crn_h,vh);
+	break;
+    case LEOR: 
+	printf("\teor\t%s, %s, #%d\n",crn_l,crn_l,v);
+	printf("\teor\t%s, %s, #%d\n",crn_h,crn_h,vh);
 	break;
     case LBOR:
-	printf("\tori %s,%s,%d\n",crn_l,crn_l,v);
+	printf("\torr\t%s, %s, #%d\n",crn_l,crn_l,v);
+	printf("\torr\t%s, %s, #%d\n",crn_h,crn_h,vh);
 	break;
     default:
 	error(-1);
@@ -4999,8 +5006,8 @@
     crn_h = lregister_name_high(lreg);
     crn_l = lregister_name_low(lreg);
     if (reg0!=regv_l(lreg))
-	printf("\tmove %s,%s\n",crn_l,crn);
-    printf("\tsra %s,%s,31\n",crn_h,crn_l);
+	printf("\tmov\t%s, %s\n",crn_l,crn);
+    printf("\tmov %s,%s asr #31\n",crn_h,crn_l);
 }
 
 void
@@ -5019,8 +5026,8 @@
     crn_h = lregister_name_high(lreg);
     crn_l = lregister_name_low(lreg);
     if (reg0!=regv_l(lreg))
-	printf("\tmove %s,%s\n",crn_l,crn);
-    printf("\tli %s,0\n",crn_h);
+	printf("\tmov\t%s, %s\n",crn_l,crn);
+    printf("\tmov\t%s, #0\n",crn_h);
 }
 
 void
@@ -5037,7 +5044,7 @@
     crn_l = lregister_name_low(reg0=lreg);
     use_int(reg);
     if (ireg!=regv_l(reg0))
-	printf("\tmove %s,%s\n",register_name(ireg),crn_l);
+	printf("\tmov\t%s, %s\n",register_name(ireg),crn_l);
 }
 
 void
@@ -5069,6 +5076,7 @@
     set_lreg(RET_LREGISTER,0);
     if (reg!=USE_CREG&&reg!=RET_LREGISTER)
 	use_longlong(reg);
+    }
 }
 
 void
@@ -5139,23 +5147,17 @@
 static void
 ladd(int dreg,int rreg,int v)   //   rreg = dreg + v
 {
-  int dx;
-  char *crn_l=lregister_name_low(dreg);
-  char *crn_h=lregister_name_high(dreg);
-  char *rrn_l=lregister_name_low(rreg);
-  char *rrn_h=lregister_name_high(rreg);
-  char *drn = register_name(dx = get_register());
-    if (v<0) {
-        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("\taddu %s,%s,%s\n",rrn_h,rrn_h,drn);
+    if (v>0) {
+	printf("\tadds\t%s, %s, #%d\n", 
+		lregister_name_low(creg),lregister_name_low(reg), v);
+	printf("\tadc\t%s %s, #0\n", 
+		lregister_name_high(creg),lregister_name_high(reg));
     } else {
-        printf("\taddu %s,%s,%d\n",rrn_l,crn_l,v);
-        printf("\tsltu %s,%s,%d\n",drn,rrn_l,v);
-        printf("\taddu %s,%s,%s\n",rrn_h,crn_h,drn);
-    }
-    free_register(dx);
+	printf("\tsubs\t%s, %s, #%d\n", 
+		lregister_name_low(creg),lregister_name_low(reg), -v);
+	printf("\tsbc\t%s %s, #0\n", 
+		lregister_name_high(creg),lregister_name_high(reg));
+    }
 }
 
 void
@@ -5231,7 +5233,7 @@
     use_longlong(reg);
     if (regv_l(lreg)==edx || regv_h(lreg)==edx) {
 	edx0 = get_register(); if(!edx0) error(-1);
-	printf("# lassop\n\tmove %s,%s\n",register_name(edx0),
+	printf("# lassop\n\tmov\t%s, %s\n",register_name(edx0),
 	       register_name(edx));
 	edx = edx0;
     }
@@ -5310,7 +5312,7 @@
 #if CASE_CODE
 
 int
-code_table_jump_p() { return 1; }
+code_table_jump_p(int delta) { return delta==1||delta==2||delta==4; }
 
 void
 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel)
@@ -5320,31 +5322,26 @@
     char *trn = register_name(t=get_register());
     char *srn = register_name(s=get_register());
 
-    printf("\taddu\t%s,%s,%d\n",trn,crn,-min);
-    printf("\tsltu\t%s,%s,%d\n",srn,trn,max-min+1);
-    printf("\tbeq\t%s,$0,$L_%d\n",srn,dlabel);
+    code_add(t,s,-min);
+    code_cmpidimm(max-min+1,t,dlabel,GT);
     switch(delta) {
-    case 1: printf("\tsll %s,%s,2\n",trn,trn); break;
+    case 1: printf("\tldrls\tpc, [pc, %s, asl #2]\n",trn); break;
     case 2:
-	printf("\tli\t%s,1\n",srn);
-	printf("\tand\t%s,%s,%s\n",srn,trn,srn);
-	printf("\tbne\t%s,$0,$L_%d\n",srn,dlabel);
-	printf("\tsll %s,%s,1\n",trn,trn);
+	printf("\tand\t%s, %s, #1\n",srn,trn,srn);
+	printf("\tcmp\t%s, #0\n",srn);
+	printf("\tbne\t% .L%d\n",dlabel);
+	printf("\tldrls\tpc, [pc, %s, asl #1]\n",trn); break;
 	break;
     case 4:
-	printf("\tli\t%s,3\n",srn);
-	printf("\tand\t%s,%s,%s\n",srn,trn,srn);
-	printf("\tbne\t%s,$0,$L_%d\n",srn,dlabel);
+	printf("\tand\t%s, %s, #3\n",srn,trn,srn);
+	printf("\tcmp\t%s, #0\n",srn);
+	printf("\tbne\t% .L%d\n",dlabel);
+	printf("\tldrls\tpc, [pc, %s]\n",trn); break;
 	break;
     default:
-	printf("\tdivu %s,%s,%d\n",trn,trn,delta);
-	printf("\tmfhi %s\n",srn);
-	printf("\tbne\t%s,$0,$L_%d\n",srn,dlabel);
-	printf("\tsll %s,%s,2\n",trn,trn); 
-    }
-    printf("\tlw\t%s,$L_%d(%s)\n",trn,l,trn);
-    printf("\t.cpadd %s\n",trn);
-    printf("\tj %s\n",trn);
+	error(-1);
+    }
+    printf("\tb\t.L%d\n",dlabel);
 
     free_register(s);
     free_register(t);
@@ -5354,21 +5351,19 @@
 code_table_open(int l)
 {
     output_mode = DATA_EMIT_MODE;
-    printf("\t.rdata\n");
-    printf("\t.align 4\n");
+    printf("\t.palign 2\n");
     fwddef(l);
 }
 
 void
 code_table_value(int label,int table_top)
 {
-    printf("\t.gpword $L_%d\n",label);
+    printf("\t.word .L%d\n",label);
 }
 
 void
 code_table_close()
 {
-    text_mode(4);
 }
 
 #endif
@@ -5390,7 +5385,7 @@
     } else if (car(rstr)==FNAME) {
 	printf("%s",(char*)cadr(rstr));
     } else if (car(rstr)==STRING) {
-	printf("$L_%d",cadr(rstr));
+	printf(".L%d",cadr(rstr));
     } else {
 	error(-1);
     }
@@ -5634,14 +5629,14 @@
 {
 // printf("# mask 0x%08x ~0x%08x\n",mask,~mask);
 	code_const(~mask,tmp);
-	printf("\tor %s,%s,%s\n",trn,crn,trn);
+	printf("\torr %s,%s,%s\n",trn,crn,trn);
 	/* do conjunction  */
 	printf("\tand %s,%s,%s\n",lrn,trn,lrn);
 	/* make or-mask  */
 	code_const(mask,tmp);
 	printf("\tand %s,%s,%s\n",trn,crn,trn);
 	/* do disjunction  */
-	printf("\tor %s,%s,%s\n",crn,trn,lrn);
+	printf("\torr %s,%s,%s\n",crn,trn,lrn);
 }
 
 extern void
@@ -5695,23 +5690,28 @@
 {
     char *trn;
     int tmp = -1;
+    int m;
 // printf("# mask 0x%08x ~0x%08x\n",mask,~mask);
-    if ((~mask|c)!=-1) {
-	trn = register_name(tmp=get_register());
-	code_const((~mask|c),tmp);
-	/* do conjunction  */
-	printf("\tand %s,%s,%s\n",crn,trn,crn);
+    if ((m=(~mask|c))!=-1) {
+	if (is_stage1_const(m,0)) {
+	    printf("\tand\t%s, %s, #%d\n",crn,trn,m);
+	} else {
+	    trn = register_name(tmp=get_register());
+	    code_const((~mask|c),tmp);
+	    /* do conjunction  */
+	    printf("\tand\t%s, %s, %s\n",crn,trn,crn);
+	}
     }
     /* make or-mask  */
     c = mask&c;
     if (c!=0) {
 	/* do disjunction  */
-	if (!((mask&c)&0xffff0000)) {
-	    printf("\tori %s,%s,%d\n",crn,crn,c);
+	if (is_stage1_const(c,0)) {
+	    printf("\torr\t%s, %s, #%d\n",crn,trn,m);
 	} else {
 	    trn = register_name(tmp=get_register());
 	    code_const(c,tmp);
-	    printf("\tor %s,%s,%s\n",crn,trn,crn);
+	    printf("\torr\t%s, %s, %s\n",crn,trn,crn);
 	}
     }
     if (tmp!=-1) free_register(tmp);
--- a/mc-code-ia32.c	Mon Jul 19 15:16:26 2004 +0900
+++ b/mc-code-ia32.c	Mon Jul 19 16:30:11 2004 +0900
@@ -3145,7 +3145,7 @@
 #if CASE_CODE
 
 int
-code_table_jump_p() { return 1; }
+code_table_jump_p(int delta) { return 1; }
 
 void
 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel)
--- a/mc-code-mips.c	Mon Jul 19 15:16:26 2004 +0900
+++ b/mc-code-mips.c	Mon Jul 19 16:30:11 2004 +0900
@@ -5198,7 +5198,7 @@
 #if CASE_CODE
 
 int
-code_table_jump_p() { return 1; }
+code_table_jump_p(int delta) { return 1; }
 
 void
 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel)
--- a/mc-code-powerpc.c	Mon Jul 19 15:16:26 2004 +0900
+++ b/mc-code-powerpc.c	Mon Jul 19 16:30:11 2004 +0900
@@ -4902,7 +4902,7 @@
 #if CASE_CODE
 
 int
-code_table_jump_p() { return 1; }
+code_table_jump_p(int delta) { return 1; }
 
 void
 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel)
--- a/mc-code.h	Mon Jul 19 15:16:26 2004 +0900
+++ b/mc-code.h	Mon Jul 19 16:30:11 2004 +0900
@@ -250,7 +250,7 @@
 // extern int use_longlong(int);
 
 #if CASE_CODE
-extern int code_table_jump_p();
+extern int code_table_jump_p(int delta);
 extern void code_table_jump(int table,int csvalue,int delta,int max,int min,int dlabel);
 extern void code_table_open(int table);
 extern void code_table_value(int label,int table);
--- a/mc-switch.c	Mon Jul 19 15:16:26 2004 +0900
+++ b/mc-switch.c	Mon Jul 19 16:30:11 2004 +0900
@@ -187,7 +187,7 @@
 {
     int list,i;
     int l,max,min;
-    if (!code_table_jump_p())
+    if (!code_table_jump_p(delta))
 	return cascade_compare(count,chunks);
 
     min=cadr(cadddr(chunks));