Mercurial > hg > CbC > old > device
changeset 138:e6e77af048a1 float-double
float/dobule configuration
author | kono |
---|---|
date | Tue, 06 May 2003 02:31:46 +0900 |
parents | 9fb09db54436 |
children | 742224f4da02 |
files | Changes Makefile mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h mc-parse.c |
diffstat | 9 files changed, 266 insertions(+), 254 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sun May 04 22:08:20 2003 +0900 +++ b/Changes Tue May 06 02:31:46 2003 +0900 @@ -2926,3 +2926,10 @@ あとはstackに積むみたいね。 これらを get_input_register_var で処理するわけか。 + +Mon May 5 15:28:07 JST 2003 + +code_fconst/code_dconst と code_drgvar(e4,d,reg) みたいなのが +入混じってるな。ま、いいんだけど。 + +やっぱり、後者に統一。(めんどさ〜) free で d を指定するのはまずい。
--- a/Makefile Sun May 04 22:08:20 2003 +0900 +++ b/Makefile Tue May 06 02:31:46 2003 +0900 @@ -73,7 +73,7 @@ mc-code-powerpc.c clean : - -rm -f mc mc-ia32 mc-powerpc mc-mips *.bak *.s *.o *.cc mc mc1 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out + -rm -f mc mc-ia32 mc-powerpc mc-mips *.bak *.s *.o *.cc mc mc1 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i mc1 : b00.s b01.s mc-codegen.o mc-tree.o $(CONVERTER) $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o $(CONVERTER)
--- a/mc-code-ia32.c Sun May 04 22:08:20 2003 +0900 +++ b/mc-code-ia32.c Tue May 06 02:31:46 2003 +0900 @@ -32,8 +32,18 @@ int MAX_INPUT_REGISTER_VAR = 0; int MAX_CODE_INPUT_REGISTER_VAR = 2; int MAX_INPUT_DREGISTER_VAR = 0; +int MAX_INPUT_FREGISTER_VAR = 0; int MAX_CODE_INPUT_DREGISTER_VAR = 0; +int reg_sp; /* REGister Stack-Pointer */ +int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ + +/* floating point registers */ + +int freg_sp; /* floating point REGister Stack-Pointer */ +int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ + + /* -28 -8 local2 -24 -4 local1 @@ -226,19 +236,19 @@ } int -get_input_fregister_var(int i,NMTBL *nptr,int is_code) +get_input_dregister_var(int i,NMTBL *nptr,int is_code,int d) { return 0; } int -get_fregister(void) +get_dregister(int d) { return -1; } void -free_fregister(int i) { +free_dregister(int i,int d) { error(-1); } @@ -328,7 +338,7 @@ 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))) { + if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { n->sc = DREGISTER; n->dsp = cadr(reg); fregv[n->dsp]= 1; @@ -412,15 +422,9 @@ } int -get_fregister_var(NMTBL *nptr) +get_dregister_var(NMTBL *nptr,int d) { - return list2(LVAR,new_lvar(size_of_double)); -} - -int -get_dregister_var(NMTBL *nptr) -{ - return get_fregister_var(nptr); + return list2(LVAR,new_lvar(d?size_of_double:size_of_float)); } void @@ -1675,7 +1679,7 @@ printf("\t%s %d(%%ebp)\n",fstore(d),lvar(e2)); } -void code_dassign_fregister(int e,int d,int freg) +void code_dassign_dregister(int e,int d,int freg) { error(-1); } @@ -1701,21 +1705,21 @@ return (i[1] == 0x3ff00000)?j[1]:j[0]; } -void code_dconst(int e2,int freg) +void code_dconst(int e2,int freg,int d) { int lb; - double d = dcadr(e2); + double value = dcadr(e2); - if (d==0.0) { + if (value==0.0) { printf("\tfldz\n"); return; } - if (d==1.0) { + if (value==1.0) { printf("\tfld1\n"); return; } printf(" \t.section\t.rodata\n\t.align 8\n"); lb=fwdlabel(); printf("_%d:\n",lb); - printf("\t.long\t0x%x,0x%x\n",code_d1(d),code_d2(d)); + printf("\t.long\t0x%x,0x%x\n",code_d1(value),code_d2(value)); if (output_mode==TEXT_EMIT_MODE) { printf(".text\n"); } else { @@ -1724,21 +1728,11 @@ printf("\tfldl _%d\n",lb); } -void code_fconst(int e2,int freg) -{ - code_dconst(e2,freg); -} - -void code_dneg(int freg) +void code_dneg(int freg,int d) { printf("\tfchs\n"); } -void code_fneg(int freg) -{ - code_dneg(freg); -} - void code_d2i(int freg,int creg) { printf("\tlea -%d(%%esp),%%esp\n",size_of_int*2); @@ -1801,12 +1795,12 @@ printf("\t%s %d(%%ebp)\n",fload(d),lvar(e2)); } -void code_cmp_drgvar(int e2) +void code_cmp_drgvar(int e2,int d) { printf("\tfcomp %s\n",((NMTBL*)cadr(e2))->nm); } -void code_cmp_drlvar(int e2) +void code_cmp_drlvar(int e2,int d) { printf("\tfcomp %d(%%ebp)\n",lvar(e2)); } @@ -1896,13 +1890,13 @@ } void -code_fregister(int e2,int freg) +code_dregister(int e2,int freg,int d) { error(-1); } -void -code_cmp_fregister(int r) +void +code_cmp_dregister(int e2,int d) { error(-1); } @@ -1915,7 +1909,7 @@ } int -emit_dpop(int type) +emit_dpop(int d) { int xreg; if ((xreg=pop_fregister())==-1) { @@ -1930,7 +1924,7 @@ } -void emit_dpop_free(int e1) +void emit_dpop_free(int e1,int d) { }
--- a/mc-code-mips.c Sun May 04 22:08:20 2003 +0900 +++ b/mc-code-mips.c Tue May 06 02:31:46 2003 +0900 @@ -66,19 +66,27 @@ #define CREG_REGISTER MAX_TMP_REG #define FREG_FREGISTER MAX_TMP_FREG +int reg_sp; /* REGister Stack-Pointer */ +int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ + +/* floating point registers */ + +int freg_sp; /* floating point REGister Stack-Pointer */ +int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ + static int dreg; /* general temporal register */ -int powerpc_regs[REAL_MAX_REGISTER]; -int powerpc_regv[REAL_MAX_REGISTER]; +int mips_regs[REAL_MAX_REGISTER]; +int mips_regv[REAL_MAX_REGISTER]; -int *regv = powerpc_regv; -int *regs = powerpc_regs; +int *regv = mips_regv; +int *regs = mips_regs; -int powerpc_fregs[REAL_MAX_FREGISTER]; -int powerpc_fregv[REAL_MAX_FREGISTER]; +int mips_fregs[REAL_MAX_FREGISTER]; +int mips_fregv[REAL_MAX_FREGISTER]; -int *fregv = powerpc_fregv; -int *fregs = powerpc_fregs; +int *fregv = mips_fregv; +int *fregs = mips_fregs; static int max_reg_var, max_freg_var; static int cond_reg=-1,cond_freg=-1; @@ -270,7 +278,7 @@ cadddr(args)=size_of_int; /* why we need this? */ } } else if (type==FLOAT) { - if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { + if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { n->sc = DREGISTER; n->dsp = cadr(reg); fregv[n->dsp]= 1; @@ -279,7 +287,7 @@ cadddr(args)=size(type); /* why we need this? */ } } else if (type==DOUBLE) { - if ((reg = get_input_fregister_var(freg_var,n,is_code0))) { + if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) { n->sc = DREGISTER; n->dsp = cadr(reg); fregv[n->dsp]= 1; @@ -332,7 +340,7 @@ } int -get_fregister(void) +get_dregister(int d) { /* 使われていないレジスタを調べる */ int i,reg; for(i=MAX_TMP_FREG;i>MIN_TMP_FREG;i--) { @@ -362,7 +370,6 @@ error(REG_ERR); return freg; } - int pop_fregister(void) { /* レジスタから値を取り出す */ @@ -383,13 +390,13 @@ } void -free_fregister(int i) { /* いらなくなったレジスタを開放 */ +free_dregister(int i,int d) { /* いらなくなったレジスタを開放 */ if (i<0||MAX_FREGISTER<i) error(-1); fregv[i]=fregs[i]=0; } int -get_input_fregister_var(int i,NMTBL *n,int is_code) +get_input_dregister_var(int i,NMTBL *n,int is_code,int d) { if (is_code) { if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; @@ -446,7 +453,7 @@ for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0; } for(i=0;i<MAX_FREGISTER;i++) { fregs[i]=0; fregv[i]=0; } creg = get_register(); - freg = get_fregister(); + freg = get_dregister(0); set_creg(CREG_REGISTER,0); set_freg(FREG_FREGISTER,0); return; @@ -485,7 +492,8 @@ free_register(reg_stack[--reg_sp]); } if (cond_freg!=-1) { - if(car(cond_freg)==DREGISTER) free_fregister(cadr(cond_freg)); + if(car(cond_freg)==DREGISTER) free_dregister(cadr(cond_freg),1); + else if(car(cond_freg)==FREGISTER) free_dregister(cadr(cond_freg),0); cond_freg=-1; } if (cond_reg!=-1) { @@ -536,7 +544,7 @@ } int -get_fregister_var(NMTBL *n) +get_dregister_var(NMTBL *n,int d) { int i; for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { @@ -551,12 +559,6 @@ return list2(LVAR,new_lvar(size_of_double)); } -int -get_dregister_var(NMTBL *n) -{ - return get_fregister_var(n); -} - void emit_push() { @@ -1110,7 +1112,7 @@ if (reg!=freg) { if (mode) printf("\tfmove %s,%s\n",fregister_name(reg),fregister_name(freg)); - free_fregister(freg); + free_dregister(freg,1); freg = reg; fregs[freg]=1; } @@ -1166,7 +1168,9 @@ if (tag==REGISTER) { free_register(reg); } else if (tag==DREGISTER) { - free_fregister(reg); + free_dregister(reg,1); + } else if (tag==FREGISTER) { + free_dregister(reg,0); } } my_func_args = offset; @@ -1274,18 +1278,18 @@ */ arg_assign = list2( assign_expr0(list2(LVAR,caller_arg_offset_v(nargs)), - get_input_fregister_var(freg_arg,0,0),t,t), + get_input_dregister_var(freg_arg,0,0,1),t,t), arg_assign); } if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { arg = list2(LVAR,caller_arg_offset_v(nargs)); } else if (!simple_args(e3)) { - arg = get_fregister_var(0); + arg = get_dregister_var(0,1); arg_assign = list2( - assign_expr0(get_input_fregister_var(freg_arg,0,0),arg,t,t), + assign_expr0(get_input_dregister_var(freg_arg,0,0,1),arg,t,t), arg_assign); } else { - arg = get_input_fregister_var(freg_arg,0,0); + arg = get_input_dregister_var(freg_arg,0,0,1); } use_var(arg); /* protect from input register free */ reg_arg_list = list2(arg,reg_arg_list); @@ -1314,7 +1318,8 @@ } for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { arg = car(reg_arg_list); - if (car(arg)==DREGISTER) free_fregister(cadr(arg)); + if (car(arg)==DREGISTER) free_dregister(cadr(arg),1); + else if (car(arg)==FREGISTER) free_dregister(cadr(arg),0); else if (car(arg)==REGISTER) free_register(cadr(arg)); else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); } @@ -1831,7 +1836,7 @@ code_set_fixed_creg(int mode,int type) { if (type==FLOAT||type==DOUBLE) { if (cond_freg== -1) { - cond_freg = get_fregister_var(0); + cond_freg = get_dregister_var(0,1); if(car(cond_freg)!=DREGISTER) error(-1); } set_freg(cadr(cond_freg),mode); @@ -2019,22 +2024,22 @@ } void -code_cmp_fregister(int e2) +code_cmp_dregister(int e2,int d) { /* not tested.. */ char *frn,*grn; int greg; - grn = register_name(greg = get_fregister()); + grn = register_name(greg = get_dregister(d)); frn = register_name(e2); printf("\tli.s %s,%g\n",grn,0.0); printf("\tc.eq.s %s,%s\n",grn,frn); - free_fregister(greg); + free_dregister(greg,d); return; } void -code_fregister(int e2,int freg) +code_dregister(int e2,int freg,int d) { if (freg!=e2) printf("\tmov.s %s,%s\n",fregister_name(freg),fregister_name(e2)); @@ -2062,7 +2067,7 @@ } void -code_dassign_fregister(int e2,int d,int freg) { +code_dassign_dregister(int e2,int d,int freg) { if (e2!=freg) printf("\tmov.s %s,%s\n",fregister_name(e2),fregister_name(freg)); } @@ -2091,38 +2096,21 @@ return *j; } -void code_dconst1(int e2,int freg,int db) +void code_dconst(int e2,int freg,int d) { - double d = dcadr(e2); + double value = dcadr(e2); char *frn = fregister_name(freg); - printf("\tli.s %s,%g\n",frn,d); + printf("\tli.s %s,%g\n",frn,value); fregv[freg]=1; } -void code_fconst(int e2,int freg) -{ - code_dconst1(e2,freg,0); -} -void code_dconst(int e2,int freg) -{ - code_dconst1(e2,freg,1); -} - - -void code_dneg(int freg) +void code_dneg(int freg,int d) { char *frn = fregister_name(freg); printf("\tfneg %s,%s\n",frn,frn); } -void code_fneg(int freg) -{ - char *frn = fregister_name(freg); - printf("\tfneg %s,%s\n",frn,frn); -} - - void code_d2i(int freg,int creg) { char *frn = fregister_name(freg); @@ -2196,27 +2184,27 @@ fregv[freg]=1; } -void code_cmp_drgvar(int e2) +void code_cmp_drgvar(int e2,int d) { char *frn=fregister_name(freg); - int g=get_fregister(); + int g=get_dregister(d); char *grn=fregister_name(g); char *nm = ((NMTBL*)cadr(e2))->nm; printf("\t%s %s,%s\n",fload(1),grn,nm); printf("\tfcmpu cr0,%s,%s\n",frn,grn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=0; } -void code_cmp_drlvar(int e2) +void code_cmp_drlvar(int e2,int d) { char *frn=fregister_name(freg); - int g=get_fregister(); + int g=get_dregister(d); char *grn=fregister_name(g); printf("\t%s %s,",fload(1),grn); lvar(e2); printf("\tfcmpu cr0,%s,%s\n",frn,grn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=0; } @@ -2236,33 +2224,39 @@ case FMUL: case DMUL: opn="fmul"; break; case FCMP: + printf("\tfcmpu cr0,%s,%s\n",frn,grn); + free_dregister(e1,0); + return; case DCMP: printf("\tfcmpu cr0,%s,%s\n",frn,grn); - free_fregister(e1); + free_dregister(e1,1); return; case FCMPGE: + printf("\tfcmpu cr7,%s,%s\n",frn,grn); + free_dregister(e1,0); + return; case DCMPGE: printf("\tfcmpu cr7,%s,%s\n",frn,grn); - free_fregister(e1); + free_dregister(e1,1); return; default: error(-1); return; } printf("\t%s %s,%s,%s\n",opn,frn,frn,grn); - free_fregister(e1); + free_dregister(e1,1); } void code_dassop(int op,int d) { /* we have lvalue in creg, applied floating value is in freg */ char *frn=fregister_name(freg); - int xreg=emit_dpop(0); + int xreg=emit_dpop(d); char *crn=register_name(creg); printf("\t%s %s,0(%s)\n",fload(d),frn,crn); dtosop(op,xreg); printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); - emit_dpop_free(xreg); + emit_dpop_free(xreg,d); fregv[freg]=1; } @@ -2280,7 +2274,7 @@ crn=register_name(creg); frn=fregister_name(freg); drn=register_name(r); - grn=fregister_name(g=get_fregister()); + grn=fregister_name(g=get_dregister(d)); printf("\t%s %s,0(%s)\n",fload(d),frn,crn); printf("\tlfs %s,0(%s)\n",grn,drn); @@ -2289,7 +2283,7 @@ else printf("\tfsub %s,%s,%s\n",frn,frn,grn); printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=1; } @@ -2304,7 +2298,7 @@ crn=register_name(creg); frn=fregister_name(freg); - grn=fregister_name(g=get_fregister()); + grn=fregister_name(g=get_dregister(d)); printf("\t%s %s,0(%s)\n",fload(d),frn,crn); printf("\tlfs %s,0(%s)\n",grn,drn); @@ -2313,7 +2307,7 @@ else printf("\tfsub %s,%s,%s\n",grn,frn,grn); printf("\t%s %s,0(%s)\n",fstore(d),grn,crn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=1; } @@ -2342,12 +2336,12 @@ } } -int emit_dpop(int e1) +int emit_dpop(int d) { int xreg,reg; xreg=pop_fregister(); if (xreg<= -REG_LVAR_OFFSET) { - reg = get_fregister(); + reg = get_dregister(d); code_drlvar(REG_LVAR_OFFSET+xreg,1,reg); free_lvar(REG_LVAR_OFFSET+xreg); fregv[reg]=1; xreg=reg; @@ -2355,16 +2349,16 @@ return xreg; } -void emit_dpop_free(int e1) +void emit_dpop_free(int e1,int d) { - free_fregister(e1); + free_dregister(e1,d); } void emit_dpush(int d) { int new_reg; if (freg_sp>MAX_MAX) error(-1); - new_reg = get_fregister(); + new_reg = get_dregister(d); freg_stack[freg_sp++] = freg; /* push するかわりにレジスタを使う */ freg = new_reg; fregv[freg]=1;
--- a/mc-code-powerpc.c Sun May 04 22:08:20 2003 +0900 +++ b/mc-code-powerpc.c Tue May 06 02:31:46 2003 +0900 @@ -34,6 +34,13 @@ int size_of_longlong = 8; int endian = 1; +int reg_sp; /* REGister Stack-Pointer */ +int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ + +/* floating point registers */ + +int freg_sp; /* floating point REGister Stack-Pointer */ +int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ #define REG_fp 1 #define REG_sp 30 @@ -60,7 +67,9 @@ int MAX_INPUT_REGISTER_VAR = 11-MIN_TMP_REG; int MAX_CODE_INPUT_REGISTER_VAR = 11-MIN_TMP_REG; int MAX_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG; +int MAX_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG; int MAX_CODE_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG; +int MAX_CODE_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG; #define CREG_REGISTER MAX_TMP_REG #define FREG_FREGISTER MAX_TMP_FREG @@ -302,8 +311,17 @@ 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))) { + } else if (type==FLOAT) { + if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) { + 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_dregister_var(freg_var,n,is_code0,1))) { n->sc = DREGISTER; n->dsp = cadr(reg); fregv[n->dsp]= 1; @@ -365,7 +383,7 @@ } int -get_fregister(void) +get_dregister(int d) { /* 使われていないレジスタを調べる */ int i,reg; for(i=MAX_TMP_FREG;i>MIN_TMP_FREG;i--) { @@ -395,7 +413,6 @@ error(REG_ERR); return freg; } - int pop_fregister(void) { /* レジスタから値を取り出す */ @@ -416,13 +433,13 @@ } void -free_fregister(int i) { /* いらなくなったレジスタを開放 */ +free_dregister(int i,int d) { /* いらなくなったレジスタを開放 */ if (i<0||MAX_FREGISTER<i) error(-1); fregv[i]=fregs[i]=0; } int -get_input_fregister_var(int i,NMTBL *n,int is_code) +get_input_dregister_var(int i,NMTBL *n,int is_code,int d) { if (is_code) { if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0; @@ -494,7 +511,7 @@ for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0; } for(i=0;i<MAX_FREGISTER;i++) { fregs[i]=0; fregv[i]=0; } creg = get_register(); - freg = get_fregister(); + freg = get_dregister(1); set_creg(CREG_REGISTER,0); set_freg(FREG_FREGISTER,0); return; @@ -532,7 +549,8 @@ free_register(reg_stack[--reg_sp]); } if (cond_freg!=-1) { - if(car(cond_freg)==DREGISTER) free_fregister(cadr(cond_freg)); + if(car(cond_freg)==DREGISTER) free_dregister(cadr(cond_freg),1); + else if(car(cond_freg)==FREGISTER) free_dregister(cadr(cond_freg),0); cond_freg=-1; } if (cond_reg!=-1) { @@ -584,7 +602,7 @@ } int -get_fregister_var(NMTBL *n) +get_dregister_var(NMTBL *n,int d) { int i; for(i=0;i<FREG_VAR_BASE-REG_VAR_MIN;i++) { @@ -599,12 +617,6 @@ return list2(LVAR,new_lvar(size_of_double)); } -int -get_dregister_var(NMTBL *n) -{ - return get_fregister_var(n); -} - void emit_push() { @@ -1271,7 +1283,7 @@ if (reg!=freg) { if (mode) printf("\tfmr %s,%s\n",fregister_name(reg),fregister_name(freg)); - free_fregister(freg); + free_dregister(freg,1); freg = reg; fregs[freg]=1; } @@ -1327,7 +1339,9 @@ if (tag==REGISTER) { free_register(reg); } else if (tag==DREGISTER) { - free_fregister(reg); + free_dregister(reg,1); + } else if (tag==FREGISTER) { + free_dregister(reg,0); } } my_func_args = offset; @@ -1454,19 +1468,19 @@ */ arg_assign = list2( assign_expr0(list2(LVAR,caller_arg_offset_v(nargs)), - get_input_fregister_var(freg_arg,0,0),t,t), + get_input_dregister_var(freg_arg,0,0,1),t,t), arg_assign); } if (freg_arg>=MAX_INPUT_DREGISTER_VAR) { arg = list2(LVAR,caller_arg_offset_v(nargs)); } else if (!simple_args(e3) && cadr(e3)) { - arg = get_fregister_var(0); + arg = get_dregister_var(0,1); arg_assign = list2( - assign_expr0(get_input_fregister_var(freg_arg,0,0), + assign_expr0(get_input_dregister_var(freg_arg,0,0,1), arg,t,t), arg_assign); } else { - arg = get_input_fregister_var(freg_arg,0,0); + arg = get_input_dregister_var(freg_arg,0,0,1); } use_var(arg); /* protect from input register free */ reg_arg_list = list2(arg,reg_arg_list); @@ -1497,7 +1511,8 @@ } for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { arg = car(reg_arg_list); - if (car(arg)==DREGISTER) free_fregister(cadr(arg)); + if (car(arg)==DREGISTER) free_dregister(cadr(arg),1); + else if (car(arg)==FREGISTER) free_dregister(cadr(arg),0); else if (car(arg)==REGISTER) free_register(cadr(arg)); else if (car(arg)==LVAR&&cadr(arg)<0) free_lvar(cadr(arg)); } @@ -1987,7 +2002,7 @@ code_set_fixed_creg(int mode,int type) { if (type==FLOAT||type==DOUBLE) { if (cond_freg== -1) { - cond_freg = get_fregister_var(0); + cond_freg = get_dregister_var(0,1); if(car(cond_freg)!=DREGISTER) error(-1); } set_freg(cadr(cond_freg),mode); @@ -2259,23 +2274,23 @@ } void -code_cmp_fregister(int e2) +code_cmp_dregister(int e2,int d) { char *frn,*rrn,*grn; int greg,r; - grn = register_name(greg = get_fregister()); + grn = register_name(greg = get_dregister(d)); frn = register_name(e2); float_zero_lib_used=1; r = get_ptr_cache(&float_zero); rrn = register_name(r); printf("\tlfs %s,0(%s)\n",grn,rrn); printf("\tfcmpu cr0,%s,%s\n",grn,frn); - free_fregister(greg); + free_dregister(greg,d); return; } void -code_fregister(int e2,int freg) +code_dregister(int e2,int freg,int d) { if (freg!=e2) printf("\tfmr %s,%s\n",fregister_name(freg),fregister_name(e2)); @@ -2305,7 +2320,7 @@ } void -code_dassign_fregister(int e2,int d,int freg) { +code_dassign_dregister(int e2,int d,int freg) { if (e2!=freg) printf("\tfmr %s,%s\n",fregister_name(e2),fregister_name(freg)); } @@ -2334,22 +2349,22 @@ return *j; } -static void -code_dconst1(int e2,int freg,int db) +void +code_dconst(int e2,int freg,int d) { int lb; - double d = dcadr(e2); + double value = dcadr(e2); int r; char *rrn,*frn; frn = fregister_name(freg); - if (d==0.0) { + if (value==0.0) { float_zero_lib_used=1; r = get_ptr_cache(&float_zero); rrn = register_name(r); printf("\tlfs %s,0(%s)\n",frn,rrn); return; } - if (d==1.0) { + if (value==1.0) { float_one_lib_used=1; r = get_ptr_cache(&float_one); rrn = register_name(r); @@ -2360,10 +2375,10 @@ printf(" \t.data\n\t.align 3\n"); lb=fwdlabel(); printf("L_%d:\n",lb); - if (db) { - printf("\t.long\t0x%x,0x%x\n",code_d2(d),code_d1(d)); + if (d) { + printf("\t.long\t0x%x,0x%x\n",code_d2(value),code_d1(value)); } else { - printf("\t.long\t0x%x\n",code_f(d)); + printf("\t.long\t0x%x\n",code_f(value)); } if (output_mode==TEXT_EMIT_MODE) { printf(".text\n"); @@ -2372,7 +2387,7 @@ } printf("\taddis %s,r31,ha16(L_%d-L_%d)\n",rrn,lb,code_base); printf("\tla %s,lo16(L_%d-L_%d)(%s)\n",rrn,lb,code_base,rrn); - if (db) { + if (d) { printf("\tlfd %s,0(%s)\n",frn,rrn); } else { printf("\tlfs %s,0(%s)\n",frn,rrn); @@ -2381,28 +2396,13 @@ fregv[freg]=1; } -void code_fconst(int e2,int freg) -{ - code_dconst1(e2,freg,0); -} -void code_dconst(int e2,int freg) -{ - code_dconst1(e2,freg,1); -} - - -void code_dneg(int freg) +void code_dneg(int freg,int d) { char *frn = fregister_name(freg); printf("\tfneg %s,%s\n",frn,frn); } -void code_fneg(int freg) -{ - code_dneg(freg); -} - void code_d2i(int freg,int creg) { char *frn = fregister_name(freg); @@ -2573,29 +2573,29 @@ fregv[freg]=1; } -void code_cmp_drgvar(int e2) +void code_cmp_drgvar(int e2,int d) { int r; char *frn=fregister_name(freg); - int g=get_fregister(); + int g=get_dregister(d); char *grn=fregister_name(g); r = get_ptr_cache((NMTBL*)cadr(e2)); printf("\t%s %s,0(%s)\n",fload(1),grn,register_name(r)); printf("\tfcmpu cr0,%s,%s\n",frn,grn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=0; } -void code_cmp_drlvar(int e2) +void code_cmp_drlvar(int e2,int d) { char *frn=fregister_name(freg); - int g=get_fregister(); + int g=get_dregister(d); char *grn=fregister_name(g); lvar_intro(e2); printf("\t%s %s,",fload(1),grn); lvar(e2); printf("\tfcmpu cr0,%s,%s\n",frn,grn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=0; } @@ -2617,31 +2617,31 @@ case FCMP: case DCMP: printf("\tfcmpu cr0,%s,%s\n",frn,grn); - free_fregister(e1); + free_dregister(e1,1); return; case FCMPGE: case DCMPGE: printf("\tfcmpu cr7,%s,%s\n",frn,grn); - free_fregister(e1); + free_dregister(e1,1); return; default: error(-1); return; } printf("\t%s %s,%s,%s\n",opn,frn,frn,grn); - free_fregister(e1); + free_dregister(e1,1); } void code_dassop(int op,int d) { /* we have lvalue in creg, applied floating value is in freg */ char *frn=fregister_name(freg); - int xreg=emit_dpop(0); + int xreg=emit_dpop(d); char *crn=register_name(creg); printf("\t%s %s,0(%s)\n",fload(d),frn,crn); dtosop(op,xreg); printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); - emit_dpop_free(xreg); + emit_dpop_free(xreg,d); fregv[freg]=1; } @@ -2661,7 +2661,7 @@ crn=register_name(creg); frn=fregister_name(freg); drn=register_name(r); - grn=fregister_name(g=get_fregister()); + grn=fregister_name(g=get_dregister(d)); printf("\t%s %s,0(%s)\n",fload(d),frn,crn); printf("\tlfs %s,0(%s)\n",grn,drn); @@ -2670,7 +2670,7 @@ else printf("\tfsub %s,%s,%s\n",frn,frn,grn); printf("\t%s %s,0(%s)\n",fstore(d),frn,crn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=1; } @@ -2689,7 +2689,7 @@ crn=register_name(creg); frn=fregister_name(freg); drn=register_name(r); - grn=fregister_name(g=get_fregister()); + grn=fregister_name(g=get_dregister(d)); printf("\t%s %s,0(%s)\n",fload(d),frn,crn); printf("\tlfs %s,0(%s)\n",grn,drn); @@ -2698,7 +2698,7 @@ else printf("\tfsub %s,%s,%s\n",grn,frn,grn); printf("\t%s %s,0(%s)\n",fstore(d),grn,crn); - free_fregister(g); + free_dregister(g,d); fregv[freg]=1; } @@ -2727,12 +2727,12 @@ } } -int emit_dpop(int e1) +int emit_dpop(int d) { int xreg,reg; xreg=pop_fregister(); if (xreg<= -REG_LVAR_OFFSET) { - reg = get_fregister(); + reg = get_dregister(d); code_drlvar(REG_LVAR_OFFSET+xreg,1,reg); free_lvar(REG_LVAR_OFFSET+xreg); fregv[reg]=1; xreg=reg; @@ -2740,16 +2740,16 @@ return xreg; } -void emit_dpop_free(int e1) +void emit_dpop_free(int e1,int d) { - free_fregister(e1); + free_dregister(e1,1); } -void emit_dpush(int type) +void emit_dpush(int d) { int new_reg; if (freg_sp>MAX_MAX) error(-1); - new_reg = get_fregister(); + new_reg = get_dregister(1); freg_stack[freg_sp++] = freg; /* push するかわりにレジスタを使う */ freg = new_reg; fregv[freg]=1;
--- a/mc-code.h Sun May 04 22:08:20 2003 +0900 +++ b/mc-code.h Tue May 06 02:31:46 2003 +0900 @@ -14,6 +14,7 @@ extern int MAX_INPUT_REGISTER_VAR; extern int MAX_CODE_INPUT_REGISTER_VAR; extern int MAX_INPUT_DREGISTER_VAR; +extern int MAX_CODE_INPUT_FREGISTER_VAR; extern int MAX_CODE_INPUT_DREGISTER_VAR; #define REG_LVAR_OFFSET 2 @@ -22,10 +23,9 @@ extern void gexpr_code_init(void); 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_dregister_var(NMTBL *n,int d); extern int get_input_register_var(int,NMTBL *,int); -extern int get_input_fregister_var(int,NMTBL *,int); +extern int get_input_dregister_var(int,NMTBL *,int,int); extern void emit_push(); extern int emit_pop(int type); extern void gexpr_code_init(); @@ -94,22 +94,20 @@ extern int dpop_register(); extern int emit_dpop(int); -extern void code_fregister(int e2,int reg); -extern void code_cmp_fregister(int); -extern void code_cmp_drgvar(int); -extern void code_cmp_drlvar(int); +extern void code_dregister(int e2,int reg,int d); +extern void code_cmp_dregister(int,int); +extern void code_cmp_drgvar(int,int); +extern void code_cmp_drlvar(int,int); extern void code_dassign(int,int,int); extern void code_dassign_gvar(int,int,int); extern void code_dassign_lvar(int,int,int); -extern void code_dassign_fregister(int e2,int d,int reg); -extern void code_dconst(int,int); -extern void code_fconst(int,int); -extern void code_dneg(int); -extern void code_fneg(int); +extern void code_dassign_dregister(int e2,int d,int reg); +extern void code_dconst(int,int,int); +extern void code_dneg(int,int); extern void code_drgvar(int,int,int); extern void code_drlvar(int,int,int); extern void dtosop(int,int); -extern void emit_dpop_free(int); +extern void emit_dpop_free(int,int); extern void emit_dpush(int); extern void code_i2d(int,int); extern void code_d2i(int,int); @@ -130,10 +128,11 @@ extern void code_arg_register(NMTBL *fnptr); extern int get_register(void); -extern int get_fregister(void); +extern int get_dregister(int); extern void free_register(int i) ; -extern void free_fregister(int i) ; +extern void free_dregister(int i,int d) ; extern int pop_register(void); extern void emit_pop_free(int xreg); + /* */
--- a/mc-codegen.c Sun May 04 22:08:20 2003 +0900 +++ b/mc-codegen.c Tue May 06 02:31:46 2003 +0900 @@ -7,21 +7,12 @@ #include "mc-code.h" int creg; /* current register */ -int reg_sp; /* REGister Stack-Pointer */ -int reg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ - -/* floating point registers */ - int freg; /* current floating point register */ -int freg_sp; /* floating point REGister Stack-Pointer */ -int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */ int use; /* generated value will be used */ /* creg currrent virtual register - regs[] virtual register usage - regv[] value in virtual register flag freg current floating point register fregv calue in floating point register */ @@ -107,10 +98,10 @@ code_register(e2,creg); return INT; case DREGISTER: - code_fregister(e2,freg); + code_dregister(e2,freg,1); return DOUBLE; case FREGISTER: - code_fregister(e2,freg); + code_dregister(e2,freg,0); return FLOAT; case RLVAR: code_rlvar(e2,creg); @@ -137,10 +128,10 @@ code_const(e2,creg); return INT; case DCONST: - code_dconst(e1,freg); + code_dconst(e1,freg,1); return DOUBLE; case FCONST: - code_fconst(e1,freg); + code_dconst(e1,freg,0); return FLOAT; case STRING: code_string(e1,creg); @@ -157,18 +148,18 @@ case DRINDIRECT: case FRINDIRECT: return rindirect(e1); case ADDRESS: - if (car(e2)==REGISTER||car(e2)==DREGISTER) - return register_to_lvar(e2); + if (car(e2)==REGISTER||car(e2)==DREGISTER||car(e2)==FREGISTER) + return register_to_lvar(e2); /* too late? */ else return g_expr0(e2); case MINUS: /* レジスタに対し、neglを実行すれば実現可能 */ g_expr0(e2); code_neg(creg); return INT; case DMINUS: - g_expr0(e2); code_dneg(freg); + g_expr0(e2); code_dneg(freg,1); return DOUBLE; case FMINUS: - g_expr0(e2); code_fneg(freg); + g_expr0(e2); code_dneg(freg,0); return FLOAT; case CONV: g_expr0(e2); @@ -255,7 +246,7 @@ return t; case DCOND: case FCOND: - d = car(e1)==DCOND?DOUBLE:FLOAT; + d = (car(e1)==DCOND?DOUBLE:FLOAT); e2=fwdlabel(); b_expr(cadr(e1),0,e2,0); code_set_fixed_creg(0,d); @@ -454,25 +445,38 @@ jcond(l1,cond); return; case DRLVAR: - code_cmp_drlvar(e2); + code_cmp_drlvar(e2,1); + jcond(l1,cond); + return; + case FRLVAR: + code_cmp_drlvar(e2,0); jcond(l1,cond); return; case DRGVAR: - code_cmp_drgvar(e2); + code_cmp_drgvar(e2,1); + jcond(l1,cond); + return; + case FRGVAR: + code_cmp_drgvar(e2,0); jcond(l1,cond); return; case REGISTER: code_cmp_register(e2); jcond(l1,cond); return; + case FREGISTER: + code_cmp_dregister(e2,0); + jcond(l1,cond); + return; case DREGISTER: - code_cmp_fregister(e2); + code_cmp_dregister(e2,1); jcond(l1,cond); return; case CONST: if(control&&((cond&&e2)||(!cond&&!e2))) jmp(l1); return; case DCONST: + case FCONST: if(control&&((dcadr(e2)!=0.0)^cond)) jmp(l1); return; default: @@ -480,8 +484,10 @@ error(-1); return; /* recursive g_expr/b_expr */ } t=g_expr(e1); - if(t==FLOAT||t==DOUBLE) - code_cmp_fregister(freg); + if(t==FLOAT) + code_cmp_dregister(freg,0); + else if(t==DOUBLE) + code_cmp_dregister(freg,1); else code_cmp_register(creg); jcond(l1,cond); @@ -519,13 +525,14 @@ int t; if (!n||n==&null_nptr) error(REG_ERR); if (tag==REGISTER) { - /* regs[reg]==INPUT_REG case should be considered */ n->dsp = new_lvar(size_of_int); t = INT; } else if (tag==DREGISTER) { - /* fregs[reg]==INPUT_REG case should be considered */ n->dsp = new_lvar(size_of_double); t = DOUBLE; + } else if (tag==FREGISTER) { + n->dsp = new_lvar(size_of_float); + t = DOUBLE; } else error(-1); n->sc = LVAR; lvar = list2(LVAR,n->dsp); @@ -533,7 +540,9 @@ if (tag==REGISTER) { free_register(reg); } else if (tag==DREGISTER) { - free_fregister(reg); + free_dregister(reg,1); + } else if (tag==FREGISTER) { + free_dregister(reg,0); } return g_expr0(lvar); #endif @@ -578,8 +587,10 @@ if (car(use0)==t) { if (car(caddr(use0))==REGISTER) free_register(cadr(caddr(use0))); + else if (car(caddr(use0))==FREGISTER) + free_dregister(cadr(caddr(use0)),0); else if (car(caddr(use0))==DREGISTER) - free_fregister(cadr(caddr(use0))); + free_dregister(cadr(caddr(use0)),1); break; } use0 = cadr(use0); @@ -597,11 +608,16 @@ *use=list3(t,*use,e1); g_expr_u(assign_expr0(e1,s,ty,ty)); *target = append4(*target,t,ty,e1); - } else if (sz==size_of_double && (e1=get_fregister())!=-1) { + } else if (sz==size_of_double && (e1=get_dregister(1))!=-1) { e1=list3(DREGISTER,e1,0); *use=list3(t,*use,e1); g_expr_u(assign_expr0(e1,s,ty,ty)); *target = append4(*target,t,ty,e1); + } else if (sz==size_of_float && (e1=get_dregister(0))!=-1) { + e1=list3(FREGISTER,e1,0); + *use=list3(t,*use,e1); + g_expr_u(assign_expr0(e1,s,ty,ty)); + *target = append4(*target,t,ty,e1); } else { g_expr_u(assign_expr0((e1=list2(LVAR,new_lvar(sz))),s,ty,ty)); *target = append4(*target,t,ty,e1); @@ -705,6 +721,7 @@ { return ( e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||e1==DREGISTER || + e1==FREGISTER || e1==GVAR || e1==RGVAR || e1==RLVAR || e1==CRLVAR || e1==CRGVAR || e1==DRLVAR || e1==FRLVAR ); @@ -730,7 +747,7 @@ return ( ce1==LVAR ||ce1==RLVAR||ce1==CRLVAR || ce1==DRLVAR || ce1==GVAR ||ce1==RGVAR||ce1==CRGVAR || ce1==DRGVAR || - ce1==REGISTER|| ce1==DREGISTER + ce1==REGISTER|| ce1==DREGISTER || ce1==FREGISTER ); } @@ -739,7 +756,7 @@ jump(int e1, int env) { int e2,e3,e4,sz,arg_size,ty,regs,fregs; - int t0,s0; + int t0,s0,r; NMTBL *code0 = 0; int target = 0; int source = 0; @@ -752,14 +769,12 @@ fregs = 0; for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) { e2 = car(e3); sz = size(ty=caddr(e3)); - if (scalar(ty) && - regs < MAX_CODE_INPUT_REGISTER_VAR) { - target=list4(get_input_register_var(regs++,0,1), - target,ty,e2); - } else if ((ty==DOUBLE||ty==FLOAT) && - fregs < MAX_CODE_INPUT_DREGISTER_VAR) { - target=list4(get_input_fregister_var(fregs++,0,1), - target,ty,e2); + if (scalar(ty) && (r = get_input_register_var(regs,0,1))) { + target=list4(r,target,ty,e2); regs++; + } else if (ty==FLOAT && (r = get_input_dregister_var(fregs,0,1,0))) { + target=list4(r, target,ty,e2); fregs++; + } else if (ty==DOUBLE && (r = get_input_dregister_var(fregs,0,1,1))) { + target=list4(r, target,ty,e2); fregs++; } else { target=list4(list2(LVAR,0), target,ty,e2); } @@ -833,8 +848,10 @@ while (use) { if (car(caddr(use))==REGISTER) free_register(cadr(caddr(use))); + else if (car(caddr(use))==FREGISTER) + free_dregister(cadr(caddr(use)),0); else if (car(caddr(use))==DREGISTER) - free_fregister(cadr(caddr(use))); + free_dregister(cadr(caddr(use)),1); else if (car(caddr(use))==LVAR) free_lvar(cadr(caddr(use))); use=cadr(use); @@ -895,7 +912,7 @@ emit_dpush(d); g_expr(e2); dtosop(car(e1),(e2=emit_dpop(d))); - emit_dpop_free(e2); + emit_dpop_free(e2,d); fregv[freg]=1; return; } @@ -1015,7 +1032,7 @@ { int reg; /* e2=e4 */ - if (e5==DREGISTER) { + if (e5==DREGISTER||e5==FREGISTER) { reg = cadr(e4); switch(car(e2)) { case GVAR: /* i=3 */ @@ -1025,8 +1042,9 @@ code_dassign_lvar(cadr(e2),reg,d); return; case DREGISTER: + case FREGISTER: if (reg!=cadr(e2)) - code_dassign_fregister(cadr(e2),d,reg); + code_dassign_dregister(cadr(e2),d,reg); return; default: error(-1); @@ -1036,7 +1054,7 @@ return; } /* e2 is register now */ - if (car(e2)!=DREGISTER) error(-1); + if (car(e2)!=DREGISTER && car(e2)!=FREGISTER) error(-1); reg = cadr(e2); switch(e5) { case FRGVAR: @@ -1044,7 +1062,7 @@ case FRLVAR: case DRLVAR: code_drlvar(cadr(e4),d,reg); return; case FCONST: - case DCONST: code_dconst(e4,reg); return; + case DCONST: code_dconst(e4,reg,1); return; default: error(-1); } @@ -1061,7 +1079,7 @@ e4 = caddr(e1); e5=car(e4); d = (car(e1)==LASS)?2:(car(e1)==DASS)?1:0; if (!use && ( - (e5==DREGISTER) || + (e5==DREGISTER) || (e5==FREGISTER) || (car(e2)==DREGISTER&&(e5==DRGVAR||e5==DRLVAR||e5==DCONST))|| (car(e2)==DREGISTER&&(e5==FRGVAR||e5==FRLVAR||e5==FCONST)) )) { @@ -1078,9 +1096,10 @@ code_dassign_lvar(cadr(e2),freg,d); return; case DREGISTER: + case FREGISTER: g_expr(e4); if (freg!=cadr(e2)) - code_dassign_fregister(cadr(e2),d,freg); + code_dassign_dregister(cadr(e2),d,freg); return; } g_expr(e2); @@ -1275,7 +1294,7 @@ continue; /* nullary operators */ case GVAR: case RGVAR: case CRGVAR: case LVAR: - case REGISTER: case DREGISTER: + case REGISTER: case DREGISTER: case FREGISTER: case RLVAR: case CRLVAR: case FRLVAR: case FRGVAR: case DRLVAR: case DRGVAR: case FNAME: case CONST: case DCONST: case FCONST: case STRING:
--- a/mc-codegen.h Sun May 04 22:08:20 2003 +0900 +++ b/mc-codegen.h Tue May 06 02:31:46 2003 +0900 @@ -28,8 +28,7 @@ /* function provided by mc-code-*.c */ extern int get_register_var(NMTBL *); -extern int get_fregister_var(NMTBL *); -extern int get_dregister_var(NMTBL *); +extern int get_dregister_var(NMTBL *,int); extern void arg_register(NMTBL *fnptr);
--- a/mc-parse.c Sun May 04 22:08:20 2003 +0900 +++ b/mc-parse.c Tue May 06 02:31:46 2003 +0900 @@ -880,9 +880,9 @@ if(scalar(type)) { ndsp = get_register_var(n); } else if (type==FLOAT) { - ndsp = get_fregister_var(n); + ndsp = get_dregister_var(n,0); } else if (type==DOUBLE) { - ndsp = get_dregister_var(n); + ndsp = get_dregister_var(n,1); } else error(DCERR); nsc = car(ndsp); ndsp = cadr(ndsp);