Mercurial > hg > CbC > old > device
changeset 137:9fb09db54436
fix powerpc get_fregister_var's regs error.
author | kono |
---|---|
date | Sun, 04 May 2003 22:08:20 +0900 |
parents | 069960078249 |
children | e6e77af048a1 |
files | Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h mc-parse.c mc.h |
diffstat | 9 files changed, 231 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sun May 04 15:10:41 2003 +0900 +++ b/Changes Sun May 04 22:08:20 2003 +0900 @@ -2904,3 +2904,25 @@ が起こらなければ、特に問題はないんだけどね。 局所変数、大域変数、定数の足し算とかは処理した方がいいのかなぁ。 + +Sun May 4 15:10:48 JST 2003 + +たぶん、oprt とかは、それほど効果は無いよ。効くのは、 +register full の時だけだろ? + +MIPS version は、まだまだ全然と言う感じ。ゆっくり +片付けて行くしかないね。 + +Sun May 4 18:29:26 JST 2003 + +d50 では、引数はレジスタに $4,$5,$6,$7 の double 二つしかのらない。 + +f50 では、引数は + $f12,$f14,$6,$7 +というように4つ乗るらしい。(こまったもんだ...) + +i50では、$4,$5,$6,$7 だね。 + +あとはstackに積むみたいね。 + +これらを get_input_register_var で処理するわけか。
--- a/mc-code-ia32.c Sun May 04 15:10:41 2003 +0900 +++ b/mc-code-ia32.c Sun May 04 22:08:20 2003 +0900 @@ -255,14 +255,14 @@ } int -free_register_count(void) +free_register_count(int d) { int i,count; count = 0; for(i=0;i<MAX_REGISTER;i++) { if (! regs[i] && ! regv[i]) count++; } - return count; + return d?0:count; } void @@ -304,8 +304,41 @@ } void -code_arg_register() +code_arg_register(NMTBL *fnptr) { + int args = fnptr->dsp; + NMTBL *n; + int reg_var = 0; + int freg_var = 0; + int type; + int reg; + int is_code0 = is_code(fnptr); + + while (args) { + /* process in reverse order */ + n = (NMTBL*)caddr(args); + type = n->ty; + if (scalar(type)) { + if ((reg = get_input_register_var(reg_var,n,is_code0))) { + n->sc = REGISTER; + n->dsp = cadr(reg); + regv[n->dsp]= 1; + regs[n->dsp]= INPUT_REG; + reg_var++; + cadddr(args)=size_of_int; /* why we need this? */ + } + } else if (type==FLOAT||type==DOUBLE) { + if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { + n->sc = DREGISTER; + n->dsp = cadr(reg); + fregv[n->dsp]= 1; + fregs[n->dsp]= INPUT_REG; + freg_var++; + cadddr(args)=size(type); /* why we need this? */ + } + } + args = cadr(args); + } } void @@ -384,6 +417,12 @@ return list2(LVAR,new_lvar(size_of_double)); } +int +get_dregister_var(NMTBL *nptr) +{ + return get_fregister_var(nptr); +} + void use_register(int virt, int real, int move) { @@ -943,7 +982,7 @@ #ifdef SAVE_STACKS code_save_stacks(); #endif - if (free_register_count()<1) { + if (free_register_count(0)<1) { for(save = 0;save==dreg||save==creg;save++); printf("\tpushl %s\n",register_name(save,0)); saved = 1; @@ -1211,7 +1250,7 @@ { int edx_save; /* make real EDX register empty */ - if (free_register_count()<1) { + if (free_register_count(0)<1) { for(edx_save = 0;edx_save==dreg||edx_save==creg;edx_save++); printf("\tpushl %s\n",register_name(edx_save,0)); edx_stack = list3(edx_save,edx_stack,0);
--- a/mc-code-mips.c Sun May 04 15:10:41 2003 +0900 +++ b/mc-code-mips.c Sun May 04 22:08:20 2003 +0900 @@ -245,12 +245,53 @@ fregv[freg]=0; } +void +code_arg_register(NMTBL *fnptr) +{ + int args = fnptr->dsp; + NMTBL *n; + int reg_var = 0; + int freg_var = 0; + int type; + int reg; + int is_code0 = is_code(fnptr); -void -code_arg_register() -{ + while (args) { + /* process in reverse order */ + n = (NMTBL*)caddr(args); + type = n->ty; + if (scalar(type)) { + if ((reg = get_input_register_var(reg_var,n,is_code0))) { + n->sc = REGISTER; + n->dsp = cadr(reg); + regv[n->dsp]= 1; + regs[n->dsp]= INPUT_REG; + reg_var++; + cadddr(args)=size_of_int; /* why we need this? */ + } + } else if (type==FLOAT) { + if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { + n->sc = DREGISTER; + n->dsp = cadr(reg); + fregv[n->dsp]= 1; + fregs[n->dsp]= INPUT_REG; + freg_var++; + cadddr(args)=size(type); /* why we need this? */ + } + } else if (type==DOUBLE) { + if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { + n->sc = DREGISTER; + n->dsp = cadr(reg); + fregv[n->dsp]= 1; + fregs[n->dsp]= INPUT_REG; + freg_var++; + cadddr(args)=size(type); /* why we need this? */ + } + } + args = cadr(args); + } if (is_function(fnptr)) - code_save_input_registers(); + code_save_input_registers(); } int @@ -372,7 +413,7 @@ } int -free_register_count(void) +free_register_count(int d) { int i,count,fcount; fcount = count = 0; @@ -383,7 +424,7 @@ if (! fregs[i] && ! fregv[i]) fcount++; } fprintf(stderr,"# free reg %d freg %d\n",count,fcount); - return count+fcount; + return d?fcount:count; } int @@ -510,6 +551,12 @@ return list2(LVAR,new_lvar(size_of_double)); } +int +get_dregister_var(NMTBL *n) +{ + return get_fregister_var(n); +} + void emit_push() {
--- a/mc-code-powerpc.c Sun May 04 15:10:41 2003 +0900 +++ b/mc-code-powerpc.c Sun May 04 22:08:20 2003 +0900 @@ -279,8 +279,41 @@ void -code_arg_register() +code_arg_register(NMTBL *fnptr) { + int args = fnptr->dsp; + NMTBL *n; + int reg_var = 0; + int freg_var = 0; + int type; + int reg; + int is_code0 = is_code(fnptr); + + while (args) { + /* process in reverse order */ + n = (NMTBL*)caddr(args); + type = n->ty; + if (scalar(type)) { + if ((reg = get_input_register_var(reg_var,n,is_code0))) { + n->sc = REGISTER; + n->dsp = cadr(reg); + regv[n->dsp]= 1; + regs[n->dsp]= INPUT_REG; + reg_var++; + cadddr(args)=size_of_int; /* why we need this? */ + } + } else if (type==FLOAT||type==DOUBLE) { + if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { + n->sc = DREGISTER; + n->dsp = cadr(reg); + fregv[n->dsp]= 1; + fregs[n->dsp]= INPUT_REG; + freg_var++; + cadddr(args)=size(type); /* why we need this? */ + } + } + args = cadr(args); + } if (is_function(fnptr)) code_save_input_registers(); } @@ -428,7 +461,7 @@ } int -free_register_count(void) +free_register_count(int d) { int i,count,fcount; fcount = count = 0; @@ -438,8 +471,8 @@ for(i=0;i<MAX_FREGISTER;i++) { if (! fregs[i] && ! fregv[i]) fcount++; } - fprintf(stderr,"# free reg %d freg %d\n",count,fcount); - return count+fcount; + printf("# free reg %d freg %d\n",count,fcount); + return d?fcount:count; } int @@ -533,13 +566,14 @@ { int i; for(i=0;i<REG_VAR_BASE-REG_VAR_MIN;i++) { - if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ - regs[REG_VAR_BASE-i]=USING_REG; /* そのレジスタを使うことを宣言し */ - regv[REG_VAR_BASE-i]=0; + if (! regs[REG_VAR_BASE-i]) { /* 使われていないなら */ + /* そのレジスタを使うことを宣言し */ + regs[REG_VAR_BASE-i]=USING_REG; + regv[REG_VAR_BASE-i]=0; if (i>max_reg_var) max_reg_var=i; /* その場所を表す番号を返す */ return list3(REGISTER,REG_VAR_BASE-i,(int)n); - } + } } return list2(LVAR,new_lvar(size_of_int)); } @@ -554,9 +588,9 @@ { int i; for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { - if (! regs[FREG_VAR_BASE-i]) { /* 使われていないなら */ - regs[FREG_VAR_BASE-i]=USING_REG; /*そのレジスタを使うことを宣言し*/ - regv[FREG_VAR_BASE-i]=0; + if (! fregs[FREG_VAR_BASE-i]) { /* 使われていないなら */ + fregs[FREG_VAR_BASE-i]=USING_REG; /*そのレジスタを使うことを宣言し*/ + fregv[FREG_VAR_BASE-i]=0; if (i>max_freg_var) max_freg_var=i; /* その場所を表す番号を返す */ return list3(DREGISTER,FREG_VAR_BASE-i,(int)n); @@ -565,6 +599,12 @@ return list2(LVAR,new_lvar(size_of_double)); } +int +get_dregister_var(NMTBL *n) +{ + return get_fregister_var(n); +} + void emit_push() { @@ -1362,7 +1402,8 @@ } else if (!simple_args(e3) && cadr(e3)) { arg = get_register_var(0); arg_assign = list2( - assign_expr0(get_input_register_var(reg_arg,0,0),arg,t,t), + assign_expr0(get_input_register_var(reg_arg,0,0), + arg,t,t), arg_assign); } else { arg = get_input_register_var(reg_arg,0,0); @@ -1373,35 +1414,37 @@ nargs ++ ; reg_arg++; continue; } else if (t==DOUBLE||t==FLOAT) { - if (dots && reg_arg<MAX_INPUT_REGISTER_VAR) { + if (reg_arg<MAX_INPUT_REGISTER_VAR) { /* sigh... printf requies floating value in integer registers */ - if (car(e4)==DRLVAR) { - special_lvar = cadr(e4); - e5 = list2(LVAR,special_lvar); - } else { - special_lvar = new_lvar(size_of_double); - g_expr(assign_expr0( - (e5=list2(LVAR,special_lvar)),e4,DOUBLE,t)); - reg_arg_list = list2(e5,reg_arg_list); - e4 = list2(DREGISTER,freg); - /* freg should not change until XXX */ + if (dots) { + if (car(e4)==DRLVAR) { + special_lvar = cadr(e4); + e5 = list2(LVAR,special_lvar); + } else { + special_lvar = new_lvar(size_of_double); + g_expr(assign_expr0( + (e5=list2(LVAR,special_lvar)),e4,DOUBLE,t)); + reg_arg_list = list2(e5,reg_arg_list); + e4 = list2(DREGISTER,freg); + /* freg should not change until XXX */ + } + r0=get_input_register_var(reg_arg,0,0); + r1 = reg_arg+1+MIN_TMP_REG; + if (regs[r1]==PTRC_REG) clear_ptr_cache_reg(r1); + /* else if (regs[r1]) error(-1); */ + r1=get_input_register_var_1(reg_arg+1,0,0); + + use_var(r0); /* protect from input register free */ + use_var(r1); /* protect from input register free */ + reg_arg_list = list2(r0,reg_arg_list); + reg_arg_list = list2(r1,reg_arg_list); + arg_assign = list2( assign_expr0(r0,e5,INT,INT), arg_assign); + arg_assign = list2( assign_expr0(r1, + list2(LVAR,special_lvar+size_of_int), + INT,INT), arg_assign); } - r0=get_input_register_var(reg_arg,0,0); - r1 = reg_arg+1+MIN_TMP_REG; - if (regs[r1]==PTRC_REG) clear_ptr_cache_reg(r1); - /* else if (regs[r1]) error(-1); */ - r1=get_input_register_var_1(reg_arg+1,0,0); - - use_var(r0); /* protect from input register free */ - use_var(r1); /* protect from input register free */ - reg_arg_list = list2(r0,reg_arg_list); - reg_arg_list = list2(r1,reg_arg_list); - arg_assign = list2( assign_expr0(r0,e5,INT,INT), arg_assign); - arg_assign = list2( assign_expr0(r1, - list2(LVAR,special_lvar+size_of_int), - INT,INT), arg_assign); reg_arg += 2; } if (dots && freg_arg>=4 && freg_arg<MAX_INPUT_DREGISTER_VAR) { @@ -1416,10 +1459,11 @@ } if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { arg = list2(LVAR,caller_arg_offset_v(nargs)); - } else if (!simple_args(e3)) { + } else if (!simple_args(e3) && cadr(e3)) { arg = get_fregister_var(0); arg_assign = list2( - assign_expr0(get_input_fregister_var(freg_arg,0,0),arg,t,t), + assign_expr0(get_input_fregister_var(freg_arg,0,0), + arg,t,t), arg_assign); } else { arg = get_input_fregister_var(freg_arg,0,0); @@ -2290,8 +2334,8 @@ return *j; } -static -void code_dconst1(int e2,int freg,int db) +static void +code_dconst1(int e2,int freg,int db) { int lb; double d = dcadr(e2);
--- a/mc-code.h Sun May 04 15:10:41 2003 +0900 +++ b/mc-code.h Sun May 04 22:08:20 2003 +0900 @@ -23,6 +23,7 @@ extern int register_var(int r); extern int get_register_var(NMTBL *n); extern int get_fregister_var(NMTBL *n); +extern int get_dregister_var(NMTBL *n); extern int get_input_register_var(int,NMTBL *,int); extern int get_input_fregister_var(int,NMTBL *,int); extern void emit_push(); @@ -126,7 +127,7 @@ extern void code_dpostinc(int e1,int e2,int d,int reg); extern void code_dassop(int op,int d); -extern void code_arg_register(); +extern void code_arg_register(NMTBL *fnptr); extern int get_register(void); extern int get_fregister(void);
--- a/mc-codegen.c Sun May 04 15:10:41 2003 +0900 +++ b/mc-codegen.c Sun May 04 22:08:20 2003 +0900 @@ -43,6 +43,12 @@ code_init(); } +void +arg_register(NMTBL *fnptr) +{ + code_arg_register(fnptr); +} + int gexpr(int e1,int use0) { @@ -103,6 +109,9 @@ case DREGISTER: code_fregister(e2,freg); return DOUBLE; + case FREGISTER: + code_fregister(e2,freg); + return FLOAT; case RLVAR: code_rlvar(e2,creg); return INT; @@ -495,45 +504,6 @@ } -void -arg_register(NMTBL *fnptr) -{ - int args = fnptr->dsp; - NMTBL *n; - int reg_var = 0; - int freg_var = 0; - int type; - int reg; - int is_code0 = is_code(fnptr); - - while (args) { - /* process in reverse order */ - n = (NMTBL*)caddr(args); - type = n->ty; - if (scalar(type)) { - if ((reg = get_input_register_var(reg_var,n,is_code0))) { - n->sc = REGISTER; - n->dsp = cadr(reg); - regv[n->dsp]= 1; - regs[n->dsp]= INPUT_REG; - reg_var++; - cadddr(args)=size_of_int; /* why we need this? */ - } - } else if (type==FLOAT||type==DOUBLE) { - if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { - n->sc = DREGISTER; - n->dsp = cadr(reg); - fregv[n->dsp]= 1; - fregs[n->dsp]= INPUT_REG; - freg_var++; - cadddr(args)=size(type); /* why we need this? */ - } - } - args = cadr(args); - } - code_arg_register(); -} - static int register_to_lvar(int e) {
--- a/mc-codegen.h Sun May 04 15:10:41 2003 +0900 +++ b/mc-codegen.h Sun May 04 22:08:20 2003 +0900 @@ -29,6 +29,9 @@ extern int get_register_var(NMTBL *); extern int get_fregister_var(NMTBL *); +extern int get_dregister_var(NMTBL *); + +extern void arg_register(NMTBL *fnptr); /* function provided by mc-codegen.c */ @@ -36,7 +39,7 @@ extern void def_label(int cslabel, int dlabel); extern int backdef(void); -extern int free_register_count(void); +extern int free_register_count(int); extern int fwdlabel(void); extern void b_expr(int e1, char cond, int l1,int err); extern void bexpr(int e1, char cond, int l1); @@ -73,7 +76,6 @@ extern void closing(); extern void ret(void); extern void creg_destroy(); -extern void arg_register(NMTBL *fnptr); extern int contains(int e,int type); extern int contains_in_list(int e,int type);
--- a/mc-parse.c Sun May 04 15:10:41 2003 +0900 +++ b/mc-parse.c Sun May 04 22:08:20 2003 +0900 @@ -696,7 +696,9 @@ { if(t==CHAR) return 1; if(t==VOID) return 0; - if(t==REGISTER) return size_of_int; /* could be float? */ + if(t==REGISTER) return size_of_int; + if(t==DREGISTER) return size_of_double; + if(t==FREGISTER) return size_of_float; if(scalar(t)) return size_of_int; if(t==FLOAT) return size_of_float; if(t==DOUBLE) return size_of_double; @@ -877,8 +879,10 @@ if (stmode==REGISTER) { if(scalar(type)) { ndsp = get_register_var(n); - } else if (type==FLOAT||type==DOUBLE) { + } else if (type==FLOAT) { ndsp = get_fregister_var(n); + } else if (type==DOUBLE) { + ndsp = get_dregister_var(n); } else error(DCERR); nsc = car(ndsp); ndsp = cadr(ndsp); @@ -2144,7 +2148,8 @@ case INDIRECT: e=cadr(e); break; - case DREGISTER: + case DREGISTER: /* should be error? */ + case FREGISTER: case REGISTER: case GVAR: case LVAR: @@ -2277,12 +2282,9 @@ getsym(); break; case DREGISTER: - e1=list3(DREGISTER,nptr->dsp,(int)nptr); - type=nptr->ty; - getsym(); - break; + case FREGISTER: case REGISTER: - e1=list3(REGISTER,nptr->dsp,(int)nptr); + e1=list3(nptr->sc,nptr->dsp,(int)nptr); type=nptr->ty; getsym(); break;