Mercurial > hg > CbC > old > device
comparison 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 |
comparison
equal
deleted
inserted
replaced
340:0150de6a3244 | 341:ca34f02b2056 |
---|---|
30 #define DATA_EMIT_MODE 1 | 30 #define DATA_EMIT_MODE 1 |
31 #define RODATA_EMIT_MODE 2 | 31 #define RODATA_EMIT_MODE 2 |
32 | 32 |
33 static void data_mode(char *name); | 33 static void data_mode(char *name); |
34 static void text_mode(); | 34 static void text_mode(); |
35 static void init_ptr_cache(); | |
36 static void ld_indexx(int byte, int n, int xreg,int reg,int sign); | 35 static void ld_indexx(int byte, int n, int xreg,int reg,int sign); |
37 static void local_table(void); | 36 static void local_table(void); |
38 static void shift(char *op, int creg,int reg); | 37 static void shift(char *op, int creg,int reg); |
39 static int struct_push(int e4,int t,int arg); | 38 static int struct_push(int e4,int t,int arg); |
39 | |
40 | 40 |
41 static int creg; | 41 static int creg; |
42 | 42 |
43 static int output_mode = TEXT_EMIT_MODE; | 43 static int output_mode = TEXT_EMIT_MODE; |
44 int data_alignment = 0; | 44 int data_alignment = 0; |
238 static int code_l2(long long ll); | 238 static int code_l2(long long ll); |
239 #endif | 239 #endif |
240 | 240 |
241 static void code_save_stacks(); | 241 static void code_save_stacks(); |
242 static void code_save_input_registers(int dots); | 242 static void code_save_input_registers(int dots); |
243 static void clear_ptr_cache_reg(int r); | |
244 static void set_ireg(int,int); | 243 static void set_ireg(int,int); |
245 static void set_freg(int,int); | 244 static void set_freg(int,int); |
246 static void set_lreg(int,int); | 245 static void set_lreg(int,int); |
247 static void jcond(int l, char cond); | 246 static void jcond(int l, char cond); |
248 | 247 |
508 if (regs[i]) continue; /* 使われている */ | 507 if (regs[i]) continue; /* 使われている */ |
509 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ | 508 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ |
510 return i; /* その場所を表す番号を返す */ | 509 return i; /* その場所を表す番号を返す */ |
511 } | 510 } |
512 /* PTR_CACHE をつぶす */ | 511 /* PTR_CACHE をつぶす */ |
513 for(i=MAX_TMP_REG;i>MIN_TMP_REG;i--) { | 512 if ((i=last_ptr_cache())) { |
514 if (regs[i]==PTRC_REG) { | 513 clear_ptr_cache_reg(i); |
515 clear_ptr_cache_reg(i); | |
516 } else | |
517 continue; | |
518 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ | 514 regs[i]=USING_REG; /* そのレジスタを使うことを宣言し */ |
519 return i; /* その場所を表す番号を返す */ | 515 return i; /* その場所を表す番号を返す */ |
520 } | 516 } |
521 /* search register stack */ | 517 /* search register stack */ |
522 for(i=0;i<reg_sp;i++) { | 518 for(i=0;i<reg_sp;i++) { |
699 //regv_l(i)=0; | 695 //regv_l(i)=0; |
700 //regv_h(i)=0; | 696 //regv_h(i)=0; |
701 } | 697 } |
702 } | 698 } |
703 | 699 |
700 extern void | |
701 use_ptr_cache(int r) | |
702 { | |
703 regs[r]=PTRC_REG; | |
704 } | |
705 | |
704 int | 706 int |
705 get_input_dregister_var(int i,NMTBL *n,int is_code,int d) | 707 get_input_dregister_var(int i,NMTBL *n,int is_code,int d) |
706 { | 708 { |
707 if (is_code) { | 709 if (is_code) { |
708 if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0; | 710 if(!(i<FREG_VAR_BASE-FREG_VAR_MIN)) return 0; |
1015 return xreg; | 1017 return xreg; |
1016 } | 1018 } |
1017 | 1019 |
1018 static int code_base; | 1020 static int code_base; |
1019 | 1021 |
1020 #define MAX_PTR_CACHE 10 | 1022 extern void |
1021 | 1023 code_ptr_cache_def(int r,NMTBL *nptr) |
1022 int ptr_cache=0; | 1024 { |
1023 | 1025 char *rrn = register_name(r); |
1024 void | |
1025 init_ptr_cache() | |
1026 { | |
1027 int i; | |
1028 for(i=0;i<MAX_PTR_CACHE;i++) { | |
1029 ptr_cache=glist3(0,ptr_cache,0); | |
1030 } | |
1031 } | |
1032 | |
1033 void | |
1034 clear_ptr_cache_reg(int r) | |
1035 { | |
1036 int ptcptr=ptr_cache; | |
1037 while(ptcptr) { | |
1038 if(car(ptcptr)&&caddr(ptcptr)==r) { | |
1039 car(ptcptr)=0; | |
1040 caddr(ptcptr)=0; | |
1041 free_register(r); | |
1042 return; | |
1043 } | |
1044 ptcptr=cadr(ptcptr); | |
1045 } | |
1046 } | |
1047 | |
1048 void | |
1049 clear_ptr_cache() | |
1050 { | |
1051 int ptcptr=ptr_cache; | |
1052 while(ptcptr) { | |
1053 if(car(ptcptr)) | |
1054 free_register(caddr(ptcptr)); | |
1055 car(ptcptr)=0; | |
1056 caddr(ptcptr)=0; | |
1057 ptcptr=cadr(ptcptr); | |
1058 } | |
1059 } | |
1060 | |
1061 | |
1062 int | |
1063 get_ptr_cache(NMTBL *nptr) | |
1064 { | |
1065 int r; | |
1066 int ptcptr=ptr_cache; | |
1067 int g = (int)nptr; | |
1068 int p,p1; | |
1069 char *rrn; | |
1070 | |
1071 p1 = ptcptr; p = cadr(p1); /* unnecessary, if ptcptr is initialized */ | |
1072 while(ptcptr) { | |
1073 if(car(ptcptr)==g) return caddr(ptcptr); | |
1074 p1=p; p=ptcptr; | |
1075 ptcptr=cadr(ptcptr); | |
1076 } | |
1077 cadr(p1)=0; /* remove the last one */ | |
1078 cadr(p) = ptr_cache; /* connect current queue to the last one */ | |
1079 ptr_cache = p; /* now the last one is the top */ | |
1080 if (!caddr(p)) { | |
1081 if((r=get_register())) { | |
1082 caddr(p)=r; regs[r]=PTRC_REG; | |
1083 } else { | |
1084 error(-1); | |
1085 r=creg; /* this can't happen */ | |
1086 } | |
1087 car(p)=g; | |
1088 } else { | |
1089 r = caddr(p); | |
1090 } | |
1091 rrn = register_name(r); | |
1092 if (nptr->sc==STATIC) { | 1026 if (nptr->sc==STATIC) { |
1093 printf("\taddis %s,r31,ha16(_%s-L_%d)\n", | 1027 printf("\taddis %s,r31,ha16(_%s-L_%d)\n", |
1094 rrn,nptr->nm,code_base); | 1028 rrn,nptr->nm,code_base); |
1095 printf("\tla %s,lo16(_%s-L_%d)(%s)\n", | 1029 printf("\tla %s,lo16(_%s-L_%d)(%s)\n", |
1096 rrn,nptr->nm,code_base,rrn); | 1030 rrn,nptr->nm,code_base,rrn); |
1098 printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n", | 1032 printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n", |
1099 rrn,nptr->nm,code_base); | 1033 rrn,nptr->nm,code_base); |
1100 printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n", | 1034 printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n", |
1101 rrn,nptr->nm,code_base,rrn); | 1035 rrn,nptr->nm,code_base,rrn); |
1102 } | 1036 } |
1103 return r; | |
1104 } | 1037 } |
1105 | 1038 |
1106 static char *cload(int sz) { return sz==1?"lbz":sz==SIZE_OF_SHORT?"lhz":"lwz"; } | 1039 static char *cload(int sz) { return sz==1?"lbz":sz==SIZE_OF_SHORT?"lhz":"lwz"; } |
1107 static char *cstore(int sz) { return sz==1?"stb":sz==SIZE_OF_SHORT?"sth":"stw"; } | 1040 static char *cstore(int sz) { return sz==1?"stb":sz==SIZE_OF_SHORT?"sth":"stw"; } |
1108 | 1041 |
2968 | 2901 |
2969 extern void | 2902 extern void |
2970 emit_longlong(int e) | 2903 emit_longlong(int e) |
2971 { | 2904 { |
2972 #if LONGLONG_CODE | 2905 #if LONGLONG_CODE |
2906 long long d = lcadr(e); | |
2973 data_mode(0); | 2907 data_mode(0); |
2974 long long d = lcadr(e); | |
2975 printf("\t.long\t0x%x,0x%x\n",code_l2(d),code_l1(d)); | 2908 printf("\t.long\t0x%x,0x%x\n",code_l2(d),code_l1(d)); |
2976 #endif | 2909 #endif |
2977 } | 2910 } |
2978 | 2911 |
2979 extern void | 2912 extern void |
2980 emit_double(int e) | 2913 emit_double(int e) |
2981 { | 2914 { |
2982 #if FLOAT_CODE | 2915 #if FLOAT_CODE |
2916 double d = dcadr(e); | |
2983 data_mode(0); | 2917 data_mode(0); |
2984 double d = dcadr(e); | |
2985 printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d)); | 2918 printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d)); |
2986 #endif | 2919 #endif |
2987 } | 2920 } |
2988 | 2921 |
2989 extern void | 2922 extern void |
2990 emit_float(int e) | 2923 emit_float(int e) |
2991 { | 2924 { |
2992 #if FLOAT_CODE | 2925 #if FLOAT_CODE |
2926 float f = dcadr(e); | |
2993 data_mode(0); | 2927 data_mode(0); |
2994 float f = dcadr(e); | |
2995 printf("\t.long\t0x%x\n",*(int *)&f); | 2928 printf("\t.long\t0x%x\n",*(int *)&f); |
2996 #endif | 2929 #endif |
2997 } | 2930 } |
2998 | 2931 |
2999 extern void | 2932 extern void |