Mercurial > hg > CbC > old > device
changeset 291:7b6df595b205
ia32 code_bool.
author | kono |
---|---|
date | Fri, 04 Jun 2004 03:32:19 +0900 |
parents | 4598e751af55 |
children | 6d4231b6f9fe |
files | mc-code-ia32.c mc-code-powerpc.c |
diffstat | 2 files changed, 99 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Thu Jun 03 21:10:46 2004 +0900 +++ b/mc-code-ia32.c Fri Jun 04 03:32:19 2004 +0900 @@ -813,11 +813,17 @@ regv[creg]=1; } +static int rexpr_bool(int e1,int reg); +static int drexpr_bool(int e1,int reg); void code_bool(int e1,int reg) { char *xrn; int e2,e3; + if (rexpr_bool(e1,reg)) return; +#if FLOAT_CODE + if (drexpr_bool(e1,reg)) return; +#endif b_expr(e1,1,e2=fwdlabel(),1); /* including > < ... */ if (use) { use_int(reg); @@ -1604,25 +1610,42 @@ printf("\t.ident \"Micro-C compiled\"\n"); } +static char * +code_cond(int op,int cond) +{ + switch(op) { + case GT: return code_gt(cond); + case UGT: return code_ugt(cond); + case GE: return code_ge(cond); + case UGE: return code_uge(cond); + case LT: return code_ge(!cond); + case ULT: return code_uge(!cond); + case LE: return code_gt(!cond); + case ULE: return code_ugt(!cond); + case EQ: return code_eq(cond); + case NEQ: return code_eq(!cond); + default: return 0; + } +} + +static int +rexpr_bool(int e1,int reg) +{ + char *s; + if (!(s=code_cond(car(e1),1))) return 0; + g_expr(list3(CMP,cadr(e1),caddr(e1))); + use_int(reg); + use_data_reg(reg,0); + printf("\tset%s\t%s\n",s,register_name(reg,1)); + printf("\tmovzbl %s,%s\n",register_name(reg,1),register_name(reg,0)); + return 1; +} + void rexpr(int e1, int l1, int cond,int t) { - char *s; - switch(car(e1)) { - case GT: s=code_gt(cond); break; - case UGT: s=code_ugt(cond); break; - case GE: s=code_ge(cond); break; - case UGE: s=code_uge(cond); break; - case LT: s=code_ge(!cond); break; - case ULT: s=code_uge(!cond);break; - case LE: s=code_gt(!cond); break; - case ULE: s=code_ugt(!cond);break; - case EQ: s=code_eq(cond); break; - case NEQ: s=code_eq(!cond); break; - default: error(-1); - } g_expr(list3(CMP,cadr(e1),caddr(e1))); - printf("\tj%s\t_%d\n",s,l1); + printf("\tj%s\t_%d\n",code_cond(car(e1),cond),l1); } @@ -2195,57 +2218,86 @@ printf("\t%s (%s)\n",(use?fstore_u(d):fstore(d)),register_name(creg,0)); } -void -drexpr(int e1, int e2,int l1, int op,int cond) +#define COND_BRANCH 1 +#define COND_VALUE 2 + +int +drexpr0(int e1, int e2,int l1, int op,int cond,int reg,int mode) { + char *s; if (!cond) { switch(op) { case FOP+GT: - drexpr(e2,e1,l1,FOP+GE,1); return; + return drexpr0(e2,e1,l1,FOP+GE,1,reg,mode); case FOP+GE: - drexpr(e2,e1,l1,FOP+GT,1); return; + return drexpr0(e2,e1,l1,FOP+GT,1,reg,mode); case FOP+EQ: op=FOP+NEQ; break; case FOP+NEQ: op=FOP+EQ; break; case DOP+GT: - drexpr(e2,e1,l1,DOP+GE,1); return; + return drexpr0(e2,e1,l1,DOP+GE,1,reg,mode); case DOP+GE: - drexpr(e2,e1,l1,DOP+GT,1); return; + return drexpr0(e2,e1,l1,DOP+GT,1,reg,mode); case DOP+EQ: op=DOP+NEQ; break; case DOP+NEQ: op=DOP+EQ; break; + default: return 0; } } - - g_expr(list3(DCMP,e1,e2)); + s = "e"; switch(op) { case DOP+GE: case FOP+GE: + g_expr(list3(DCMP,e1,e2)); printf("\ttestb\t$5,%%ah\n"); - printf("\tje\t_%d\n",l1); break; case DOP+GT: case FOP+GT: + g_expr(list3(DCMP,e1,e2)); printf("\ttestb\t$69,%%ah\n"); - printf("\tje\t_%d\n",l1); break; case DOP+EQ: case FOP+EQ: + g_expr(list3(DCMP,e1,e2)); printf("\tandb\t$69,%%ah\n"); printf("\txorb\t$64,%%ah\n"); - printf("\tje\t_%d\n",l1); break; case DOP+NEQ: case FOP+NEQ: + g_expr(list3(DCMP,e1,e2)); printf("\tandb\t$69,%%ah\n"); printf("\txorb\t$64,%%ah\n"); - printf("\tjne\t_%d\n",l1); + s = "ne"; break; + default: + return 0; } + if (mode==COND_BRANCH) { + printf("\tj%s\t_%d\n",s,l1); + } else { + use_int(reg); use_data_reg(reg,0); + printf("\tset%s\t%s\n",s,register_name(reg,1)); + printf("\tmovzbl\t%s,%s\n", + register_name(reg,1),register_name(reg,0)); + } + return 1; } +void +drexpr(int e1, int e2,int l1, int op,int cond) +{ + drexpr0(e1, e2,l1, op,cond,USE_CREG,COND_BRANCH); +} + +static int +drexpr_bool(int e1, int reg) +{ + return drexpr0(cadr(e1), caddr(e1),0, car(e1),1,reg,COND_VALUE); +} + + void code_dregister(int e2,int freg,int d) {
--- a/mc-code-powerpc.c Thu Jun 03 21:10:46 2004 +0900 +++ b/mc-code-powerpc.c Fri Jun 04 03:32:19 2004 +0900 @@ -1372,7 +1372,7 @@ static void inc_cmpflag() { - cmpflag = (cmpflag+1)%7; + cmpflag = (cmpflag+1)%8; } void @@ -1384,6 +1384,7 @@ r = get_ptr_cache((NMTBL*)cadr(e1)); printf("\t%s %s,0(%s)\n",cload(sz),crn,register_name(r)); cext(0,sz,r); + inc_cmpflag(); printf("\tcmpwi cr%d,%s,0\n",cmpflag,crn); jcond(label,cond); } @@ -1429,6 +1430,7 @@ void code_cmp_register(int e2,int label,int cond) { use_int(e2); + inc_cmpflag(); printf("\tcmpwi cr%d,%s,0\n",cmpflag,register_name(e2)); jcond(label,cond); } @@ -2413,9 +2415,11 @@ printf("\tsub %s,%s,%s\n",crn,crn,orn); break; case CMP: + inc_cmpflag(); printf("\tcmpw cr%d,%s,%s\n",cmpflag,crn,orn); break; case UCMP: + inc_cmpflag(); printf("\tcmplw cr%d,%s,%s\n",cmpflag,crn,orn); break; case BAND: @@ -2495,6 +2499,7 @@ printf("\taddi %s,%s,lo16(-%d)\n",crn,crn,v); break; case CMP: + inc_cmpflag(); printf("\tcmpwi cr%d,%s,lo16(%d)\n",cmpflag,crn,v); break; case EOR: @@ -2546,8 +2551,13 @@ { /* used in dosiwtch() */ if(chk) return; - printf("\tcmpwi cr%d,%s,%d\n",cmpflag,register_name(csreg),e); - jcond(label,cond); + inc_cmpflag(); + if (-32767<e&&e<32767) { + printf("\tcmpwi cr%d,%s,%d\n",cmpflag,register_name(csreg),e); + jcond(label,cond); + } else { + error(-1); /* !? */ + } } void @@ -3112,6 +3122,7 @@ r = get_ptr_cache(&float_zero); rrn = register_name(r); printf("\tlfs %s,0(%s)\n",grn,rrn); + inc_cmpflag(); printf("\tfcmpu cr%d,%s,%s\n",cmpflag,grn,frn); free_register(greg); jcond(label,cond); @@ -3433,6 +3444,7 @@ r = get_ptr_cache((NMTBL*)cadr(e2)); printf("\t%s %s,0(%s)\n",fload(1),grn,register_name(r)); + inc_cmpflag(); printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); free_register(g); jcond(label,cond); @@ -3450,6 +3462,7 @@ lvar_intro(e2); printf("\t%s %s,",fload(1),grn); lvar(e2); + inc_cmpflag(); printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); free_register(g); jcond(label,cond); @@ -3485,11 +3498,13 @@ case DMUL: opn="fmul"; break; case FCMP: case DCMP: + inc_cmpflag(); printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); if (ox!=-1) free_register(ox); return; case FCMPGE: case DCMPGE: + inc_cmpflag(); printf("\tfcmpu cr%d,%s,%s\n",cmpflag,frn,grn); if (ox!=-1) free_register(ox); return; @@ -3766,9 +3781,8 @@ op1 = lcmp(op,cond); tosop(op1,regv_h(e3),regv_h(reg)); cr0 = cmpflag; - inc_cmpflag(); + tosop(op1,regv_l(e3),regv_l(reg)); cr1 = cmpflag; - tosop(op1,regv_l(e3),regv_l(reg)); l2 = fwdlabel(); // cond==0 jump on false condtion ( if(x) => rexpr(.. cond=0 ...) ) @@ -3835,6 +3849,7 @@ lregister_name_low(reg), lregister_name_low(reg), lregister_name_high(reg)); + inc_cmpflag(); printf("\tcmpwi cr%d,%s,0\n",cmpflag,lregister_name_low(reg)); jcond(label,cond); }