Mercurial > hg > CbC > old > device
changeset 87:1738f313f98b floating-point
floating point (at most) done.
author | kono |
---|---|
date | Wed, 05 Mar 2003 21:07:20 +0900 |
parents | 4d1275f8a5b5 |
children | 5c8553d7f984 |
files | .gdbinit Changes mc-code-ia32.c mc-parse.c test/float.c |
diffstat | 5 files changed, 114 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Wed Mar 05 16:17:44 2003 +0900 +++ b/.gdbinit Wed Mar 05 21:07:20 2003 +0900 @@ -13,4 +13,4 @@ x/1i $eip end b errmsg -r -s test/float.c +r -s test/tmp7.c
--- a/Changes Wed Mar 05 16:17:44 2003 +0900 +++ b/Changes Wed Mar 05 21:07:20 2003 +0900 @@ -1892,6 +1892,8 @@ 関数の引数はdoubleにしないとだめなのね。プロトタイプが ある時は、その限りでない。(うーむ...) + (くそ、こいつの副作用が結構出るな...) + あと、fpp のスタックに頼っているので、overflowした時に 困らないか? ほとんどの場合でだいじょうぶだが、だめだった 時にerrorぐらい出せば? でも実行時にしかわからないか... @@ -1899,3 +1901,15 @@ I2D でさ、singned/unsigned の区別がいるね。 やっぱり FCONST いるんじゃないの? + +Wed Mar 5 19:51:59 JST 2003 + +副作用以外は終ったけど.... あと、name space が結構重なっている +んだよね。 + struct tag, struct field +が重なっているのは結構うっとうしい。gsearc/lsearch のあたりも +書き直さないとだめかも。 + +あと、list もなぁ。mode の作り方にもよるんでしょうけど。 + +あと、結構、汚いよな...
--- a/mc-code-ia32.c Wed Mar 05 16:17:44 2003 +0900 +++ b/mc-code-ia32.c Wed Mar 05 21:07:20 2003 +0900 @@ -722,13 +722,8 @@ continue; } else if (t==FLOAT) { g_expr(e4); -#if 0 printf("\tleal\t-4(%%esp),%%esp\n\tfstps\t(%%esp)\n"); nargs += size_of_float/size_of_int; -#else - printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n"); - nargs += size_of_double/size_of_int; -#endif fregv[freg]=0; continue; } else if (car(t)==STRUCT||car(t)==UNION) { @@ -1498,7 +1493,7 @@ g_expr(e2); printf("\t%s (%s)\n",fload(d),register_name(creg,0)); printf("\tfld1\n"); - if (cadr(e1)>0) + if (caddr(e1)>0) printf("\tfaddp %%st,%%st(1)\n"); else printf("\tfsubrp %%st,%%st(1)\n"); @@ -1512,11 +1507,11 @@ if (use) printf("\t%s (%s)\n",fload(d),register_name(creg,0)); printf("\tfld1\n"); - if (cadr(e1)>0) + if (caddr(e1)>0) printf("\tfaddp %%st,%%st(1)\n"); else printf("\tfsubrp %%st,%%st(1)\n"); - printf("\t%s (%s)\n",fstore(d),register_name(creg,0)); + printf("\t%s (%s)\n",(use?fstore_u(d):fstore(d)),register_name(creg,0)); } void
--- a/mc-parse.c Wed Mar 05 16:17:44 2003 +0900 +++ b/mc-parse.c Wed Mar 05 21:07:20 2003 +0900 @@ -54,7 +54,7 @@ static int typeid(int s); static int typename(void); static int typespec(void); -static void adecl(NMTBL *n); +static int adecl(NMTBL *n); static void code_decl(NMTBL *n); static void compatible(int t1, int t2); static void copy(NMTBL *nptr, char *s); @@ -555,26 +555,30 @@ getsym(); n->dsp=0; if (type==CODE) { - n->sc=CODE; + n->ty=CODE; n->sc=EMPTY; if(sym==RPAR) { - getsym(); + getsym();t=0; } else { stmode=REGISTER; - adecl(n); + t=adecl(n); stmode=0; } - type=list3(CODE,CODE,n->dsp); + type=list3(CODE,CODE,t); } else { - n->sc=FUNCTION; n->ty=type; n->sc=EMPTY; if(sym==RPAR) { - getsym(); + getsym();t=0; } else - adecl(n); - type=list3(FUNCTION,type,n->dsp); + t=adecl(n); + type=list3(FUNCTION,type,t); } + /* in GDECL mode dsp contains real parameter, if not, + it contains arg type list. Real parameter list is compatible + with arg type list. See def/ADECL */ + if (mode!=GDECL) + n->dsp=t; } else return n; } @@ -582,12 +586,13 @@ } -static void +static int adecl(NMTBL *n) { NMTBL *arg,*sfnptr; int sreg_var,t; int stype,smode,sd,sargs; + int argtypes; stype=type; sfnptr=fnptr; @@ -596,6 +601,7 @@ sdecl_f = 0; sreg_var=reg_var; reg_var=0; + argtypes = 0; smode = mode; mode=ADECL; args = 0; @@ -608,7 +614,7 @@ if(sym==RPAR) break; } else { if(sym==DOTS) { - n->dsp=list2(DOTS,n->dsp); + argtypes=list2(DOTS,argtypes); getsym(); break; } @@ -626,14 +632,15 @@ if (arg != &null_nptr) { if (smode==GDECL) def(arg); - } else - n->dsp=list2(type,n->dsp); + } + argtypes=list2(type,argtypes); } if(sym==RPAR) break; } if (sym!=COMMA) error(DCERR); getsym(); } + argtypes=reverse0(argtypes); n->dsp=reverse0(n->dsp); checksym(RPAR); mode=smode; @@ -641,7 +648,7 @@ fnptr=sfnptr; type=stype; sdecl_f = sd; - return; + return argtypes; } static void @@ -2565,16 +2572,34 @@ return e; } if(!integral(t1)||!integral(t2)) error(TYERR); - if(t1==INT) type=t2;else type=t1; + if(t1==INT) type=t2; else type=t1; if((op==MUL||op==DIV)&&car(e2)==CONST&&cadr(e2)==1) return e1; if(op==BOR||op==EOR||op==BAND) return(list3(op,e1,e2)); return(list3(type==UNSIGNED?op+US:op,e1,e2)); } +int +function_args(int e,int t) +{ + int t1; + e = rvalue(e); + if (type==FLOAT && t==DOTS) { type=DOUBLE;} + if (type==CHAR && t==DOTS) { type=INT;} + if (t==DOTS) return e; + if (t==UNSIGNED) e = unsigned_value(e,type); + else if (integral(t)) e = int_value(e,type); + else if (t==FLOAT||t==DOUBLE) e = float_value(e,type); + else if ((t1=car(t))==STRUCT||t1==UNION) { + if(size(t)!=size(type)) error(TYERR); + } + type = t; + return e; +} + static int expr15(int e1) { - int t,arglist,e,sz; + int t,arglist,e,sz,argtypes,at; /* function call */ if(car(type)==POINTER) { @@ -2583,15 +2608,25 @@ type=cadr(type); } } - t=type; - if(integral(t)|| ((car(t)!=FUNCTION)&&(car(t)!=CODE))) { + if(integral(type)|| ((car(type)!=FUNCTION)&&(car(type)!=CODE))) { error(TYERR); } conv->funcall_(type); getsym(); + argtypes = caddr(type); + if (!integral(t=cadr(type))&&(car(t)==STRUCT||car(t)==UNION)) { + /* skip return struct pointer */ + if (argtypes==0) error(-1); + argtypes = cadr(argtypes); + } + t=type; arglist=0; while(sym!=RPAR) { e=rvalue(expr1()); + if(argtypes==0) at=DOTS; + else if(car(argtypes)==DOTS) at=DOTS; + else { at=car(argtypes); argtypes=cadr(argtypes); } + e = function_args(e,at); arglist=list3(e,arglist,type); if(sym!=COMMA) break; conv->comma_(); @@ -3617,7 +3652,7 @@ switch (mode) { case GDECL: case GSDECL: case GUDECL: case GTDECL: - case MDECL: case ADECL: + case MDECL: case ADECL: case LSDECL: case LUDECL: e=gfree; gfree+=n; break;
--- a/test/float.c Wed Mar 05 16:17:44 2003 +0900 +++ b/test/float.c Wed Mar 05 21:07:20 2003 +0900 @@ -82,13 +82,13 @@ double testd(double i,double j) { - return i+1.1+.0e3+12.3e-12; + return j+1.1+.0e3+12.3e-12; } float testf(float i,float j) { - return i+1; + return j+1; } void @@ -104,6 +104,7 @@ double *pg1; int n = 1; + printf("simple double "); f = 1.3; g = 1.0; @@ -121,6 +122,7 @@ printf("%d:%g\t",n++,g); printf("\n"); + printf("simple float "); f = f+f; printf("%d:%g\t",n++,f); f1 = f*f; @@ -133,25 +135,37 @@ printf("%d:%g\t",n++,f); printf("\n"); + printf("post/pre increment "); g1 = g; - g1 = g1++ - ++g; - printf("%d:%g\t",n++,g1); + printf("%d:%g\t",n++,g1++ - ++g); f1 = f; - f1 = f1++ - ++f; - printf("%d:%g\t",n++,f1); + printf("%d:%g\t",n++,f1++ - ++f); + + g1 = g; + printf("%d:%g\t",n++,g1-- - --g); + + f1 = f; + printf("%d:%g\t",n++,f1-- - --f); + + printf("\n"); + printf("simple calc "); + + f=0.13; g=-0.56; f1=-0.13; g1=0.56; g = f+f; printf("%d:%g\t",n++,g); f = g*g; printf("%d:%g\t",n++,f); - f = testf(f,f1); - printf("%d:%g\t",n++,f); - g = g*g+f*f-g1*g1; printf("%d:%g\t",n++,g); printf("\n"); + printf("float argument "); + f = testf(f,f1); + printf("%d:%g\t",n++,f); + + printf("\nindirect "); n=1; f = 1.3; pf=&f; pf1=&f1; @@ -182,26 +196,37 @@ printf("%d:%g\t",n++,*pf); printf("\n"); + printf("indirect post/pre "); *pg1 = *pg; - *pg1 = (*pg1)++ - ++(*pg); - printf("%d:%g\t",n++,*pg1); + printf("%d:%g\t",n++,(*pg1)++ - ++(*pg)); *pf1 = *pf; - *pf1 = (*pf1)++ - ++(*pf); - printf("%d:%g\t",n++,*pf1); + printf("%d:%g\t",n++,(*pf1)++ - ++(*pf)); + + *pg1 = *pg; + printf("%d:%g\t",n++, (*pg1)-- - --(*pg)); + *pf1 = *pf; + printf("%d:%g\t",n++, (*pf1)-- - --(*pf)); + printf("\n"); + + *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56; *pg = *pf+*pf; printf("%d:%g\t",n++,*pg); *pf = *pg**pg; printf("%d:%g\t",n++,*pf); - *pf = testf(*pf,*pf1); - printf("%d:%g\t",n++,*pf); - *pg = *pg**pg+*pf**pf-*pg1**pg1; printf("%d:%g\t",n++,*pg); printf("\n"); + printf("float argument "); + + *pf = testf(*pf,*pf1); + printf("%d:%g\t",n++,*pf); + + + printf("\nassop "); n=1; f = 1.3; g = 1.0; @@ -229,6 +254,7 @@ f = 1.3; g = 1.0; + printf("indirect assop "); *pg *= 2**pg; printf("%d:%g\t",n++,*pg); *pg /= 2**pg;