diff mc-code-powerpc.c @ 341:ca34f02b2056

ptr cache speed up
author kono
date Sat, 26 Jun 2004 11:09:11 +0900
parents 0150de6a3244
children 2b3946ee4fc9
line wrap: on
line diff
--- a/mc-code-powerpc.c	Sat Jun 26 00:26:01 2004 +0900
+++ b/mc-code-powerpc.c	Sat Jun 26 11:09:11 2004 +0900
@@ -32,12 +32,12 @@
 
 static void data_mode(char *name);
 static void text_mode();
-static void init_ptr_cache();
 static void ld_indexx(int byte, int n, int xreg,int reg,int sign);
 static void local_table(void);
 static void shift(char *op, int creg,int reg);
 static int struct_push(int e4,int t,int arg);
 
+
 static int creg;
 
 static int output_mode = TEXT_EMIT_MODE;
@@ -240,7 +240,6 @@
 
 static void code_save_stacks();
 static void code_save_input_registers(int dots);
-static void clear_ptr_cache_reg(int r);
 static void    set_ireg(int,int);
 static void    set_freg(int,int);
 static void    set_lreg(int,int);
@@ -510,11 +509,8 @@
 	return i;   /* その場所を表す番号を返す */
     }
     /* PTR_CACHE をつぶす */
-    for(i=MAX_TMP_REG;i>MIN_TMP_REG;i--) {
-	if (regs[i]==PTRC_REG) {
-	    clear_ptr_cache_reg(i);
-	} else 
-	    continue;
+    if ((i=last_ptr_cache())) {
+	clear_ptr_cache_reg(i);
 	regs[i]=USING_REG;      /* そのレジスタを使うことを宣言し */
 	return i;   /* その場所を表す番号を返す */
     }
@@ -701,6 +697,12 @@
     }
 }
 
+extern void
+use_ptr_cache(int r)
+{
+    regs[r]=PTRC_REG;
+}
+
 int
 get_input_dregister_var(int i,NMTBL *n,int is_code,int d)
 {
@@ -1017,78 +1019,10 @@
 
 static int code_base;
 
-#define MAX_PTR_CACHE 10
-
-int ptr_cache=0;
-
-void
-init_ptr_cache()
-{
-    int i;
-    for(i=0;i<MAX_PTR_CACHE;i++) {
-	ptr_cache=glist3(0,ptr_cache,0);
-    }
-}
-
-void
-clear_ptr_cache_reg(int r)
-{
-    int ptcptr=ptr_cache;
-    while(ptcptr) {
-	if(car(ptcptr)&&caddr(ptcptr)==r) {
-	    car(ptcptr)=0;
-	    caddr(ptcptr)=0;
-	    free_register(r);
-	    return;
-	}
-	ptcptr=cadr(ptcptr);
-    }
-}
-
-void
-clear_ptr_cache()
+extern void
+code_ptr_cache_def(int r,NMTBL *nptr)
 {
-    int ptcptr=ptr_cache;
-    while(ptcptr) {
-	if(car(ptcptr))
-	    free_register(caddr(ptcptr));
-	car(ptcptr)=0;
-	caddr(ptcptr)=0;
-	ptcptr=cadr(ptcptr);
-    }
-}
-
-
-int
-get_ptr_cache(NMTBL *nptr)
-{
-    int r;
-    int ptcptr=ptr_cache;
-    int g = (int)nptr;
-    int p,p1;
-    char *rrn;
-
-    p1 = ptcptr; p = cadr(p1); /* unnecessary, if ptcptr is initialized */
-    while(ptcptr) {
-	if(car(ptcptr)==g) return caddr(ptcptr);
-	p1=p; p=ptcptr;
-	ptcptr=cadr(ptcptr);
-    }
-    cadr(p1)=0;            /* remove the last one */
-    cadr(p) = ptr_cache;   /* connect current queue to the last one */
-    ptr_cache = p;         /* now the last one is the top */
-    if (!caddr(p)) {
-	if((r=get_register())) {
-	    caddr(p)=r; regs[r]=PTRC_REG;
-	} else {
-	    error(-1);
-	    r=creg; /* this can't happen */
-	}
-	car(p)=g;
-    } else {
-	r = caddr(p);
-    }
-    rrn = register_name(r);
+    char *rrn = register_name(r);
     if (nptr->sc==STATIC) {
 	printf("\taddis %s,r31,ha16(_%s-L_%d)\n",
 		 rrn,nptr->nm,code_base);
@@ -1100,7 +1034,6 @@
 	printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n",
 		 rrn,nptr->nm,code_base,rrn);
     }
-    return r;
 }
 
 static char *cload(int sz) { return sz==1?"lbz":sz==SIZE_OF_SHORT?"lhz":"lwz"; }
@@ -2970,8 +2903,8 @@
 emit_longlong(int e)
 {
 #if LONGLONG_CODE
+    long long d = lcadr(e);
     data_mode(0);
-    long long d = lcadr(e);
     printf("\t.long\t0x%x,0x%x\n",code_l2(d),code_l1(d));
 #endif
 }
@@ -2980,8 +2913,8 @@
 emit_double(int e)
 {
 #if FLOAT_CODE
+    double d = dcadr(e);
     data_mode(0);
-    double d = dcadr(e);
     printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d));
 #endif
 }
@@ -2990,8 +2923,8 @@
 emit_float(int e)
 {
 #if FLOAT_CODE
+    float f = dcadr(e);
     data_mode(0);
-    float f = dcadr(e);
     printf("\t.long\t0x%x\n",*(int *)&f);
 #endif
 }