Mercurial > hg > CbC > old > device
changeset 288:ce7b4d90bc24
PowerPC code bool
author | kono |
---|---|
date | Thu, 03 Jun 2004 13:15:05 +0900 |
parents | a0779a414855 |
children | 55e611476cba |
files | mc-code-powerpc.c test/code-gen.c |
diffstat | 2 files changed, 158 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-powerpc.c Wed Jun 02 14:29:30 2004 +0900 +++ b/mc-code-powerpc.c Thu Jun 03 13:15:05 2004 +0900 @@ -1300,10 +1300,34 @@ #endif } +static int rexpr_bool(int e1,int reg); + +#if FLOAT_CODE +static int drexpr_bool(int e1,int reg); +#endif + +#if LONGLONG_CODE +static int lrexpr_bool(int e1,int reg) +{ + return 0; +} +#endif + + + void code_bool(int e1,int reg) { char *xrn; int e2,e3; + + if (rexpr_bool(e1,reg)) return; +#if FLOAT_CODE + else if (drexpr_bool(e1,reg)) return; +#endif +#if LONGLONG_CODE + else if (lrexpr_bool(e1,reg)) return; +#endif + b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ use_int(reg); xrn = register_name(reg); @@ -2531,6 +2555,39 @@ printf(".text\n"); } +#define CRBITSIZ 4 + +static int +rexpr_bool(int e1,int reg) +{ + int t,flag=-1,eq=-1,neg=-1; + char *rn; + switch(car(e1)) { + case GT: t=INT; flag = 2; break; + case UGT: t=0; flag = 2; break; + case GE: t=INT; flag = 2; eq=3; break; + case UGE: t=0; flag = 2; eq=3; break; + case LT: t=INT; flag = 1; break; + case ULT: t=0; flag = 1; break; + case LE: t=INT; flag = 1; eq=3; break; + case ULE: t=0; flag = 1; eq=3; break; + case EQ: t=INT; flag = 3; break; + case NEQ: t=INT; flag = 3; neg=1; break; + default: return 0; + } + g_expr(list3((t==INT?CMP:UCMP),cadr(e1),caddr(e1))); + use_int(reg); + rn = register_name(reg); + if (eq>0) { + printf("\tcror %d,%d,%d\n",CRBITSIZ*cmpflag+flag-1, + CRBITSIZ*cmpflag+eq-1,CRBITSIZ*cmpflag+flag-1); + } + printf("\tmfcr %s\n",rn); + printf("\trlwinm %s,%s,%d,1\n",rn,rn,CRBITSIZ*cmpflag+flag); + if (neg>0) code_lnot(reg); + return 1; +} + void rexpr(int e1, int l1, int cond,int t) { @@ -2552,7 +2609,6 @@ printf("\tb%s cr%d,L_%d\n",s,cmpflag,l1); } - static void jcond(int l, char cond) { @@ -3422,12 +3478,12 @@ case DMUL: opn="fmul"; break; case FCMP: case DCMP: - printf("\tfcmpu cr7,%s,%s\n",frn,grn); + printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); if (ox!=-1) free_register(ox); return; case FCMPGE: case DCMPGE: - printf("\tfcmpu cr7,%s,%s\n",frn,grn); + printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); if (ox!=-1) free_register(ox); return; default: @@ -3543,6 +3599,33 @@ free_register(g); } +static int +drexpr_bool(int e1,int reg) +{ + int flag=-1,eq=-1,neg=-1; + char *rn; + switch(car(e1)) { + case DOP+GT: case FOP+GT: flag = 2; break; + case DOP+GE: case FOP+GE: flag = 2; eq=3; break; + case DOP+LT: case FOP+LT: flag = 1; break; + case DOP+LE: case FOP+LE: flag = 1; eq=3; break; + case DOP+EQ: case FOP+EQ: flag = 3; break; + case DOP+NEQ: case FOP+NEQ: flag = 3; neg=1; break; + default: return 0; + } + g_expr(list3(DCMP,cadr(e1),caddr(e1))); + use_int(reg); + rn = register_name(reg); + if (eq>0) { + printf("\tcror %d,%d,%d\n",CRBITSIZ*cmpflag+flag-1, + CRBITSIZ*cmpflag+eq-1,CRBITSIZ*cmpflag+flag-1); + } + printf("\tmfcr %s\n",rn); + printf("\trlwinm %s,%s,%d,1\n",rn,rn,CRBITSIZ*cmpflag+flag); + if (neg>0) code_lnot(reg); + return 1; +} + void drexpr(int e1, int e2,int l1, int op,int cond) { @@ -3566,26 +3649,19 @@ op=DOP+EQ; break; } } - // g_expr(list3( ((op==DOP+GE||op==FOP+GE)?DCMPGE:DCMP), e2,e1)); g_expr(list3(DCMP, e1,e2)); switch(op) { - case DOP+GT: - case FOP+GT: - printf("\tbgt\tcr7,L_%d\n",l1); + case DOP+GT: case FOP+GT: + printf("\tbgt\tcr%d,L_%d\n",cmpflag,l1); + break; + case DOP+GE: case FOP+GE: + printf("\tbge\tcr%d,L_%d\n",cmpflag,l1); break; - case DOP+GE: - case FOP+GE: - // printf("\tcrnor 30,29,30\n"); - // printf("\tbeq\tcr7,L_%d\n",l1); - printf("\tbge\tcr7,L_%d\n",l1); + case DOP+EQ: case FOP+EQ: + printf("\tbeq\tcr%d,L_%d\n",cmpflag,l1); break; - case DOP+EQ: - case FOP+EQ: - printf("\tbeq\tcr7,L_%d\n",l1); - break; - case DOP+NEQ: - case FOP+NEQ: - printf("\tbne\tcr7,L_%d\n",l1); + case DOP+NEQ: case FOP+NEQ: + printf("\tbne\tcr%d,L_%d\n",cmpflag,l1); break; } }
--- a/test/code-gen.c Wed Jun 02 14:29:30 2004 +0900 +++ b/test/code-gen.c Thu Jun 03 13:15:05 2004 +0900 @@ -392,18 +392,36 @@ int i1l,i2l; unsigned int ui1l,ui2l; - printf("code_bool > gvar %d %d %d %d %d %d\n", - i1>i2,ui1>ui2,i1>=i2,ui1>=ui2,ui1==ui2,i1!=i2); - printf("code_bool < gvar %d %d %d %d %d %d\n", - i1<i2,ui1<ui2,i1<=i2,ui1<=ui2,ui1==ui2,i1!=i2); - - i1l=i2l=i1; - ui1l=ui2l=ui1; - - printf("code_bool eq > lvar %d %d %d %d %d %d\n", - i1l>i2l,ui1l>ui2l,i1l>=i2l,ui1l>=ui2l,ui1l==ui2l,i1l!=i2l); - printf("code_bool eq < lvar %d %d %d %d %d %d\n", - i1l<i2l,ui1l<ui2l,i1l<=i2l,ui1l<=ui2l,ui1l==ui2l,i1l!=i2l); + ui2 = ui1-3; + for(i2=i1-3;i2<i1+3;i2++) { + printf("code_bool %d>%d gvar %d\n",i1,i2,i1>i2); + printf("code_bool %u>%u gvar %d u\n",ui1,ui2,ui1>ui2); + printf("code_bool %d>=%d gvar %d\n",i1,i2,i1>=i2); + printf("code_bool %u>=%u gvar %d u\n",ui1,ui2,ui1>=ui2); + printf("code_bool %d<%d gvar %d\n",i1,i2,i1<i2); + printf("code_bool %u<%u gvar %d u\n",ui1,ui2,ui1<ui2); + printf("code_bool %d<=%d gvar %d\n",i1,i2,i1<=i2); + printf("code_bool %u<=%u gvar %d u\n",ui1,ui2,ui1<=ui2); + printf("code_bool %u==%u gvar %d u\n",ui1,ui2,ui1==ui2); + printf("code_bool %u!=%u gvar %d\n",i1,i2,i1!=i2); + ui2++; + } + ui1l = ui1; + i1l = i1; + ui2l = ui1-3; + for(i2l=i1-3;i2l<i1l+3;i2l++) { + printf("code_bool %d>%d lvar %d\n",i1l,i2l,i1l>i2l); + printf("code_bool %u>%u lvar %d u\n",ui1l,ui2l,ui1l>ui2l); + printf("code_bool %d>=%d lvar %d\n",i1l,i2l,i1l>=i2l); + printf("code_bool %u>=%u lvar %d u\n",ui1l,ui2l,ui1l>=ui2l); + printf("code_bool %d<%d lvar %d\n",i1l,i2l,i1l<i2l); + printf("code_bool %u<%u lvar %d u\n",ui1l,ui2l,ui1l<ui2l); + printf("code_bool %d<=%d lvar %d\n",i1l,i2l,i1l<=i2l); + printf("code_bool %u<=%u lvar %d u\n",ui1l,ui2l,ui1l<=ui2l); + printf("code_bool %u==%u lvar %d u\n",ui1l,ui2l,ui1l==ui2l); + printf("code_bool %u!=%u lvar %d\n",i1l,i2l,i1l!=i2l); + ui2l++; + } } void @@ -1546,31 +1564,41 @@ void code_dbool() { - float lf0,lf1; - double ld0,ld1; - - printf("code_bool > float %d %d %d %d\n", - f0>f1,f0>=f1,f0==f1,f0!=f1); - printf("code_bool > double %d %d %d %d\n", - d0>d1,d0>=d1,d0==d1,d0!=d1); - printf("code_bool < float %d %d %d %d\n", - f0<f1,f0<=f1,f0==f1,f0!=f1); - printf("code_bool < double %d %d %d %d\n", - d0<d1,d0<=d1,d0==d1,d0!=d1); + float i1l,i2l; + double ui1l,ui2l; - lf0=lf1=f0; - ld0=ld1=d0; + d1 = d0-3; + for(f1=f0-3;f1<f0+3;f1++) { + printf("code_dbool %g>%g gvar %d\n",f0,f1,f0>f1); + printf("code_dbool %g>%g gvar %d d\n",d0,d1,d0>d1); + printf("code_dbool %g>=%g gvar %d\n",f0,f1,f0>=f1); + printf("code_dbool %g>=%g gvar %d d\n",d0,d1,d0>=d1); + printf("code_dbool %g<%g gvar %d\n",f0,f1,f0<f1); + printf("code_dbool %g<%g gvar %d d\n",d0,d1,d0<d1); + printf("code_dbool %g<=%g gvar %d\n",f0,f1,f0<=f1); + printf("code_dbool %g<=%g gvar %d d\n",d0,d1,d0<=d1); + printf("code_dbool %g==%g gvar %d d\n",d0,d1,d0==d1); + printf("code_dbool %g!=%g gvar %d\n",f0,f1,f0!=f1); + d1++; + } + ui1l = d0; + i1l = f0; + ui2l = d0-3; + for(i2l=f0-3;i2l<i1l+3;i2l++) { + printf("code_dbool %g>%g lvar %d\n",i1l,i2l,i1l>i2l); + printf("code_dbool %g>%g lvar %d d\n",ui1l,ui2l,ui1l>ui2l); + printf("code_dbool %g>=%g lvar %d\n",i1l,i2l,i1l>=i2l); + printf("code_dbool %g>=%g lvar %d d\n",ui1l,ui2l,ui1l>=ui2l); + printf("code_dbool %g<%g lvar %d\n",i1l,i2l,i1l<i2l); + printf("code_dbool %g<%g lvar %d d\n",ui1l,ui2l,ui1l<ui2l); + printf("code_dbool %g<=%g lvar %d\n",i1l,i2l,i1l<=i2l); + printf("code_dbool %g<=%g lvar %d d\n",ui1l,ui2l,ui1l<=ui2l); + printf("code_dbool %g==%g lvar %d d\n",ui1l,ui2l,ui1l==ui2l); + printf("code_dbool %g!=%g lvar %d\n",i1l,i2l,i1l!=i2l); + ui2l++; + } +} - printf("code_bool eq > float %d %d %d %d\n", - lf0>lf1,lf0>=lf1,lf0==lf1,lf0!=lf1); - printf("code_bool eq > double %d %d %d %d\n", - ld0>ld1,ld0>=ld1,ld0==ld1,ld0!=ld1); - printf("code_bool eq < float %d %d %d %d\n", - lf0<lf1,lf0<=lf1,lf0==lf1,lf0!=lf1); - printf("code_bool eq < double %d %d %d %d\n", - ld0<ld1,ld0<=ld1,ld0==ld1,ld0!=ld1); - -} #endif