Mercurial > hg > CbC > old > device
changeset 289:55e611476cba
*** empty log message ***
author | kono |
---|---|
date | Thu, 03 Jun 2004 20:41:36 +0900 |
parents | ce7b4d90bc24 |
children | 4598e751af55 |
files | Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c |
diffstat | 5 files changed, 135 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Jun 03 13:15:05 2004 +0900 +++ b/Changes Thu Jun 03 20:41:36 2004 +0900 @@ -4599,3 +4599,10 @@ かな。 あーあ、なんか恥ずかしいミスが残っているね。 + +Thu Jun 3 13:16:33 JST 2004 + +code_bool はできたんだけど、まぁ、自己満足だよね。 + +code_bool で !use の時に、null branchが残っちゃうけど... +ま、仕方がないか。
--- a/mc-code-ia32.c Thu Jun 03 13:15:05 2004 +0900 +++ b/mc-code-ia32.c Thu Jun 03 20:41:36 2004 +0900 @@ -819,14 +819,18 @@ char *xrn; int e2,e3; b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ - use_int(reg); - xrn = register_name(reg,0); - printf("\txorl %s,%s\n",xrn,xrn); - jmp(e3=fwdlabel()); - fwddef(e2); - printf("\tmovl $1,%s\n",xrn); - fwddef(e3); - regv[reg]=1; + if (use) { + use_int(reg); + xrn = register_name(reg,0); + printf("\txorl %s,%s\n",xrn,xrn); + jmp(e3=fwdlabel()); + fwddef(e2); + printf("\tmovl $1,%s\n",xrn); + fwddef(e3); + regv[reg]=1; + } else { + fwddef(e2); + } } char *
--- a/mc-code-mips.c Thu Jun 03 13:15:05 2004 +0900 +++ b/mc-code-mips.c Thu Jun 03 20:41:36 2004 +0900 @@ -1325,18 +1325,25 @@ #endif } +static int rexpr_bool(int e1, int reg); + void code_bool(int e1,int reg) { char *xrn; int e2,e3; + if (rexpr_bool(e1, reg)) return; b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ - use_int(reg); - xrn = register_name(reg); - printf("\tli %s,0\n",xrn); - jmp(e3=fwdlabel()); - fwddef(e2); - printf("\tli %s,1\n",xrn); - fwddef(e3); + if (use) { + use_int(reg); + xrn = register_name(reg); + printf("\tli %s,0\n",xrn); + jmp(e3=fwdlabel()); + fwddef(e2); + printf("\tli %s,1\n",xrn); + fwddef(e3); + } else { + fwddef(e2); + } } char * @@ -2720,14 +2727,21 @@ // should have pcond_const +#define COND_BRANCH 1 +#define COND_VALUE 2 + static void -pcond(int op, int r2,int r1,int r0,int cond,int l1) +pcond(int op, int r2,int r1,int r0,int cond,int l1,int mode) { char *slt = "slt"; char *sltu = "sltu"; char *eq = "eq"; char *ne = "ne"; int t; + char *rn2 = register_name(r2); + char *rn1 = register_name(r1); + char *rn0 = register_name(r0); + // printf("# pcond %d cond %d\n",op,cond); switch(op+(!cond)*BNOT) { case GT: case LE+BNOT: @@ -2756,18 +2770,49 @@ default: error(-1); } - if (op==EQ||op==NEQ) { - printf("\tb%s\t%s,%s,$L_%d\n",eq, - register_name(r0), - register_name(r1), - l1); - } else { - printf("\t%s\t%s,%s,%s\n",slt, - register_name(r2), - register_name(r1), - register_name(r0)); - printf("\tb%s %s,$0,$L_%d\n",eq,register_name(r2),l1); - } + if (mode==COND_BRANCH) { + if (op==EQ||op==NEQ) { + printf("\tb%s\t%s,%s,$L_%d\n",eq,rn0,rn1, l1); + } else { + printf("\t%s\t%s,%s,%s\n",slt,rn2,rn1,rn0); + printf("\tb%s %s,$0,$L_%d\n",eq,rn2,l1); + } + } else if (mode==COND_VALUE) { + if (op==EQ) { + printf("\txor\t%s,%s,%s\n",rn2,rn1,rn0); + printf("\tsltu\t%s,%s,1\n",rn2,rn2); + } else if (op==NEQ) { + printf("\txor\t%s,%s,%s\n",rn2,rn1,rn0); + printf("\tsltu\t%s,$0,%s\n",rn2,rn2); + } else { + printf("\t%s\t%s,%s,%s\n",slt,rn2,rn1,rn0); + } + if (eq==ne) { + printf("\txor\t%s,%s,1\n",rn2,rn2); + } + } else error(-1); +} + +int +rexpr_bool(int e1, int reg) +{ + int e2,reg0; + int op = car(e1); +return 0; + if (!( + op== GT || op== LT || op== UGT || op== ULT || + op== ULE || op== UGE || op== LE || op== GE || + op== EQ || op== NEQ + )) return 0; + g_expr(cadr(e1)); + emit_push(); + g_expr(caddr(e1)); + e2 = emit_pop(1); + reg0 = ireg; + use_int(reg); + pcond(op, reg,e2,reg0,1,0,COND_VALUE); + emit_pop_free(e2); + return 1; } void @@ -2780,7 +2825,7 @@ emit_push(); g_expr(caddr(e1)); e2 = emit_pop(1); - pcond(op, e2,e2,ireg,cond,l1); + pcond(op, e2,e2,ireg,cond,l1,COND_BRANCH); emit_pop_free(e2); } @@ -4184,23 +4229,23 @@ e3h = regv_h(e3); e3l = regv_l(e3); switch(op) { case LOP+GT: case LOP+GE: - pcond(GT, cr0,e3h,regh,1,cond?l1:l2); - pcond(NEQ, cr0,e3h,regh,1,cond?l2:l1); + pcond(GT, cr0,e3h,regh,1,cond?l1:l2,COND_BRANCH); + pcond(NEQ, cr0,e3h,regh,1,cond?l2:l1,COND_BRANCH); break; case LOP+UGT: case LOP+UGE: - pcond(UGT, cr0,e3h,regh,1,cond?l1:l2); - pcond(NEQ, cr0,e3h,regh,1,cond?l2:l1); + pcond(UGT, cr0,e3h,regh,1,cond?l1:l2,COND_BRANCH); + pcond(NEQ, cr0,e3h,regh,1,cond?l2:l1,COND_BRANCH); break; case LOP+EQ: - pcond(EQ, cr0,regh,e3h,0,cond?l2:l1); + pcond(EQ, cr0,regh,e3h,0,cond?l2:l1,COND_BRANCH); break; case LOP+NEQ: - pcond(EQ, cr0,regh,e3h,0,cond?l1:l2); + pcond(EQ, cr0,regh,e3h,0,cond?l1:l2,COND_BRANCH); break; default: error(-1); } - pcond(op%LOP,cr0,e3l,regl,cond,l1); + pcond(op%LOP,cr0,e3l,regl,cond,l1,COND_BRANCH); fwddef(l2); if (cr0!=-1) free_register(cr0); emit_lpop_free(e3);
--- a/mc-code-powerpc.c Thu Jun 03 13:15:05 2004 +0900 +++ b/mc-code-powerpc.c Thu Jun 03 20:41:36 2004 +0900 @@ -1329,13 +1329,17 @@ #endif b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ - use_int(reg); - xrn = register_name(reg); - printf("\tli %s,0\n",xrn); - jmp(e3=fwdlabel()); - fwddef(e2); - printf("\tli %s,1\n",xrn); - fwddef(e3); + if (use) { + use_int(reg); + xrn = register_name(reg); + printf("\tli %s,0\n",xrn); + jmp(e3=fwdlabel()); + fwddef(e2); + printf("\tli %s,1\n",xrn); + fwddef(e3); + } else { + fwddef(e2); + } } char * @@ -2572,19 +2576,22 @@ 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; + case NEQ: t=INT; flag = 3; neg=3; break; default: return 0; } g_expr(list3((t==INT?CMP:UCMP),cadr(e1),caddr(e1))); use_int(reg); rn = register_name(reg); + t = CRBITSIZ*cmpflag; if (eq>0) { - printf("\tcror %d,%d,%d\n",CRBITSIZ*cmpflag+flag-1, - CRBITSIZ*cmpflag+eq-1,CRBITSIZ*cmpflag+flag-1); + printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); + } + if (neg>0) { + neg = t+neg-1, + printf("\tcrnor %d,%d,%d\n",neg,neg,neg); } printf("\tmfcr %s\n",rn); - printf("\trlwinm %s,%s,%d,1\n",rn,rn,CRBITSIZ*cmpflag+flag); - if (neg>0) code_lnot(reg); + printf("\trlwinm %s,%s,%d,1\n",rn,rn,t+flag); return 1; } @@ -3602,7 +3609,7 @@ static int drexpr_bool(int e1,int reg) { - int flag=-1,eq=-1,neg=-1; + int flag=-1,eq=-1,neg=-1,t; char *rn; switch(car(e1)) { case DOP+GT: case FOP+GT: flag = 2; break; @@ -3610,19 +3617,22 @@ 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; + case DOP+NEQ: case FOP+NEQ: flag = 3; neg=3; break; default: return 0; } g_expr(list3(DCMP,cadr(e1),caddr(e1))); use_int(reg); rn = register_name(reg); + t = CRBITSIZ*cmpflag; if (eq>0) { - printf("\tcror %d,%d,%d\n",CRBITSIZ*cmpflag+flag-1, - CRBITSIZ*cmpflag+eq-1,CRBITSIZ*cmpflag+flag-1); + printf("\tcror %d,%d,%d\n",t+flag-1,t+eq-1,t+flag-1); + } + if (neg>0) { + neg = t+neg-1, + printf("\tcrnor %d,%d,%d\n",neg,neg,neg); } printf("\tmfcr %s\n",rn); - printf("\trlwinm %s,%s,%d,1\n",rn,rn,CRBITSIZ*cmpflag+flag); - if (neg>0) code_lnot(reg); + printf("\trlwinm %s,%s,%d,1\n",rn,rn,t+flag); return 1; }
--- a/mc-codegen.c Thu Jun 03 13:15:05 2004 +0900 +++ b/mc-codegen.c Thu Jun 03 20:41:36 2004 +0900 @@ -18,6 +18,7 @@ static void assop(int e1); static int g_expr0(int e1); static int register_to_lvar(int e); +static void bexpr_u(int e1, char cond, int l1); #if FLOAT_CODE @@ -469,7 +470,7 @@ } void -bexpr(int e1, char cond, int l1) +bexpr_u(int e1, char cond, int l1) { int op = car(e1); if (chk) return; @@ -481,6 +482,14 @@ } void +bexpr(int e1, char cond, int l1) +{ + int uses = use; use=1; + bexpr_u(e1, cond, l1); + use = uses; +} + +void b_expr(int e1, char cond, int l1,int err) { int e2,l2,t; @@ -533,13 +542,13 @@ return; #endif case LAND: - b_expr(e2,0,cond?(l2=fwdlabel()):l1,0); - b_expr(caddr(e1),cond,l1,0); + bexpr(e2,0,cond?(l2=fwdlabel()):l1); + bexpr_u(caddr(e1),cond,l1); if(cond) fwddef(l2); return; case LOR: - b_expr(e2,1,cond?l1:(l2=fwdlabel()),0); - b_expr(caddr(e1),cond,l1,0); + bexpr(e2,1,cond?l1:(l2=fwdlabel())); + bexpr_u(caddr(e1),cond,l1); if(!cond) fwddef(l2); return; case CRGVAR: case CURGVAR: @@ -609,6 +618,7 @@ error(-1); return; /* recursive g_expr/b_expr */ } t=g_expr(e1); + if (!use) return; if (0) ; #if FLOAT_CODE else if(t==FLOAT)