Mercurial > hg > CbC > old > device
diff mc-codegen.c @ 138:e6e77af048a1 float-double
float/dobule configuration
author | kono |
---|---|
date | Tue, 06 May 2003 02:31:46 +0900 |
parents | 9fb09db54436 |
children | 742224f4da02 |
line wrap: on
line diff
--- 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: