changeset 665:2cc418b247ce

*** empty log message ***
author kono
date Sat, 28 Apr 2007 22:55:19 +0900
parents ec1bac997e50
children 7c42cf329666
files mc-code-spu.c
diffstat 1 files changed, 85 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-spu.c	Sat Apr 28 21:10:26 2007 +0900
+++ b/mc-code-spu.c	Sat Apr 28 22:55:19 2007 +0900
@@ -133,7 +133,7 @@
 #define REG_VAR_MIN  3
 #define REG_VAR_USER_MAX  127     /* at leat 6 tmp var */
 #define REG_VAR_MAX 127
-#define MIN_TMP_REG 4
+#define MIN_TMP_REG 3
 #define MAX_TMP_REG 127
 
 #define FREG_VAR_BASE 3
@@ -142,8 +142,8 @@
 #define MIN_TMP_FREG 3
 #define MAX_TMP_FREG 127
 
-int MAX_REGISTER=128;             /* ARMのレジスタを10個まで使う*/
-#define  REAL_MAX_REGISTER 128    /* ARMのレジスタが32ということ*/
+int MAX_REGISTER=127;             /* ARMのレジスタを10個まで使う*/
+#define  REAL_MAX_REGISTER 127    /* ARMのレジスタが32ということ*/
 
 #define FREG_OFFSET 3
 #define LREG_OFFSET 3
@@ -411,7 +411,7 @@
 	printf("\t.set .LC%d, %d\n",r1_offset_label,r1_offsetv);
     } else {
 	lvar_offsetv = 
-	    -12 - max_reg_var*SIZE_OF_INT-max_reg_var*SIZE_OF_DOUBLE;
+	    -(-32 - max_reg_var*SIZE_OF_INT-max_reg_var*SIZE_OF_DOUBLE);
 	printf("\t.set .LC%d, %d\n",lvar_offset_label,lvar_offsetv);
     }
     if (max_func_arg_label) {
@@ -494,7 +494,7 @@
             printf("[fp, %d]%s\n",CODE_LVAR(l),cext);
     } else if (l<0) {  /* local variable */
         //printf("[fp, #%d+.L%d]%s\n",FUNC_LVAR(l),lvar_offset_label,cext);
-        printf("%d($sp)\n",FUNC_LVAR(l));
+        printf(".LC%d+%d($sp)\n",lvar_offset_label,FUNC_LVAR(l));
     } else if (l>=ARG_LVAR_OFFSET) {  /* caller's arguments */
         printf("[sp, %d]%s\n",CALLER_ARG(l-ARG_LVAR_OFFSET),cext);
     } else { /* callee's arguments */
@@ -515,7 +515,7 @@
         } else
 	    code_add(creg,CODE_LVAR(l),REG_fp);
     } else if (l<0) {  /* local variable */
-//        printf("\tsf\t%s, fp, %d\n",register_name(creg), FUNC_LVAR(l));
+//        printf("\tsfi\t%s, fp, %d\n",register_name(creg), FUNC_LVAR(l));
 	trn = register_name(tmp = get_register());
 	//disp = search_const(LVAR,glist2(lvar_offset_label,FUNC_LVAR(l)),&label);
         printf("\tlqd\t%s, %d($sp)\n",trn,(disp*4));
@@ -567,7 +567,7 @@
 
 void
 code_gexpr(int e){
-     // if (is_int_reg(creg) && creg!=ireg) error(-1);
+     if (is_int_reg(creg) && creg!=ireg) error(-1);
 //  register_usage("code_gexpr");
 }
 
@@ -828,7 +828,7 @@
 	use_input_reg(i,1);
     } else {
 	if (i<0||i>=MAX_INPUT_REGISTER_VAR) return 0;
-	i = i+1;
+	i = i+MIN_TMP_REG;
     }
     return list3(REGISTER,i,(int)n);
 }
@@ -1087,11 +1087,13 @@
 {
     int xreg,reg;
     xreg=pop_register();
-    if (xreg<= -REG_LVAR_OFFSET) {
-	reg = get_register();
+    // REG_LVAR_OFFSET = 2
+	if (xreg<= -REG_LVAR_OFFSET) {
+		reg = get_register();
         code_rlvar(REG_LVAR_OFFSET+xreg,reg);
-	free_lvar(REG_LVAR_OFFSET+xreg);
-	xreg = reg;
+		free_lvar(REG_LVAR_OFFSET+xreg);
+		//free_lvar(-4);
+		xreg = reg;
     }
     return xreg;
 }
@@ -1346,7 +1348,7 @@
     sign = make_const(c,&p1,&p2,&p3,mode);
     return (c==0||(p1&&!p2&&!p3))?sign:0;
 }
-
+/*
 
 static void 
 code_const0(int e2,int reg,char *opt)
@@ -1359,7 +1361,23 @@
     use_int(reg);
     crn = register_name(reg);
     if ((s=make_const(e2,&p1,&p2,&p3,CONST))) {
-	add = s>0?"a":"sfi";
+	add = s>0?"a":"sf";
+	mov = s>0?"il":"mvn";
+	printf("\t%s\t%s, %d\n",mov,crn,p1);
+	if (p2) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p2);
+	if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3);
+    } else {
+	//disp = search_const(CONST,e2,&label);
+	printf("\tlqd\t%s, %d($sp)\n",crn,(disp*4));
+    }
+}
+*/
+extern void 
+code_const(int e2,int reg) {
+    char *crn;
+	int r;
+	//code_const0(e2,reg,"");
+	//	printf("code_const\n");
 	/************************************************************
 	 * ここでp1の値によって、命令が異なる......                 *
 	 * il命令は-32768~32767                                     *
@@ -1368,20 +1386,32 @@
 	 * example:15728639                                         *
 	 *     15728639/16^4 = 239             ilhu  $4,239         *
 	 *     15728639%16^4 = 65535           iohl  $4,65535       *
+	 *負の場合も異なる                                          *
+	 * example : -99999  fffe7961                               *
+	 *     r = ~(-99999)   r = (r >> 16) & 0xffff; r += 1; r=-r;*       
+	 *     ilhu     $4,-2                                       *
+	 *     -99999 & 0xfff       iohl     $4,31073    -> 0x7961  *
+	 * example : -15728639  ff100001                            *
 	 ***********************************************************/
-	mov = s>0?"il":"mvn";
-	printf("\t%s\t%s, %d\n",mov,crn,p1);
-	if (p2) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p2);
-	if (p3) printf("\t%s\t%s, %s, %d\n",add,crn,crn,p3);
-    } else {
-	//disp = search_const(CONST,e2,&label);
-	printf("\tlqd\t%s, %d($sp)\n",crn,(disp*4));
-    }
-}
-
-extern void 
-code_const(int e2,int reg) {
-    code_const0(e2,reg,"");
+	use_int(reg);
+	crn = register_name(reg);
+	if (-32768<e2&&e2<32768)
+		printf("\til %s,%d\n",crn,e2);
+	else if(32767<e2&&e2<262143)
+		printf("\tila %s,%d\n",crn,e2);
+	else if(262143<e2) {
+		printf("\t ilhu %s,%d\n",crn,e2/16^4);
+		printf("\t iohl %s,%d\n",crn,e2%16^4);
+	} else {
+		r = (~e2 >> 16) & 0xffff;
+		r += 1;
+		r = -r;
+		printf("\tilhu %s,%d\n",crn,r);
+		if(e2 > -262143)
+			printf("\tiohl %s,%d\n",crn, (e2&0xffff));
+		else
+			printf("\tori %s,%s,%d\n",crn,crn,(e2&0xffff));
+	}
 }
 
 static void 
@@ -1758,7 +1788,7 @@
     char *s,*crn;
     //int lb,label;
     int lb;
-	printf("creg:%d\n",creg);
+	//printf("creg:%d\n",creg);
 	NMTBL *n = (NMTBL *)cadr(e1);
     if ((lb=attr_value(n,LABEL))) {
 	// already defined
@@ -2212,7 +2242,7 @@
 	reg = freg;
     case DREGISTER:
 	if (car(e2)==DREGISTER) reg = cadr(e2);
-        printf("\tstfd\t%s, [sp, #-8]!\n",register_name(reg));
+        printf("\tstqd\t%s, [sp, #-8]!\n",register_name(reg));
         printf("\tldmfd\tsp!, {%s, %s}\n",lregister_name_low(r),lregister_name_high(r));
     }
     if (tmp!=-1) free_lvar(tmp);
@@ -2588,7 +2618,7 @@
     // jump to continuation means use all register variable
     max_reg_var = REG_VAR_MAX-REG_VAR_MIN;
     max_reg_var = FREG_VAR_MAX-FREG_VAR_MIN;
-    printf("\tbr\t%s\n",s);
+    printf("\thogebr\t%s\n",s);
     control=0;
 }
 
@@ -2831,21 +2861,21 @@
 	printf("\tsf\t%s, %s, %s\n",crn,crn,orn);
 	break;
     case CMP:
-        printf("\tcmp\t%s, %s\n",crn,orn);
+        printf("\tceqp\t%s, %s\n",crn,orn);
 	break;
     case BAND: 
 	printf("\tand\t%s, %s, %s\n",crn,crn,orn);
 	break;
     case EOR: 
-	printf("\teor\t%s, %s, %s\n",crn,crn,orn);
+	printf("\txor\t%s, %s, %s\n",crn,crn,orn);
 	break;
     case BOR:
-	printf("\torr\t%s, %s, %s\n",crn,crn,orn);
+	printf("\tor\t%s, %s, %s\n",crn,crn,orn);
 	break;
     case MUL:
     case UMUL:
 	/* target!=source */
-	printf("\tmul\t%s, %s, %s\n",crn,orn,crn);
+	printf("\tmpy\t%s, %s, %s\n",crn,orn,crn);
 	break;
     case DIV:
 	code_int_lib("__divsi3",creg,oreg); break;
@@ -2900,12 +2930,12 @@
     case DIV:
 	v=ilog(v);
     case RSHIFT:
-	printf("\tmov\t%s, %s, asr #%d\n",crn,crn,v);
+	printf("\trotmai\t%s, %s, %d\n",crn,crn,v);
 	break;
     case UDIV:
 	v=ilog(v);
     case URSHIFT:
-	printf("\tmov\t%s, %s, lsr #%d\n",crn,crn,v);
+	printf("\tshli\t%s, %s,%d\n",crn,crn,v);
 	break;
     case ADD:
 	code_add(creg,v,creg);
@@ -2913,9 +2943,9 @@
     case SUB:
 	code_add(creg,-v,creg);
 	break;
-    case CMP: printf("\tcmp\t%s,%d\n",crn,v); break;
-    case BOR: printf("\torr\t%s, %s, #%d\n",crn,crn,v); break;
-    case EOR: printf("\teor\t%s, %s, #%d\n",crn,crn,v); break;
+    case CMP: printf("\tceq\t%s,%d\n",crn,v); break;
+    case BOR: printf("\tor\t%s, %s, #%d\n",crn,crn,v); break;
+    case EOR: printf("\txor\t%s, %s, #%d\n",crn,crn,v); break;
     case BAND: printf("\tand\t%s, %s, #%d\n",crn,crn,v); break;
     default:
 	error(-1);
@@ -2929,7 +2959,10 @@
     char *rrn = register_name(reg);
     use_int(creg);
     crn = register_name(creg);
-    printf("\tmov\t%s, %s, %s  %s\n",crn,crn,op,rrn);
+    if(crn == "asr") printf("\tshl\t%s, %s,%s\n",crn,crn,rrn);      //算術右シフト
+	if(crn == "asl")  printf("\trotma\t%s, %s, -%s\n",crn,crn,rrn);  //算術左シフト
+	if(crn == "lsr")  printf("\trot\t%s, %s, %s\n",crn,crn,rrn);  //左シフト
+	//printf("\tmov\t%s, %s, %s  %s\n",crn,crn,op,rrn);
 }
 
 void
@@ -2959,12 +2992,13 @@
 	rn = register_name(reg= get_register());
 	regs[csreg] = regsv;
 	code_const(e,reg);
-	printf("\tcmp\t%s, %s\n",crn,rn);
+	printf("\tceq\t%s, %s, %s\n",crn,crn,rn);
     } else {
 	if (sign>0) 
-	    printf("\tcmp\t%s, #%d\n",crn,e);
+	    printf("\tceqi\t%s, %s, %d\n",crn,crn,e);
 	else
-	    printf("\tcmn\t%s, #%d\n",crn,-e);
+	    //printf("\tcmn\t%s, #%d\n",crn,-e);
+	    printf("\tceqi\t%s, %s, %d\n",crn,crn,-e);
     }
     switch(cond) {
     case -1: break;
@@ -3012,18 +3046,18 @@
     if (mode==COND_BRANCH_CONST||mode==COND_VALUE_CONST) {
 	rn1 =		register_name(r1);
 	if (r2>=0) 
-	    printf("\tcmp\t%s, #%d\n",rn1,r2);
+	    printf("\tceqi\t%s, %s, %d\n",rn1,rn1,r2);
 	else
-	    printf("\tcmn\t%s, #%d\n",rn1,-r2);
+	    printf("\tceqi\t%s, %s, -%d\n",rn1,rn1,-r2);
     } else {
 	rn1 =		register_name(r1);
 	rn2 =		register_name(r2);
-	printf("\tcmp\t%s, %s\n",rn1,rn2);
+	printf("\tceq\t%s, %s, %s\n",rn1,rn1,rn2);
     }
 
     switch(op+(!cond)*BNOT) {
-    case GT:  case LE+BNOT:	cc="gt"; ncc="le"; break;
-    case LE:  case GT+BNOT:	cc="le"; ncc="gt"; break;
+    case GT:  case LE+BNOT:	cc="cgt"; ncc="le"; break;
+    case LE:  case GT+BNOT:	cc="le"; ncc="cgt"; break;
     case GE:  case LT+BNOT:	cc="ge"; ncc="lt"; break;
     case LT:  case GE+BNOT:	cc="lt"; ncc="ge"; break;
     case UGT: case ULE+BNOT:	cc="hi"; ncc="ls"; break;
@@ -3205,8 +3239,8 @@
     printf("\tstqd\t$lr,16($sp)\n");
     printf("\tstqd\t$sp,-32($sp)\n");
     printf("\tai\t$sp,$sp,-32\n");	
-    gen_jmp(entry_label = fwdlabel());
-    register_save_return_label = backdef();
+    //gen_jmp(entry_label = fwdlabel());
+    //register_save_return_label = backdef();
     clear_ptr_cache();
 }
 
@@ -5083,7 +5117,7 @@
     default:
 	error(-1);
     }
-    printf("\tbr\t.L%d\n",dlabel);
+    printf("\thbr\t.L%d\n",dlabel);
 
     free_register(t);
 }