Mercurial > hg > CbC > old > device
diff mc-code-ia32.c @ 291:7b6df595b205
ia32 code_bool.
author | kono |
---|---|
date | Fri, 04 Jun 2004 03:32:19 +0900 |
parents | 55e611476cba |
children | 6d4231b6f9fe |
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) {