118381Sralph #ifndef lint 2*32986Sdonn static char sccsid[] = "@(#)c21.c 4.21 12/11/87"; 318381Sralph #endif 41498Sbill /* char C21[] = {"@(#)c21.c 1.83 80/10/16 21:18:22 JFR"}; /* sccs ident */ 51496Sbill 61496Sbill /* 71496Sbill * C object code improver-- second part 81496Sbill */ 91496Sbill 101496Sbill #include "c2.h" 111496Sbill #include <stdio.h> 121496Sbill #include <ctype.h> 131496Sbill 141496Sbill #define NUSE 6 151496Sbill int ioflag; 161496Sbill int biti[NUSE] = {1,2,4,8,16,32}; 175794Sroot int bitsize[] = { /* index by type codes */ 186958Srrh 0, /* 0 not allocated */ 196958Srrh 8, /* 1 BYTE */ 206958Srrh 16, /* 2 WORD */ 216958Srrh 32, /* 3 LONG */ 22*32986Sdonn 32, /* 4 FFLOAT */ 236958Srrh 64, /* 5 DFLOAT */ 246958Srrh 64, /* 6 QUAD */ 256958Srrh 0, /* 7 OP2 */ 266958Srrh 0, /* 8 OP3 */ 276958Srrh 0, /* 9 OPB */ 286958Srrh 0, /* 10 OPX */ 296958Srrh 64, /* 11 GFLOAT */ 306958Srrh 128, /* 12 HFLOAT */ 316958Srrh 128 /* 13 OCTA */ 325794Sroot }; 331496Sbill int pos,siz; long f; /* for bit field communication */ 341496Sbill struct node *uses[NUSE]; /* for backwards flow analysis */ 351496Sbill char *lastrand; /* last operand of instruction */ 361496Sbill struct node *bflow(); 371496Sbill struct node *bicopt(); 381496Sbill char *findcon(); 3918381Sralph char *strcpy(); 401496Sbill 411496Sbill redun3(p,split) register struct node *p; int split; { 421496Sbill /* check for 3 addr instr which should be 2 addr */ 431496Sbill if (OP3==((p->subop>>4)&0xF)) { 441496Sbill if (split) splitrand(p); 451496Sbill if (equstr(regs[RT1],regs[RT3]) 461496Sbill && (p->op==ADD || p->op==MUL || p->op==BIS || p->op==XOR)) { 471496Sbill register char *t=regs[RT1]; regs[RT1]=regs[RT2]; regs[RT2]=t; 481496Sbill } 491496Sbill if (equstr(regs[RT2],regs[RT3])) { 501496Sbill p->subop=(p->subop&0xF)|(OP2<<4); p->pop=0; 511496Sbill lastrand=regs[RT2]; *regs[RT3]=0; return(1); 521496Sbill } 531496Sbill } return(0); 541496Sbill } 551496Sbill 561496Sbill bmove() { 571496Sbill register struct node *p, *lastp; register char *cp1,*cp2; register int r; 581496Sbill refcount(); 591496Sbill for (p=lastp= &first; 0!=(p=p->forw); lastp=p); 601496Sbill clearreg(); clearuse(); 611496Sbill for (p=lastp; p!= &first; p=p->back) { 621496Sbill if (debug) { 631496Sbill printf("Uses:\n"); 641496Sbill for (r=NUSE;--r>=0;) if (uses[r]) 651496Sbill printf("%d: %s\n",r,uses[r]->code? uses[r]->code:""); 661496Sbill printf("-\n"); 671496Sbill } 681496Sbill r=(p->subop>>4)&0xF; 691496Sbill if (OP2==r && (cp1=p->code, *cp1++)=='$' && *cp1++=='0' && *cp1++==',' && 701496Sbill !source(cp1)) {/* a no-op unless MUL or DIV */ 711496Sbill if (p->op==MUL) {p->op=MOV; p->subop&=0xF; p->pop=0;} 721496Sbill else if (p->op==DIV) fprintf(stderr,"c2: zero divide\n"); 731496Sbill else {delnode(p); redunm++; continue;} 741496Sbill } 751496Sbill if (OP3==r && 0!=redun3(p,1)) {newcode(p); redunm++;} 761496Sbill switch (p->op) { 771496Sbill case LABEL: case DLABEL: 781496Sbill for (r=NUSE; --r>=0;) 791496Sbill if (uses[r]) p->ref=(struct node *) (((int)p->ref)|biti[r]); 801496Sbill break; 811496Sbill case CALLS: 821496Sbill clearuse(); goto std; 831496Sbill case 0: 8417720Sralph /* 8517720Sralph * Be conservative -- if we don't know what it is, then we 8617720Sralph * assume that it can set anything. 8717720Sralph */ 8817720Sralph for ( r = 0; r < NUSE; ++r ) 8917720Sralph uses[r] = p; 9017720Sralph break; 911496Sbill case SUB: 921496Sbill if ((p->subop&0xF)!=LONG) goto std; cp1=p->code; 931496Sbill if (*cp1++!='$') goto std; splitrand(p); 941496Sbill if (equstr(regs[RT2],"fp") && !indexa(regs[RT1])) {/* address comp. */ 953933Sroot char buf[C2_ASIZE]; cp2=buf; *cp2++='-'; 961496Sbill cp1=regs[RT1]+1; while (*cp2++= *cp1++); --cp2; 971496Sbill cp1="(fp),"; while (*cp2++= *cp1++); --cp2; 981496Sbill cp1=regs[RT3]; while (*cp2++= *cp1++); 991496Sbill p->code=copy(buf); p->combop=T(MOVA,LONG); p->pop=0; 1001496Sbill } else if (*cp1++=='-' && 0<=(r=getnum(cp1))) { 1011496Sbill p->op=ADD; p->pop=0; *--cp1='$'; p->code=cp1; 1021496Sbill } goto std; 1031496Sbill case ADD: 1041496Sbill if ((p->subop&0xF)!=LONG) goto std; cp1=p->code; 1051496Sbill if (*cp1++!='$') goto std; splitrand(p); 1061496Sbill if (isstatic(cp1) && (r=isreg(regs[RT2]))>=0 && r<NUSE && uses[r]==p->forw) 1071496Sbill { 1081496Sbill /* address comp: 1091496Sbill ** addl2 $_foo,r0 \ movab _foo[r0],bar 1101496Sbill ** movl r0,bar / 1111496Sbill */ 1121496Sbill register struct node *pnext = p->forw; 1133933Sroot char buf[C2_ASIZE]; 1141496Sbill 1151496Sbill if (pnext->op == MOV && pnext->subop == LONG) 1161496Sbill { 1171496Sbill cp1 = ®s[RT1][1]; cp2 = &buf[0]; 1181496Sbill while (*cp2++ = *cp1++) ; cp2--; 1191496Sbill splitrand(pnext); 1201496Sbill if (r == isreg(regs[RT1])) 1211496Sbill { 1221496Sbill delnode(p); p = pnext; 1231496Sbill p->op = MOVA; p->subop = BYTE; 1241496Sbill p->pop = 0; 1251496Sbill cp1 = regs[RT1]; *cp2++ = '['; 1261496Sbill while (*cp2++ = *cp1++) ; cp2--; 1271496Sbill *cp2++ = ']'; *cp2++ = ','; 1281496Sbill cp1 = regs[RT2]; 1291496Sbill while (*cp2++ = *cp1++) ; 1301496Sbill p->code = copy(buf); 1311496Sbill } 1321496Sbill } 1331496Sbill } 1341496Sbill else 1351496Sbill if (equstr(regs[RT2],"fp") && !indexa(regs[RT1])) {/* address comp. */ 1361496Sbill cp2=cp1-1; cp1=regs[RT1]+1; while (*cp2++= *cp1++); --cp2; 1371496Sbill cp1="(fp)"; while (*cp2++= *cp1++); *--cp2=','; 1381496Sbill p->combop=T(MOVA,LONG); p->pop=0; 1391496Sbill } else if (*cp1++=='-' && 0<=(r=getnum(cp1))) { 1401496Sbill p->op=SUB; p->pop=0; *--cp1='$'; p->code=cp1; 1411496Sbill } 1421496Sbill /* fall thru ... */ 1431496Sbill case CASE: 1441496Sbill default: std: 1451496Sbill p=bflow(p); break; 1461496Sbill case MUL: 1471496Sbill { 1481496Sbill /* 1491496Sbill ** Change multiplication by constant powers of 2 to 1501496Sbill ** shifts. 1511496Sbill */ 1521496Sbill splitrand(p); 1531496Sbill if (regs[RT1][0] != '$' || regs[RT1][1] == '-') goto std; 1541496Sbill if ((r = ispow2(getnum(®s[RT1][1]))) < 0) goto std; 1551496Sbill switch (r) 1561496Sbill { 1571496Sbill case 0: /* mull3 $1,x,y */ 1581496Sbill if (p->subop == U(LONG,OP3)) 1591496Sbill { 1601496Sbill if (equstr(regs[RT2], regs[RT3])) 1611496Sbill { 1621496Sbill delnode(p); p = p->forw; 1631496Sbill } 1641496Sbill else 1651496Sbill { 1661496Sbill p->op = MOV; p->subop = LONG; 1671496Sbill p->pop = 0; newcode(p); nchange++; 1681496Sbill } 1691496Sbill } 1701496Sbill else 1711496Sbill if (p->subop == U(LONG,OP2)) 1721496Sbill { 1731496Sbill delnode(p); p = p->forw; 1741496Sbill } 1751496Sbill goto std; 1761496Sbill 1771496Sbill case 1: /* mull2 $2,x */ 1781496Sbill if (p->subop == U(LONG, OP2) && !source(regs[RT2])) 1791496Sbill { 1801496Sbill strcpy(regs[RT1], regs[RT2]); 1811496Sbill p->op = ADD; p->pop = 0; newcode(p); nchange++; 1821496Sbill } 1831496Sbill goto std; 1841496Sbill } 1851496Sbill if(p->subop==U(LONG,OP3)||(p->subop==U(LONG,OP2)&&!source(regs[RT2]))) 1861496Sbill { 1871496Sbill if (p->subop == U(LONG,OP2)) 1881496Sbill strcpy(regs[RT3], regs[RT2]); 1891496Sbill sprintf(regs[RT1], "$%d", r); 1901496Sbill p->op = ASH; p->subop = LONG; 1911496Sbill p->pop = 0; newcode(p); nchange++; 1921496Sbill } 1931496Sbill goto std; 1941496Sbill } 1951496Sbill case ASH: 1961496Sbill { 1971496Sbill /* address comp: 1981496Sbill ** ashl $1,bar,r0 \ movl bar,r0 1991496Sbill ** movab _foo[r0] / movaw _foo[r0] 2001496Sbill ** 2011496Sbill ** ashl $2,r0,r0 \ moval _foo[r0] 2021496Sbill ** movab _foo[r0] / 2031496Sbill */ 2041496Sbill register struct node *pf; 2051496Sbill register int shfrom, shto; 2061496Sbill long shcnt; 2071496Sbill char *regfrom; 2081496Sbill 2091496Sbill splitrand(p); 2101496Sbill if (regs[RT1][0] != '$') goto std; 2111496Sbill if ((shcnt = getnum(®s[RT1][1])) < 1 || shcnt > 3) goto std; 2121496Sbill if ((shfrom = isreg(regs[RT2])) >= 0) 21318381Sralph regfrom = copy(regs[RT2]); 2141496Sbill if ((shto = isreg(regs[RT3])) >= 0 && shto<NUSE) 2151496Sbill { 2161496Sbill int regnum; 2171496Sbill 2181496Sbill if (uses[shto] != (pf = p->forw)) goto ashadd; 2191496Sbill if (pf->op != MOVA && pf->op != PUSHA) goto ashadd; 2201496Sbill if (pf->subop != BYTE) goto ashadd; 2211496Sbill splitrand(pf); 2221496Sbill if (!indexa(regs[RT1])) goto std; 2231496Sbill cp2 = regs[RT1]; 2241496Sbill if(!isstatic(cp2)) goto std; 2251496Sbill while (*cp2++ != '[') ; 2261496Sbill if (*cp2++ != 'r' || !isdigit(*cp2)) goto std; 2271496Sbill regnum = *cp2++ - '0'; 2281496Sbill if (isdigit(*cp2)) 2291496Sbill { 2301496Sbill if (cp2[1] != ']') goto std; 2311496Sbill regnum *= 10; regnum += *cp2 - '0'; 2321496Sbill } 2331496Sbill if (regnum != shto) goto std; 2341496Sbill if (shfrom >= 0) /* ashl $N,r*,r0 */ 2351496Sbill { 2361496Sbill delnode(p); 2371496Sbill if (shfrom != shto) 2381496Sbill { 2391496Sbill uses[shto] = NULL; splitrand(pf); 2401496Sbill cp2=regs[RT1]; while (*cp2++!='['); 2411496Sbill cp1=regfrom; while (*cp2++= *cp1++); 24218381Sralph *--cp2 = ']'; 24318381Sralph *++cp2 = '\0'; 2441496Sbill newcode(pf); 2451496Sbill } 2461496Sbill } 2471496Sbill else 2481496Sbill { 2491496Sbill p->op = MOV; splitrand(p); 2501496Sbill strcpy(regs[RT1], regs[RT2]); 2511496Sbill strcpy(regs[RT2], regs[RT3]); 2521496Sbill regs[RT3][0] = '\0'; 2531496Sbill p->pop = 0; newcode(p); 2541496Sbill } 2551496Sbill switch (shcnt) 2561496Sbill { 2571496Sbill case 1: pf->subop = WORD; break; 2581496Sbill case 2: pf->subop = LONG; break; 2591496Sbill case 3: pf->subop = QUAD; break; 2601496Sbill } 2611496Sbill redunm++; nsaddr++; nchange++; 26225756Sdonn goto std; 2631496Sbill } 2641496Sbill ashadd: 2651496Sbill /* at this point, RT2 and RT3 are guaranteed to be simple regs*/ 2661496Sbill if (shcnt == 1 && equstr(regs[RT2], regs[RT3])) 2671496Sbill { 2681496Sbill /* 2691496Sbill ** quickie: 2701496Sbill ** ashl $1,A,A > addl2 A,A 2711496Sbill */ 2721496Sbill p->op = ADD; p->subop = U(LONG,OP2); p->pop = 0; 2731496Sbill strcpy(regs[RT1], regs[RT2]); regs[RT3][0] = '\0'; 2741496Sbill newcode(p); nchange++; 2751496Sbill } 2761496Sbill goto std; 2771496Sbill } 2781496Sbill 2791496Sbill case EXTV: 2801496Sbill case EXTZV: 2811496Sbill { 2821496Sbill /* bit tests: 2831496Sbill ** extv A,$1,B,rC \ 2841496Sbill ** tstl rC > jbc A,B,D 2851496Sbill ** jeql D / 2861496Sbill ** 2871496Sbill ** also byte- and word-size fields: 2881496Sbill ** extv $n*8,$8,A,B > cvtbl n+A,B 28916133Sralph ** extv $n*16,$16,A,B > cvtwl 2n+A,B 2901496Sbill ** extzv $n*8,$8,A,B > movzbl n+A,B 29116133Sralph ** extzv $n*16,$16,A,B > movzwl 2n+A,B 2921496Sbill */ 2931496Sbill register struct node *pf; /* forward node */ 2941496Sbill register struct node *pn; /* next node (after pf) */ 2951496Sbill int flen; /* field length */ 2961496Sbill 2971496Sbill splitrand(p); 2981496Sbill if (regs[RT2][0] != '$') goto std; 2991496Sbill if ((flen = getnum(®s[RT2][1])) < 0) goto std; 3001496Sbill if (flen == 1) 3011496Sbill { 3021496Sbill register int extreg; /* reg extracted to */ 3031496Sbill 3041496Sbill extreg = isreg(regs[RT4]); 3051496Sbill if (extreg < 0 || extreg >= NUSE) goto std; 3061496Sbill if ((pf = p->forw)->op != TST) goto std; 3071496Sbill if (uses[extreg] && uses[extreg] != pf) goto std; 3081496Sbill splitrand(pf); 3091496Sbill if (extreg != isreg(regs[RT1])) goto std; 3101496Sbill if ((pn = pf->forw)->op != CBR) goto std; 3111496Sbill if (pn->subop != JEQ && pn->subop != JNE) goto std; 3121496Sbill delnode(p); delnode(pf); 3131496Sbill pn->subop = (pn->subop == JEQ) ? JBC : JBS; 3141496Sbill for(cp2=p->code; *cp2++!=',';); 3151496Sbill for(cp1=cp2; *cp1++!=',';); 3161496Sbill while (*cp1!=',') *cp2++= *cp1++; *cp2='\0'; 3171496Sbill pn->code = p->code; pn->pop = NULL; 3181496Sbill uses[extreg] = NULL; 3191496Sbill } 3201496Sbill else 3211496Sbill if (flen == 8 || flen == 16) 3221496Sbill { 3231496Sbill register int boff; /* bit offset */ 3241496Sbill register int coff; /* chunk (byte or word) offset*/ 3251496Sbill 3261496Sbill if (regs[RT1][0] != '$') goto std; 3271496Sbill if ((boff = getnum(®s[RT1][1])) < 0) goto std; 3281496Sbill coff = boff / flen; 3291496Sbill if (coff && (isreg(regs[RT3]) >= 0)) goto std; 3301496Sbill if (boff < 0 || (boff % flen) != 0) goto std; 3311496Sbill p->op = (p->op == EXTV) ? CVT : MOVZ; 3321496Sbill p->subop = U((flen == 8 ? BYTE : WORD), LONG); 3331496Sbill if (coff == 0) 3341496Sbill strcpy(regs[RT1], regs[RT3]); 3351496Sbill else 33616133Sralph sprintf(regs[RT1], "%d%s%s", 33716133Sralph (flen == 8 ? coff : 2*coff), 33816133Sralph (regs[RT3][0] == '(' ? "" : "+"), 3391496Sbill regs[RT3]); 3401496Sbill strcpy(regs[RT2], regs[RT4]); 3411496Sbill regs[RT3][0] = '\0'; regs[RT4][0] = '\0'; 3421496Sbill p->pop = 0; newcode(p); 3431496Sbill } 3441496Sbill nchange++; 3451496Sbill goto std; 3461496Sbill } 3471496Sbill 3481496Sbill case CMP: 3491496Sbill { 3501496Sbill /* comparison to -63 to -1: 3511496Sbill ** cmpl r0,$-1 > incl r0 3521496Sbill ** jeql ... 3531496Sbill ** 3541496Sbill ** cmpl r0,$-63 > addl2 $63,r0 3551496Sbill ** jeql ... 3561496Sbill */ 3571496Sbill register int num; 3581496Sbill register int reg; 3591496Sbill register struct node *regp = p->back; 3601496Sbill 3611496Sbill if (p->forw->op != CBR) goto std; 3621496Sbill if (p->forw->subop != JEQ && p->forw->subop != JNE) goto std; 3631496Sbill splitrand(p); 3641496Sbill if (strncmp(regs[RT2], "$-", 2) != 0) goto std; 3651496Sbill reg = r = isreg(regs[RT1]); 3661496Sbill if (r < 0) goto std; 3671496Sbill if (r < NUSE && uses[r] != 0) goto std; 3681496Sbill if (r >= NUSE && regp->op == MOV && p->subop == regp->subop) 3691496Sbill { 3701496Sbill if (*regp->code != 'r') goto std; 3711496Sbill reg = regp->code[1] - '0'; 3721496Sbill if (isdigit(regp->code[2]) || reg >= NUSE || uses[reg]) 3731496Sbill goto std; 3741496Sbill } 3751496Sbill if (r >= NUSE) goto std; 3761496Sbill if (reg != r) 3771496Sbill sprintf(regs[RT1], "r%d", reg); 3781496Sbill if ((num = getnum(®s[RT2][2])) <= 0 || num > 63) goto std; 3791496Sbill if (num == 1) 3801496Sbill { 3811496Sbill p->op = INC; regs[RT2][0] = '\0'; 3821496Sbill } 3831496Sbill else 3841496Sbill { 3851496Sbill register char *t; 3861496Sbill 3871496Sbill t=regs[RT1];regs[RT1]=regs[RT2];regs[RT2]=t; 3881496Sbill p->op = ADD; p->subop = U(p->subop, OP2); 3891496Sbill for (t = ®s[RT1][2]; t[-1] = *t; t++) ; 3901496Sbill } 3911496Sbill p->pop = 0; newcode(p); 3921496Sbill nchange++; 3931496Sbill goto std; 3941496Sbill } 3951496Sbill 3961496Sbill case JSB: 3971496Sbill if (equstr(p->code,"mcount")) {uses[0]=p; regs[0][0]= -1;} 3981496Sbill goto std; 3991496Sbill case JBR: case JMP: 4001496Sbill clearuse(); 4011496Sbill if (p->subop==RET || p->subop==RSB) {uses[0]=p; regs[0][0]= -1; break;} 4021496Sbill if (p->ref==0) goto std; /* jmp (r0) */ 4031496Sbill /* fall through */ 4041496Sbill case CBR: 4051496Sbill if (p->ref->ref!=0) for (r=NUSE;--r>=0;) 4061496Sbill if (biti[r] & (int)p->ref->ref) {uses[r]=p; regs[r][0]= -1;} 4071496Sbill case EROU: case JSW: 4081496Sbill case TEXT: case DATA: case BSS: case ALIGN: case WGEN: case END: ; 4091496Sbill } 4101496Sbill } 4111496Sbill for (p= &first; p!=0; p=p->forw) 4121496Sbill if (p->op==LABEL || p->op==DLABEL) p->ref=0; /* erase our tracks */ 4131496Sbill } 4141496Sbill 4151496Sbill rmove() 4161496Sbill { 41718381Sralph register struct node *p; 4181496Sbill register int r; 4191496Sbill int r1; 4201496Sbill 4211496Sbill clearreg(); 4221496Sbill for (p=first.forw; p!=0; p = p->forw) { 4231496Sbill if (debug) { 42417210Sralph if (*conloc) { 42517210Sralph r1=conval[0]; 42617210Sralph printf("Con %s = %d%d %s\n", conloc, r1&0xF, r1>>4, conval+1); 42717210Sralph } 4281496Sbill printf("Regs:\n"); 4291496Sbill for (r=0; r<NREG; r++) 4301496Sbill if (regs[r][0]) { 4311496Sbill r1=regs[r][0]; 4321496Sbill printf("%d: %d%d %s\n", r, r1&0xF, r1>>4, regs[r]+1); 4331496Sbill } 4341496Sbill printf("-\n"); 4351496Sbill } 4361496Sbill switch (p->op) { 4371496Sbill 4381496Sbill case CVT: 4391496Sbill splitrand(p); goto mov; 4401496Sbill 4411496Sbill case MOV: 4421496Sbill splitrand(p); 4431496Sbill if ((r = findrand(regs[RT1],p->subop)) >= 0) { 4441496Sbill if (r == isreg(regs[RT2]) && p->forw->op!=CBR) { 4451496Sbill delnode(p); redunm++; break; 4461496Sbill } 4471496Sbill } 4481496Sbill mov: 4491496Sbill repladdr(p); 4501496Sbill r = isreg(regs[RT1]); 4511496Sbill r1 = isreg(regs[RT2]); 4521496Sbill dest(regs[RT2],p->subop); 4531506Sbill if (r>=0) { 4541506Sbill if (r1>=0) savereg(r1, regs[r]+1, p->subop); 4551506Sbill else if (p->op!=CVT) savereg(r, regs[RT2], p->subop); 4561506Sbill } else if (r1>=0) savereg(r1, regs[RT1], p->subop); 4571506Sbill else if (p->op!=CVT) setcon(regs[RT1], regs[RT2], p->subop); 4581496Sbill break; 4591496Sbill 4601496Sbill /* .rx,.wx */ 4611496Sbill case MFPR: 4621496Sbill case COM: 4631496Sbill case NEG: 4641496Sbill /* .rx,.wx or .rx,.rx,.wx */ 4651496Sbill case ADD: 4661496Sbill case SUB: 4671496Sbill case BIC: 4681496Sbill case BIS: 4691496Sbill case XOR: 4701496Sbill case MUL: 4711496Sbill case DIV: 4721496Sbill case ASH: 4731496Sbill case MOVZ: 4741496Sbill /* .rx,.rx,.rx,.wx */ 4751496Sbill case EXTV: 4761496Sbill case EXTZV: 4771496Sbill case INSV: 4781496Sbill splitrand(p); 4791496Sbill repladdr(p); 4801496Sbill dest(lastrand,p->subop); 4811496Sbill if (p->op==INSV) ccloc[0]=0; 4821496Sbill break; 4831496Sbill 4841496Sbill /* .mx or .wx */ 4851496Sbill case CLR: 4861496Sbill case INC: 4871496Sbill case DEC: 4881496Sbill splitrand(p); 4891496Sbill dest(lastrand,p->subop); 4901496Sbill if (p->op==CLR) 4911496Sbill if ((r = isreg(regs[RT1])) >= 0) 4921496Sbill savereg(r, "$0", p->subop); 4931496Sbill else 4941496Sbill setcon("$0", regs[RT1], p->subop); 4951496Sbill break; 4961496Sbill 4971496Sbill /* .rx */ 4981496Sbill case TST: 4991496Sbill case PUSH: 5001496Sbill splitrand(p); 5011496Sbill lastrand=regs[RT1+1]; /* fool repladdr into doing 1 operand */ 5021496Sbill repladdr(p); 5031496Sbill if (p->op==TST && equstr(lastrand=regs[RT1], ccloc+1) 5041496Sbill && ((0xf&(ccloc[0]>>4))==p->subop || equtype(ccloc[0],p->subop)) 5051496Sbill &&!source(lastrand)) { 5061496Sbill delnode(p); p = p->back; nrtst++; nchange++; 5071496Sbill } 5081496Sbill setcc(lastrand,p->subop); 5091496Sbill break; 5101496Sbill 5111496Sbill /* .rx,.rx,.rx */ 5121496Sbill case PROBER: 5131496Sbill case PROBEW: 5141496Sbill case CASE: 5151496Sbill case MOVC3: 5161496Sbill /* .rx,.rx */ 5171496Sbill case MTPR: 5181496Sbill case CALLS: 5191496Sbill case CMP: 5201496Sbill case BIT: 5211496Sbill splitrand(p); 5221496Sbill /* fool repladdr into doing right number of operands */ 5233957Sbugs if (p->op==CASE || p->op==PROBER || p->op==PROBEW) lastrand=regs[RT4]; 5243958Sbugs /* else if (p->op==CMPV || p->op==CMPZV) lastrand=regs[RT4+1]; */ 5253957Sbugs else if (p->op==MOVC3) lastrand=regs[RT1]; 5261496Sbill else lastrand=regs[RT3]; 5271496Sbill repladdr(p); 5281496Sbill if (p->op==CALLS || p->op==MOVC3) clearreg(); 5291496Sbill if (p->op==BIT) bitopt(p); 5301496Sbill ccloc[0]=0; break; 5311496Sbill 5321496Sbill case CBR: 5331496Sbill if (p->subop>=JBC) { 5341496Sbill splitrand(p); 5351496Sbill if (p->subop<JBCC) lastrand=regs[RT3]; /* 2 operands can be optimized */ 5361496Sbill else lastrand=regs[RT2]; /* .mb destinations lose */ 5371496Sbill repladdr(p); 5381496Sbill } 5391496Sbill ccloc[0] = 0; 5401496Sbill break; 5411496Sbill 5421496Sbill case JBR: 5431496Sbill redunbr(p); 5441496Sbill 5451496Sbill /* .wx,.bb */ 5461496Sbill case SOB: 5471496Sbill 5481496Sbill default: 5491496Sbill clearreg(); 5501496Sbill } 5511496Sbill } 5521496Sbill } 5531496Sbill 5541496Sbill char * 5551496Sbill byondrd(p) register struct node *p; { 5561496Sbill /* return pointer to register which is "beyond last read/modify operand" */ 5571496Sbill if (OP2==(p->subop>>4)) return(regs[RT3]); 5581496Sbill switch (p->op) { 5591496Sbill case MFPR: 5601496Sbill case JSB: 5611496Sbill case PUSHA: 5621496Sbill case TST: case INC: case DEC: case PUSH: return(regs[RT2]); 5631496Sbill case MTPR: 5641496Sbill case BIT: case CMP: case CALLS: return(regs[RT3]); 5651496Sbill case PROBER: case PROBEW: 5661496Sbill case CASE: case MOVC3: return(regs[RT4]); 5671496Sbill } 5681496Sbill return(lastrand); 5691496Sbill } 5701496Sbill 5711496Sbill struct node * 5721496Sbill bflow(p) 5731496Sbill register struct node *p; 5741496Sbill { 5751496Sbill register char *cp1,*cp2,**preg; register int r; 5761496Sbill int flow= -1; 5771496Sbill struct node *olduse=0; 5781496Sbill splitrand(p); 5791496Sbill if (p->op!=PUSH && p->subop && 0<=(r=isreg(lastrand)) && r<NUSE && uses[r]==p->forw) { 580*32986Sdonn if ((p->op==CVT || p->op==MOVZ) 581*32986Sdonn && (p->forw->op==CVT || p->forw->op==MOVZ) 582*32986Sdonn && p->forw->subop&0xf 583*32986Sdonn && compat(p->subop,p->forw->subop) 584*32986Sdonn && !source(cp1=regs[RT1]) 585*32986Sdonn && !indexa(cp1)) goto movit; 5861496Sbill if (equtype(p->subop,regs[r][0]) 5871496Sbill || ((p->op==CVT || p->op==MOVZ) 5881496Sbill && 0xf®s[r][0] && compat(0xf&(p->subop>>4),regs[r][0]))) { 5891496Sbill register int r2; 5901496Sbill if (regs[r][1]!=0) {/* send directly to destination */ 5911496Sbill if (p->op==INC || p->op==DEC) { 5921496Sbill if (p->op==DEC) p->op=SUB; else p->op=ADD; 5931496Sbill p->subop=(OP2<<4)+(p->subop&0xF); /* use 2 now, convert to 3 later */ 5941496Sbill p->pop=0; 5951496Sbill cp1=lastrand; cp2=regs[RT2]; while (*cp2++= *cp1++); /* copy reg */ 5961496Sbill cp1=lastrand; *cp1++='$'; *cp1++='1'; *cp1=0; 5971496Sbill } 5981496Sbill cp1=regs[r]+1; cp2=lastrand; 5991496Sbill if (OP2==(p->subop>>4)) {/* use 3 operand form of instruction */ 6001496Sbill p->pop=0; 6011496Sbill p->subop += (OP3-OP2)<<4; lastrand=cp2=regs[RT3]; 6021496Sbill } 6031496Sbill while (*cp2++= *cp1++); 6041496Sbill if (p->op==MOVA && p->forw->op==PUSH) { 6051496Sbill p->op=PUSHA; *regs[RT2]=0; p->pop=0; 6061496Sbill } else if (p->op==MOV && p->forw->op==PUSH) { 6071496Sbill p->op=PUSH ; *regs[RT2]=0; p->pop=0; 6081496Sbill } 6091496Sbill delnode(p->forw); 6101496Sbill if (0<=(r2=isreg(lastrand)) && r2<NUSE) { 6111496Sbill uses[r2]=uses[r]; uses[r]=0; 6121496Sbill } 61318381Sralph (void) redun3(p,0); 6141496Sbill newcode(p); redunm++; flow=r; 6151496Sbill } else if (p->op==MOV && p->forw->op!=EXTV && p->forw->op!=EXTZV) { 6161496Sbill /* superfluous fetch */ 6171496Sbill int nmatch; 6182829Stoy char src[C2_ASIZE]; 6191496Sbill movit: 6201496Sbill cp2=src; cp1=regs[RT1]; while (*cp2++= *cp1++); 6211496Sbill splitrand(p->forw); 6221496Sbill if (p->forw->op != INC && p->forw->op != DEC) 6231496Sbill lastrand=byondrd(p->forw); 6241496Sbill nmatch=0; 6251496Sbill for (preg=regs+RT1;*preg!=lastrand;preg++) 6261496Sbill if (r==isreg(*preg)) { 6271496Sbill cp2= *preg; cp1=src; while (*cp2++= *cp1++); ++nmatch; 6281496Sbill } 6291496Sbill if (nmatch==1) { 6301496Sbill if (OP2==(p->forw->subop>>4) && equstr(src,regs[RT2])) { 6311496Sbill p->forw->pop=0; 6321496Sbill p->forw->subop += (OP3-OP2)<<4; cp1=regs[RT3]; 6331496Sbill *cp1++='r'; *cp1++=r+'0'; *cp1=0; 6341496Sbill } 6351496Sbill delnode(p); p=p->forw; 6361496Sbill if (0<=(r2=isreg(src)) && r2<NUSE) { 6371496Sbill uses[r2]=uses[r]; uses[r]=0; 6381496Sbill } 63918381Sralph (void) redun3(p,0); 6401496Sbill newcode(p); redunm++; flow=r; 6411496Sbill } else splitrand(p); 6421496Sbill } 6431496Sbill } else if (p->op==MOV && (p->forw->op==CVT || p->forw->op==MOVZ) 6441496Sbill && p->forw->subop&0xf /* if base or index, then forget it */ 6451496Sbill && compat(p->subop,p->forw->subop) && !source(cp1=regs[RT1]) 6461496Sbill && !indexa(cp1)) goto movit; 6471496Sbill } 6481496Sbill /* adjust 'lastrand' past any 'read' or 'modify' operands. */ 6491496Sbill lastrand=byondrd(p); 6501496Sbill /* a 'write' clobbers the register. */ 6511496Sbill if (0<=(r=isreg(lastrand)) && r<NUSE 6521496Sbill || OP2==(p->subop>>4) && 0<=(r=isreg(regs[RT2])) && r<NUSE && uses[r]==0) { 6531496Sbill /* writing a dead register is useless, but watch side effects */ 6541496Sbill switch (p->op) { 6551498Sbill case ACB: 6561496Sbill case AOBLEQ: case AOBLSS: case SOBGTR: case SOBGEQ: break; 6571498Sbill default: 6581496Sbill if (uses[r]==0) {/* no direct uses, check for use of condition codes */ 6591496Sbill register struct node *q=p; 6601496Sbill while ((q=nonlab(q->forw))->combop==JBR) q=q->ref; /* cc unused, unchanged */ 6611496Sbill if (q->op!=CBR) {/* ... and destroyed */ 6621496Sbill preg=regs+RT1; 6631496Sbill while (cp1= *preg++) { 6641496Sbill if (cp1==lastrand) {redunm++; delnode(p); return(p->forw);} 6651496Sbill if (source(cp1) || equstr(cp1,lastrand)) break; 6661496Sbill } 6671496Sbill } 6681496Sbill } 6691496Sbill flow=r; 6701496Sbill } 6711496Sbill } 67218381Sralph if (0<=(r=flow)) { 67318381Sralph olduse=uses[r]; 67418381Sralph uses[r]=0; 67518381Sralph regs[r][0]=regs[r][1]=0; 67618381Sralph } 6771496Sbill /* these two are here, rather than in bmove(), 6781496Sbill /* because I decided that it was better to go for 3-address code 6791496Sbill /* (save time) rather than fancy jbxx (save 1 byte) 6801496Sbill /* on sequences like bisl2 $64,r0; movl r0,foo 6811496Sbill */ 6821496Sbill if (p->op==BIC) {p=bicopt(p); splitrand(p); lastrand=byondrd(p);} 68318381Sralph if (p->op==BIS) {(void) bixprep(p,JBSS); lastrand=byondrd(p);} 6841496Sbill /* now look for 'read' or 'modify' (read & write) uses */ 6851496Sbill preg=regs+RT1; 6861496Sbill while (*(cp1= *preg++)) { 6871496Sbill /* check for r */ 6881496Sbill if (lastrand!=cp1 && 0<=(r=isreg(cp1)) && r<NUSE && uses[r]==0) { 6891496Sbill uses[r]=p; cp2=regs[r]; *cp2++=p->subop; 6901506Sbill if (p->op==ASH && preg==(regs+RT1+1)) cp2[-1]=BYTE; /* stupid DEC */ 6911496Sbill if (p->op==MOV || p->op==PUSH || p->op==CVT || p->op==MOVZ || p->op==COM || p->op==NEG) { 6921496Sbill if (p->op==PUSH) cp1="-(sp)"; 6931496Sbill else { 6941496Sbill cp1=regs[RT2]; 6951496Sbill if (0<=(r=isreg(cp1)) && r<NUSE && uses[r]==0) 6961496Sbill uses[r]=olduse; /* reincarnation!! */ 6971496Sbill /* as in addl2 r0,r1; movl r1,r0; ret */ 6981496Sbill if (p->op!=MOV) cp1=0; 6991496Sbill } 7001496Sbill if (cp1) while (*cp2++= *cp1++); 7011506Sbill else *cp2=0; 7021506Sbill } else *cp2=0; 7031496Sbill continue; 7041496Sbill } 7051496Sbill /* check for (r),(r)+,-(r),[r] */ 7061496Sbill do if (*cp1=='(' || *cp1=='[') {/* get register number */ 7071496Sbill char t; 7081496Sbill cp2= ++cp1; while (*++cp1!=')' && *cp1!=']'); t= *cp1; *cp1=0; 7091496Sbill if (0<=(r=isreg(cp2)) && r<NUSE && (uses[r]==0 || uses[r]==p)) { 7101496Sbill uses[r]=p; regs[r][0]=(*--cp2=='[' ? OPX<<4 : OPB<<4); 7111496Sbill } 7121496Sbill *cp1=t; 7131496Sbill } while (*++cp1); 7141496Sbill } 7151496Sbill /* pushax or movax possibility? */ 7161496Sbill cp1=regs[RT1]; 7171496Sbill if (*cp1++=='$' && isstatic(cp1) && natural(regs[RT1])) { 7181496Sbill if (p->combop==T(MOV,LONG)) { 7191496Sbill if (regs[RT1][1]=='L' && 0!=(p->labno=getnum(regs[RT1]+2))) { 7201496Sbill cp1=p->code; while (*cp1++!=','); p->code= --cp1; 7211496Sbill } 7221496Sbill p->combop=T(MOVA,LONG); ++p->code; p->pop=0; 7231496Sbill } else if (p->combop==T(PUSH,LONG)) { 7241496Sbill p->combop=T(PUSHA,LONG); ++p->code; p->pop=0; 7251496Sbill } else if ((p->combop&0xFFFF)==T(ADD,U(LONG,OP3)) 7261496Sbill && 0<=(r=isreg(regs[RT2]))) { 7271496Sbill cp1=cp2=p->code; ++cp1; 7281496Sbill do *cp2++= *cp1; while (*cp1++!=','); cp2[-1]='['; 7291496Sbill do *cp2++= *cp1; while (*cp1++!=','); cp2[-1]=']'; 7301496Sbill if (!equstr(regs[RT3],"-(sp)")) p->combop=T(MOVA,BYTE); 7311496Sbill else {p->combop=T(PUSHA,BYTE); *cp2=0;} 73224399Smckusick if (r < NUSE && uses[r] == 0) { 73324399Smckusick uses[r]=p; 73424399Smckusick regs[r][0]=OPX<<4; 73524399Smckusick } 7361496Sbill p->pop=0; 7371496Sbill } 7381496Sbill } 7391496Sbill return(p); 7401496Sbill } 7411496Sbill 7421496Sbill ispow2(n) register long n; {/* -1 -> no; else -> log to base 2 */ 7431496Sbill register int log; 7441496Sbill if (n==0 || n&(n-1)) return(-1); log=0; 7451496Sbill for (;;) {n >>= 1; if (n==0) return(log); ++log; if (n== -1) return(log);} 7461496Sbill } 7471496Sbill 7481496Sbill bitopt(p) register struct node *p; { 7491496Sbill /* change "bitx $<power_of_2>,a" followed by JEQ or JNE 7501496Sbill /* into JBC or JBS. watch out for I/O registers. (?) 7511496Sbill /* assumes that 'splitrand' has already been called. 7521496Sbill */ 7531496Sbill register char *cp1,*cp2; int b; 7541496Sbill cp1=regs[RT1]; cp2=regs[RT2]; 7551496Sbill if (*cp1++!='$' || !okio(cp2) || p->forw->op!=CBR || p->forw->subop&-2 || 75627461Sdonn 0>(b=ispow2(getnum(cp1)))) return; 75727461Sdonn if (p->subop!=BYTE && !(b==0 && p->subop==LONG) && 75827461Sdonn (source(cp2) || indexa(cp2))) return; 7591496Sbill if (b>=bitsize[p->subop]) {/* you dummy! */ 7601496Sbill if (source(cp2)) {/* side effect: auto increment or decrement */ 7611496Sbill p->pop=0; 7621496Sbill p->op=TST; --cp1; while (*cp1++= *cp2++); 7631496Sbill regs[RT2][0]=0; newcode(p); 7641496Sbill } else delnode(p); 7651496Sbill p = p->forw; 7661496Sbill if (p->subop==JEQ) {p->combop=JBR; p->pop=0;} 7671496Sbill else delnode(p); 7681496Sbill nchange++; nbj++; return; 7691496Sbill } 7701496Sbill if (cp1=p->forw->code) {/* destination is not an internal label */ 7711496Sbill cp2=regs[RT3]; while (*cp2++= *cp1++); 7721496Sbill } 77327461Sdonn if (b==0 && (p->subop==LONG || !(source(regs[RT2]) || indexa(regs[RT2])))) { 77427461Sdonn /* JLB optimization, ala BLISS */ 7751496Sbill cp2=regs[RT1]; cp1=regs[RT2]; while (*cp2++= *cp1++); 7761496Sbill cp2=regs[RT2]; cp1=regs[RT3]; while (*cp2++= *cp1++); 7771496Sbill *(regs[RT3])=0; p->forw->subop += JLBC-JBC; 7781496Sbill p->forw->pop=0; 7791496Sbill } else { 7801496Sbill cp1=regs[RT1]+1; 7811496Sbill if (b>9) *cp1++= b/10 +'0'; *cp1++= b%10 +'0'; *cp1=0; /* $<bit_number> */ 7821496Sbill } 7831496Sbill nbj++; newcode(p); p->combop = p->forw->combop+((JBC-JEQ)<<8); 7841496Sbill p->labno = p->forw->labno; delnode(p->forw); 7851496Sbill p->pop=0; 7861496Sbill } 7871496Sbill 7881496Sbill isfield(n) register long n; {/* -1 -> no; else -> position of low bit */ 78918381Sralph register int p; register long t; 7901496Sbill t= ((n-1)|n) +1; 79116832Sralph if (n!=0 && (0==t || 0<=ispow2(t))) { 79218381Sralph p=0; while(!(n&1)) {n >>= 1; ++p;} return(p); 7931496Sbill } else return(-1); 7941496Sbill } 7951496Sbill 7961496Sbill bixprep(p,bix) register struct node *p; { 7971496Sbill /* initial setup, single-bit checking for bisopt, bicopt. 7981496Sbill /* return: 0->don't bother any more; 1->worthwhile trying 7991496Sbill */ 8001496Sbill register char *cp1,*cp2; 8011496Sbill splitrand(p); cp1=regs[RT1]; cp2=regs[RT2]; 8021496Sbill if (*cp1++!='$' || 0>(pos=isfield(f=getnum(cp1))) 8031496Sbill || !okio(cp2) || indexa(cp2) || source(cp2) || !okio(lastrand)) return(0); 8041496Sbill f |= f-1; if (++f==0) siz=32-pos; else siz=ispow2(f)-pos; 8051496Sbill if (siz==1 && pos>5 && (p->subop>>4)==OP2 && (p->subop&0xF)!=BYTE 8061496Sbill && pos<bitsize[p->subop&0xF]) { 8071496Sbill p->ref = insertl(p->forw); p->combop = CBR | (bix<<8); 8081496Sbill p->pop=0; 8091496Sbill p->labno = p->ref->labno; 8101496Sbill if (pos>9) {*cp1++= pos/10 +'0'; pos %= 10;} 8111496Sbill *cp1++=pos+'0'; *cp1=0; newcode(p); nbj++; return(0); 8121496Sbill } 8131496Sbill return(1); 8141496Sbill } 8151496Sbill 8161496Sbill 8171496Sbill struct node * 8181496Sbill bicopt(p) register struct node *p; { 8191496Sbill /* use field operations or MOVZ if possible. done as part of 'bflow'. 8201496Sbill */ 8211496Sbill register char *cp1,*cp2; int r; 8223933Sroot char src[C2_ASIZE]; 82318381Sralph char lhssiz, sop; 8241496Sbill if (!bixprep(p,JBCC)) return(p); 8251496Sbill if (f==0) {/* the BIC isolates low order bits */ 8261496Sbill siz=pos; pos=0; 8271496Sbill if ((p->subop&0xF)==LONG && *(regs[RT2])!='$') {/* result of EXTZV is long */ 8281496Sbill /* save source of BICL in 'src' */ 8291496Sbill cp1=regs[RT2]; cp2=src; while (*cp2++= *cp1++); 8301496Sbill if (p->back->op==ASH) {/* try for more */ 8311496Sbill splitrand(p->back); cp1=regs[RT1]; cp2=regs[RT3]; 8321496Sbill if (*cp1++=='$' && *(regs[RT2])!='$' && !indexa(regs[RT2]) 8331496Sbill && 0>(f=getnum(cp1)) && equstr(src,cp2) 83416832Sralph && 0<=(r=isreg(cp2)) && r<NUSE 83516832Sralph && siz-f <= 32) { /* a good ASH */ 8361496Sbill pos -= f; cp1=regs[RT2]; cp2=src; while (*cp2++= *cp1++); 8371496Sbill delnode(p->back); 8381496Sbill } 8391496Sbill } 84016133Sralph /* 84116133Sralph * 'pos', 'siz' known; find out the size of the 84216133Sralph * left-hand operand of what the bicl will turn into. 84316133Sralph */ 84416133Sralph if (pos==0 && siz==16) 84516133Sralph lhssiz = WORD; /* movzwl */ 84616133Sralph else 84716133Sralph lhssiz = BYTE; /* movzbl or extzvl */ 8481496Sbill if (p->back->op==CVT || p->back->op==MOVZ) {/* greedy, aren't we? */ 8491496Sbill splitrand(p->back); cp1=regs[RT1]; cp2=regs[RT2]; 85016133Sralph /* 85116133Sralph * If indexa(cp1) || autoid(cp1), the fold may 85216133Sralph * still be OK if the CVT/MOVZ has the same 85316133Sralph * size operand on its left size as what we 85416133Sralph * will turn the bicl into. 85516133Sralph * However, if the CVT is from a float or 85616133Sralph * double, forget it! 85716133Sralph */ 85818381Sralph sop = p->back->subop&0xF; /* type of LHS of CVT/MOVZ */ 85916133Sralph if (equstr(src,cp2) && okio(cp1) 86018381Sralph && sop != FFLOAT && sop != DFLOAT 86118381Sralph && sop != GFLOAT && sop != HFLOAT 86218381Sralph && ((!indexa(cp1) && !autoid(cp1)) || lhssiz == sop) 8631496Sbill && 0<=(r=isreg(cp2)) && r<NUSE 86418381Sralph && bitsize[sop]>=(pos+siz) 8651496Sbill && bitsize[p->back->subop>>4]>=(pos+siz)) {/* good CVT */ 8661496Sbill cp1=regs[RT1]; cp2=src; while (*cp2++= *cp1++); 8671496Sbill delnode(p->back); 8681496Sbill } 8691496Sbill } 8701496Sbill /* 'pos', 'siz' known; source of field is in 'src' */ 8711496Sbill splitrand(p); /* retrieve destination of BICL */ 87216133Sralph if ((siz==8 || siz==16) && pos==0) { 87316133Sralph p->combop = T(MOVZ,U(lhssiz,LONG)); 8741496Sbill sprintf(line,"%s,%s",src,lastrand); 8751496Sbill } else { 8761496Sbill p->combop = T(EXTZV,LONG); 8771496Sbill sprintf(line,"$%d,$%d,%s,%s",pos,siz,src,lastrand); 8781496Sbill } 8791496Sbill p->pop=0; 8801496Sbill p->code = copy(line); nfield++; return(p); 8811496Sbill }/* end EXTZV possibility */ 8821496Sbill }/* end low order bits */ 8831496Sbill /* unfortunately, INSV clears the condition codes, thus cannot be used */ 8841496Sbill /* else {/* see if BICL2 of positive field should be INSV $0 */ 8851496Sbill /* if (p->subop==(LONG | (OP2<<4)) && 6<=(pos+siz)) { 8861496Sbill /* p->combop = INSV; 8871496Sbill /* sprintf(line,"$0,$%d,$%d,%s",pos,siz,lastrand); 8881496Sbill /* p->code = copy(line); nfield++; return(p); 8891496Sbill /* } 8901496Sbill /* } 8911496Sbill */ 8921496Sbill return(p); 8931496Sbill } 8941496Sbill 8951496Sbill jumpsw() 8961496Sbill { 8971496Sbill register struct node *p, *p1; 89818381Sralph register struct node *tp; 89918381Sralph long tl; 90018381Sralph char *tcp; 90118381Sralph int ti; 9021496Sbill int nj; 9031496Sbill 90418381Sralph ti = 0; 9051496Sbill nj = 0; 9061496Sbill for (p=first.forw; p!=0; p = p->forw) 90718381Sralph p->seq = ++ti; 9081496Sbill for (p=first.forw; p!=0; p = p1) { 9091496Sbill p1 = p->forw; 9101496Sbill if (p->op == CBR && p1->op==JBR && p->ref && p1->ref 9111496Sbill && abs(p->seq - p->ref->seq) > abs(p1->seq - p1->ref->seq)) { 9121496Sbill if (p->ref==p1->ref) 9131496Sbill continue; 9141496Sbill p->subop = revbr[p->subop]; 9151496Sbill p->pop=0; 91618381Sralph tp = p1->ref; 9171496Sbill p1->ref = p->ref; 91818381Sralph p->ref = tp; 91918381Sralph tl = p1->labno; 9201496Sbill p1->labno = p->labno; 92118381Sralph p->labno = tl; 9221496Sbill #ifdef COPYCODE 9231496Sbill if (p->labno == 0) { 92418381Sralph tcp = p1->code; 92518381Sralph p1->code = p->code; 92618381Sralph p->code = tcp; 9271496Sbill } 9281496Sbill #endif 9291496Sbill nrevbr++; 9301496Sbill nj++; 9311496Sbill } 9321496Sbill } 9331496Sbill return(nj); 9341496Sbill } 9351496Sbill 9361496Sbill addsob() 9371496Sbill { 9381496Sbill register struct node *p, *p1, *p2, *p3; 9391496Sbill 9401496Sbill for (p = &first; (p1 = p->forw)!=0; p = p1) { 9411496Sbill if (p->combop==T(DEC,LONG) && p1->op==CBR) { 9423933Sroot if (abs(p->seq - p1->ref->seq) > 8) continue; 9431496Sbill if (p1->subop==JGE || p1->subop==JGT) { 9441496Sbill if (p1->subop==JGE) p->combop=SOBGEQ; else p->combop=SOBGTR; 9451496Sbill p->pop=0; 9461496Sbill p->labno = p1->labno; delnode(p1); nsob++; 9471496Sbill } 9481496Sbill } else if (p->combop==T(INC,LONG)) { 9491496Sbill if (p1->op==LABEL && p1->refc==1 && p1->forw->combop==T(CMP,LONG) 9501496Sbill && (p2=p1->forw->forw)->combop==T(CBR,JLE) 9511496Sbill && (p3=p2->ref->back)->combop==JBR && p3->ref==p1 9521496Sbill && p3->forw->op==LABEL && p3->forw==p2->ref) { 9531496Sbill /* change INC LAB: CMP to LAB: INC CMP */ 9541496Sbill p->back->forw=p1; p1->back=p->back; 9551496Sbill p->forw=p1->forw; p1->forw->back=p; 9561496Sbill p->back=p1; p1->forw=p; 9571496Sbill p1=p->forw; 9581496Sbill /* adjust beginning value by 1 */ 9591496Sbill p2=alloc(sizeof first); p2->combop=T(DEC,LONG); 9601496Sbill p2->pop=0; 9611496Sbill p2->forw=p3; p2->back=p3->back; p3->back->forw=p2; 9621496Sbill p3->back=p2; p2->code=p->code; p2->labno=0; 9631496Sbill } 9641496Sbill if (p1->combop==T(CMP,LONG) && (p2=p1->forw)->op==CBR) { 9651496Sbill register char *cp1,*cp2; 9661496Sbill splitrand(p1); if (!equstr(p->code,regs[RT1])) continue; 9673933Sroot if (abs(p->seq - p2->ref->seq)>8) {/* outside byte displ range */ 9681496Sbill if (p2->subop!=JLE) continue; 9691496Sbill p->combop=T(ACB,LONG); 9701496Sbill cp2=regs[RT1]; cp1=regs[RT2]; while (*cp2++= *cp1++); /* limit */ 9711496Sbill cp2=regs[RT2]; cp1="$1"; while (*cp2++= *cp1++); /* increment */ 9721496Sbill cp2=regs[RT3]; cp1=p->code; while (*cp2++= *cp1++); /* index */ 9731496Sbill p->pop=0; newcode(p); 9741496Sbill p->labno = p2->labno; delnode(p2); delnode(p1); nsob++; 9751496Sbill } else if (p2->subop==JLE || p2->subop==JLT) { 9761496Sbill if (p2->subop==JLE) p->combop=AOBLEQ; else p->combop=AOBLSS; 9771496Sbill cp2=regs[RT1]; cp1=regs[RT2]; while (*cp2++= *cp1++); /* limit */ 9781496Sbill cp2=regs[RT2]; cp1=p->code; while (*cp2++= *cp1++); /* index */ 9791496Sbill p->pop=0; newcode(p); 9801496Sbill p->labno = p2->labno; delnode(p2); delnode(p1); nsob++; 9811496Sbill } 9821496Sbill } 9831496Sbill } 9841496Sbill } 9851496Sbill } 9861496Sbill 9871496Sbill equop(p1, p2) 9881496Sbill register struct node *p1; 9891496Sbill struct node *p2; 9901496Sbill { 9911496Sbill register char *cp1, *cp2; 9921496Sbill 9931496Sbill if (p1->combop != p2->combop) 9941496Sbill return(0); 99532985Sdonn if (p1->combop == 0 && p1->pop != p2->pop) 99632985Sdonn return(0); 9971496Sbill if (p1->op>0 && p1->op<MOV) 9981496Sbill return(0); 99918381Sralph switch (p1->combop) { 100018381Sralph case EROU: case JSW: case TEXT: case DATA: 100118381Sralph case BSS: case ALIGN: case WGEN: case END: 100218381Sralph /* 100318381Sralph * Consider all pseudo-ops to be unique. 100418381Sralph */ 100518381Sralph return(0); 100618381Sralph } 10071496Sbill if (p1->op==MOVA && p1->labno!=p2->labno) return(0); 10081496Sbill cp1 = p1->code; 10091496Sbill cp2 = p2->code; 10101496Sbill if (cp1==0 && cp2==0) 10111496Sbill return(1); 10121496Sbill if (cp1==0 || cp2==0) 10131496Sbill return(0); 10141496Sbill while (*cp1 == *cp2++) 10151496Sbill if (*cp1++ == 0) 10161496Sbill return(1); 10171496Sbill return(0); 10181496Sbill } 10191496Sbill 102018381Sralph #ifndef delnode 10211496Sbill delnode(p) register struct node *p; { 10221496Sbill p->back->forw = p->forw; 10231496Sbill p->forw->back = p->back; 10241496Sbill } 102518381Sralph #endif 10261496Sbill 102718381Sralph #ifndef decref 10281496Sbill decref(p) 10291496Sbill register struct node *p; 10301496Sbill { 10311496Sbill if (p && --p->refc <= 0) { 10321496Sbill nrlab++; 10331496Sbill delnode(p); 10341496Sbill } 10351496Sbill } 103618381Sralph #endif 10371496Sbill 10381496Sbill struct node * 10391496Sbill nonlab(ap) 10401496Sbill struct node *ap; 10411496Sbill { 10421496Sbill register struct node *p; 10431496Sbill 10441496Sbill p = ap; 10451496Sbill while (p && p->op==LABEL) 10461496Sbill p = p->forw; 10471496Sbill return(p); 10481496Sbill } 10491496Sbill 10501496Sbill clearuse() { 10511496Sbill register struct node **i; 10521496Sbill for (i=uses+NUSE; i>uses;) *--i=0; 10531496Sbill } 10541496Sbill 10551496Sbill clearreg() { 105618381Sralph register char **i; 105718381Sralph for (i=regs; i<regs+NREG; ++i) { 105818381Sralph **i = 0; 105918381Sralph *(*i+1) = 0; 106018381Sralph } 106118381Sralph conloc[0] = 0; 106218381Sralph ccloc[0] = 0; 10631496Sbill } 10641496Sbill 10651496Sbill savereg(ai, s, type) 10661496Sbill register char *s; 10671496Sbill { 10681496Sbill register char *p, *sp; 10691496Sbill 10701496Sbill sp = p = regs[ai]; 10711496Sbill if (source(s)) /* side effects in addressing */ 10721496Sbill return; 10731496Sbill /* if any indexing, must be parameter or local */ 10741496Sbill /* indirection (as in "*-4(fp)") is ok, however */ 10751496Sbill *p++ = type; 10761496Sbill while (*p++ = *s) 10771496Sbill if (*s=='[' || *s++=='(' && *s!='a' && *s!='f') {*sp = 0; return;} 10781496Sbill } 10791496Sbill 10801496Sbill dest(s,type) 10811496Sbill register char *s; 10821496Sbill { 10831496Sbill register int i; 10841496Sbill 108518381Sralph (void) source(s); /* handle addressing side effects */ 108617210Sralph if (!natural(s)) { 108717210Sralph /* wild store, everything except constants vanishes */ 108817210Sralph for (i=NREG; --i>=0;) 108918381Sralph if (regs[i][1] != '$') 109018381Sralph regs[i][0] = regs[i][1] = 0; 109117210Sralph conloc[0] = 0; ccloc[0] = 0; 109217210Sralph return; 109317210Sralph } 10941496Sbill if ((i = isreg(s)) >= 0) { 109518381Sralph /* if register destination, that reg is a goner */ 109618381Sralph regs[i][0] = regs[i][1] = 0; 10975794Sroot switch(type & 0xF){ 10985794Sroot case DFLOAT: /* clobber two at once */ 10995794Sroot /*FALLTHROUGH*/ 11005794Sroot case GFLOAT: 110118381Sralph regs[i+1][0] = regs[i+1][1] = 0; 11025794Sroot break; 11035794Sroot case HFLOAT: /* clobber four at once */ 110418381Sralph regs[i+1][0] = regs[i+1][1] = 0; 110518381Sralph regs[i+2][0] = regs[i+2][1] = 0; 110618381Sralph regs[i+3][0] = regs[i+3][1] = 0; 11075794Sroot break; 11085794Sroot } 11095794Sroot switch((type>>4)&0xF){ 11105794Sroot case DFLOAT: /* clobber two at once */ 11115794Sroot /*FALLTHROUGH*/ 11125794Sroot case GFLOAT: 111318381Sralph regs[i+1][0] = regs[i+1][1] = 0; 11145794Sroot break; 11155794Sroot case HFLOAT: /* clobber four at once */ 111618381Sralph regs[i+1][0] = regs[i+1][1] = 0; 111718381Sralph regs[i+2][0] = regs[i+2][1] = 0; 111818381Sralph regs[i+3][0] = regs[i+3][1] = 0; 11195794Sroot break; 11205794Sroot } 11211496Sbill } 11221496Sbill for (i=NREG; --i>=0;) 11231496Sbill if (regs[i][1]=='*' && equstr(s, regs[i]+2)) 112418381Sralph regs[i][0] = regs[i][1] = 0; /* previous indirection through destination is invalid */ 11251496Sbill while ((i = findrand(s,0)) >= 0) /* previous values of destination are invalid */ 112618381Sralph regs[i][0] = regs[i][1] = 0; 112717210Sralph if (*conloc && equstr(conloc, s)) 112817210Sralph conloc[0] = 0; 112917210Sralph setcc(s, type); /* natural destinations set condition codes */ 11301496Sbill } 11311496Sbill 113217210Sralph /* separate operands at commas, set up 'regs' and 'lastrand' */ 11331496Sbill splitrand(p) struct node *p; { 113417210Sralph register char *p1, *p2; 113517210Sralph register char **preg; 113617210Sralph 113717210Sralph preg = regs+RT1; 113817210Sralph if (p1 = p->code) 113917210Sralph while (*p1) { 114017210Sralph lastrand = p2 = *preg++; 114117210Sralph while (*p1) 114217210Sralph if (',' == (*p2++ = *p1++)) { 114317210Sralph --p2; 114417210Sralph break; 114517210Sralph } 114617210Sralph *p2 = 0; 114717210Sralph } 114817210Sralph while (preg < (regs+RT1+5)) 114917210Sralph *(*preg++) = 0; 11501496Sbill } 11511496Sbill 11521496Sbill compat(have, want) { 11531496Sbill register int hsrc, hdst; 11541496Sbill if (0==(want &= 0xF)) return(1); /* anything satisfies a wildcard want */ 115526407Sdonn hsrc=have&0xF; 115626407Sdonn if (0==(hdst=((have>>4)&0xF)) || (hdst>=OP2 && hdst<=OPX)) hdst=hsrc; 11575794Sroot if (want>=FFLOAT) return(hdst==want && hsrc==want); 11585794Sroot /* FLOAT, DFLOAT not compat: rounding */ 11595794Sroot return(hsrc>=want && hdst>=want && hdst<FFLOAT); 11601496Sbill } 11611496Sbill 11621496Sbill equtype(t1,t2) {return(compat(t1,t2) && compat(t2,t1));} 11631496Sbill 11641496Sbill findrand(as, type) 11651496Sbill char *as; 11661496Sbill { 11671496Sbill register char **i; 11681496Sbill for (i = regs+NREG; --i>=regs;) { 11691496Sbill if (**i && equstr(*i+1, as) && compat(**i,type)) 11701496Sbill return(i-regs); 11711496Sbill } 11721496Sbill return(-1); 11731496Sbill } 11741496Sbill 11751496Sbill isreg(s) 11761496Sbill register char *s; 11771496Sbill { 11781496Sbill if (*s++!='r' || !isdigit(*s++)) return(-1); 11791496Sbill if (*s==0) return(*--s-'0'); 11801496Sbill if (*(s-1)=='1' && isdigit(*s++) && *s==0) return(10+*--s-'0'); 11811496Sbill return(-1); 11821496Sbill } 11831496Sbill 11841496Sbill check() 11851496Sbill { 11861496Sbill register struct node *p, *lp; 11871496Sbill 11881496Sbill lp = &first; 11891496Sbill for (p=first.forw; p!=0; p = p->forw) { 119018381Sralph if (p->back != lp) { 119118381Sralph fprintf(stderr, "c2: failed internal consistency check -- help!\n"); 119218381Sralph exit(-1); 119318381Sralph } 11941496Sbill lp = p; 11951496Sbill } 11961496Sbill } 11971496Sbill 11981496Sbill source(ap) 11991496Sbill char *ap; 12001496Sbill { 12011496Sbill register char *p1, *p2; 12021496Sbill 12031496Sbill p1 = ap; 12041496Sbill p2 = p1; 12051496Sbill if (*p1==0) 12061496Sbill return(0); 12071496Sbill while (*p2++ && *(p2-1)!='['); 12081496Sbill if (*p1=='-' && *(p1+1)=='(' 12091496Sbill || *p1=='*' && *(p1+1)=='-' && *(p1+2)=='(' 12101496Sbill || *(p2-2)=='+') { 12111496Sbill while (*p1 && *p1++!='r'); 12121496Sbill if (isdigit(*p1++)) 121318381Sralph if (isdigit(*p1)) 121418381Sralph regs[10+*p1-'0'][0] = regs[10+*p1-'0'][1] = 0; 121518381Sralph else { 121618381Sralph --p1; 121718381Sralph regs[*p1-'0'][0] = regs[*p1-'0'][1] = 0; 121818381Sralph } 12191496Sbill return(1); 12201496Sbill } 12211496Sbill return(0); 12221496Sbill } 12231496Sbill 12241496Sbill newcode(p) struct node *p; { 12251496Sbill register char *p1,*p2,**preg; 12261496Sbill preg=regs+RT1; p2=line; 12271496Sbill while (*(p1= *preg++)) {while (*p2++= *p1++); *(p2-1)=',';} 12281496Sbill *--p2=0; 12291496Sbill p->code=copy(line); 12301496Sbill } 12311496Sbill 12321496Sbill repladdr(p) 12331496Sbill struct node *p; 12341496Sbill { 12351496Sbill register r; 123618381Sralph register char *p1; 12371496Sbill char **preg; int nrepl; 12381496Sbill 12391496Sbill preg=regs+RT1; nrepl=0; 12401496Sbill while (lastrand!=(p1= *preg++)) 12411496Sbill if (!source(p1) && 0<=(r=findrand(p1,p->subop))) { 12421496Sbill *p1++='r'; if (r>9) {*p1++='1'; r -= 10;} *p1++=r+'0'; *p1=0; 12431496Sbill nrepl++; nsaddr++; 12441496Sbill } 12451496Sbill if (nrepl) newcode(p); 12461496Sbill } 12471496Sbill 12481496Sbill /* movedat() 12491496Sbill /* { 12501496Sbill /* register struct node *p1, *p2; 12511496Sbill /* struct node *p3; 12521496Sbill /* register seg; 12531496Sbill /* struct node data; 12541496Sbill /* struct node *datp; 12551496Sbill /* 12561496Sbill /* if (first.forw == 0) 12571496Sbill /* return; 12581496Sbill /* datp = &data; 12591496Sbill /* for (p1 = first.forw; p1!=0; p1 = p1->forw) { 12601496Sbill /* if (p1->op == DATA) { 12611496Sbill /* p2 = p1->forw; 12621496Sbill /* while (p2 && p2->op!=TEXT) 12631496Sbill /* p2 = p2->forw; 12641496Sbill /* if (p2==0) 12651496Sbill /* break; 12661496Sbill /* p3 = p1->back; 12671496Sbill /* p1->back->forw = p2->forw; 12681496Sbill /* p2->forw->back = p3; 12691496Sbill /* p2->forw = 0; 12701496Sbill /* datp->forw = p1; 12711496Sbill /* p1->back = datp; 12721496Sbill /* p1 = p3; 12731496Sbill /* datp = p2; 12741496Sbill /* } 12751496Sbill /* } 12761496Sbill /* if (data.forw) { 12771496Sbill /* datp->forw = first.forw; 12781496Sbill /* first.forw->back = datp; 12791496Sbill /* data.forw->back = &first; 12801496Sbill /* first.forw = data.forw; 12811496Sbill /* } 12821496Sbill /* seg = -1; 12831496Sbill /* for (p1 = first.forw; p1!=0; p1 = p1->forw) { 12841496Sbill /* if (p1->op==TEXT||p1->op==DATA||p1->op==BSS) { 12851496Sbill /* if (p1->op == seg || p1->forw&&p1->forw->op==seg) { 12861496Sbill /* p1->back->forw = p1->forw; 12871496Sbill /* p1->forw->back = p1->back; 12881496Sbill /* p1 = p1->back; 12891496Sbill /* continue; 12901496Sbill /* } 12911496Sbill /* seg = p1->op; 12921496Sbill /* } 12931496Sbill /* } 12941496Sbill /* } 12951496Sbill */ 12961496Sbill 12971496Sbill redunbr(p) 12981496Sbill register struct node *p; 12991496Sbill { 13001496Sbill register struct node *p1; 13011496Sbill register char *ap1; 13021496Sbill char *ap2; 13031496Sbill 13041496Sbill if ((p1 = p->ref) == 0) 13051496Sbill return; 13061496Sbill p1 = nonlab(p1); 13071496Sbill if (p1->op==TST) { 13081496Sbill splitrand(p1); 13091496Sbill savereg(RT2, "$0", p1->subop); 13101496Sbill } else if (p1->op==CMP) 13111496Sbill splitrand(p1); 13121496Sbill else 13131496Sbill return; 13141496Sbill if (p1->forw->op==CBR) { 13151496Sbill ap1 = findcon(RT1, p1->subop); 13161496Sbill ap2 = findcon(RT2, p1->subop); 13171496Sbill p1 = p1->forw; 13181496Sbill if (compare(p1->subop, ap1, ap2)) { 13191496Sbill nredunj++; 13201496Sbill nchange++; 13211496Sbill decref(p->ref); 13221496Sbill p->ref = p1->ref; 13231496Sbill p->labno = p1->labno; 13241496Sbill #ifdef COPYCODE 13251496Sbill if (p->labno == 0) 13261496Sbill p->code = p1->code; 132717210Sralph #endif 13281496Sbill if (p->ref) 13291496Sbill p->ref->refc++; 13301496Sbill } 13311496Sbill } else if (p1->op==TST && equstr(regs[RT1],ccloc+1) && 13321496Sbill equtype(ccloc[0],p1->subop)) { 13331496Sbill p1=insertl(p1->forw); decref(p->ref); p->ref=p1; 13341496Sbill nrtst++; nchange++; 13351496Sbill } 13361496Sbill } 13371496Sbill 13381496Sbill char * 13391496Sbill findcon(i, type) 13401496Sbill { 13411496Sbill register char *p; 13421496Sbill register r; 13431496Sbill 13441496Sbill p = regs[i]; 13451496Sbill if (*p=='$') 13461496Sbill return(p); 13471496Sbill if ((r = isreg(p)) >= 0 && compat(regs[r][0],type)) 13481496Sbill return(regs[r]+1); 13491496Sbill if (equstr(p, conloc)) 13501496Sbill return(conval+1); 13511496Sbill return(p); 13521496Sbill } 13531496Sbill 135418381Sralph compare(opc, acp1, acp2) 13551496Sbill char *acp1, *acp2; 13561496Sbill { 13571496Sbill register char *cp1, *cp2; 13581496Sbill register n1; 13591496Sbill int n2; int sign; 13601496Sbill 13611496Sbill cp1 = acp1; 13621496Sbill cp2 = acp2; 13631496Sbill if (*cp1++ != '$' || *cp2++ != '$') 13641496Sbill return(0); 13651496Sbill n1 = 0; sign=1; if (*cp2=='-') {++cp2; sign= -1;} 13661496Sbill while (isdigit(*cp2)) {n1 *= 10; n1 += (*cp2++ - '0')*sign;} 13671496Sbill n2 = n1; 13681496Sbill n1 = 0; sign=1; if (*cp1=='-') {++cp1; sign= -1;} 13691496Sbill while (isdigit(*cp1)) {n1 *= 10; n1 += (*cp1++ - '0')*sign;} 13701496Sbill if (*cp1=='+') 13711496Sbill cp1++; 13721496Sbill if (*cp2=='+') 13731496Sbill cp2++; 13741496Sbill do { 13751496Sbill if (*cp1++ != *cp2) 13761496Sbill return(0); 13771496Sbill } while (*cp2++); 137818381Sralph switch(opc) { 13791496Sbill 13801496Sbill case JEQ: 138118381Sralph return(n1 == n2); 13821496Sbill case JNE: 138318381Sralph return(n1 != n2); 13841496Sbill case JLE: 138518381Sralph return(n1 <= n2); 13861496Sbill case JGE: 138718381Sralph return(n1 >= n2); 13881496Sbill case JLT: 138918381Sralph return(n1 < n2); 13901496Sbill case JGT: 139118381Sralph return(n1 > n2); 13921496Sbill case JLO: 139318381Sralph return((unsigned) n1 < (unsigned) n2); 13941496Sbill case JHI: 139518381Sralph return((unsigned) n1 > (unsigned) n2); 13961496Sbill case JLOS: 139718381Sralph return((unsigned) n1 <= (unsigned) n2); 13981496Sbill case JHIS: 139918381Sralph return((unsigned) n1 >= (unsigned) n2); 14001496Sbill } 14011496Sbill return(0); 14021496Sbill } 14031496Sbill 14041496Sbill setcon(cv, cl, type) 14051496Sbill register char *cv, *cl; 14061496Sbill { 14071496Sbill register char *p; 14081496Sbill 14091496Sbill if (*cv != '$') 14101496Sbill return; 14111496Sbill if (!natural(cl)) 14121496Sbill return; 14131496Sbill p = conloc; 14141496Sbill while (*p++ = *cl++); 14151496Sbill p = conval; 14161496Sbill *p++ = type; 14171496Sbill while (*p++ = *cv++); 14181496Sbill } 14191496Sbill 14201496Sbill equstr(p1, p2) 14211496Sbill register char *p1, *p2; 14221496Sbill { 14231496Sbill do { 14241496Sbill if (*p1++ != *p2) 14251496Sbill return(0); 14261496Sbill } while (*p2++); 14271496Sbill return(1); 14281496Sbill } 14291496Sbill 14301496Sbill setcc(ap,type) 14311496Sbill char *ap; 14321496Sbill { 14331496Sbill register char *p, *p1; 14341496Sbill 14351496Sbill p = ap; 14361496Sbill if (!natural(p)) { 14371496Sbill ccloc[0] = 0; 14381496Sbill return; 14391496Sbill } 14401496Sbill p1 = ccloc; 14411496Sbill *p1++ = type; 14421496Sbill while (*p1++ = *p++); 14431496Sbill } 14441496Sbill 14451496Sbill okio(p) register char *p; {/* 0->probable I/O space address; 1->not */ 14461496Sbill if (ioflag && (!natural(p) || 0>getnum(p))) return(0); 14471496Sbill return(1); 14481496Sbill } 14491496Sbill 14501496Sbill indexa(p) register char *p; {/* 1-> uses [r] addressing mode; 0->doesn't */ 14511496Sbill while (*p) if (*p++=='[') return(1); 14521496Sbill return(0); 14531496Sbill } 14541496Sbill 14551496Sbill natural(p) 14561496Sbill register char *p; 14571496Sbill {/* 1->simple local, parameter, global, or register; 0->otherwise */ 145817210Sralph if (*p=='*' || *p=='(' || *p=='-'&&p[1]=='(' || *p=='$'&&getnum(p+1)) 14591496Sbill return(0); 14601496Sbill while (*p++); 14611496Sbill p--; 146217210Sralph if (*--p=='+' || *p==']' || *p==')' && p[-2]!='a' && p[-2]!='f') 14631496Sbill return(0); 14641496Sbill return(1); 14651496Sbill } 14661496Sbill 14671496Sbill /* 14681496Sbill ** Tell if an argument is most likely static. 14691496Sbill */ 14701496Sbill 14711496Sbill isstatic(cp) 14721496Sbill register char *cp; 14731496Sbill { 14741496Sbill if (*cp == '_' || *cp == 'L' || (*cp++ == 'v' && *cp == '.')) 14751496Sbill return (1); 14761496Sbill return (0); 14771496Sbill } 147816133Sralph 147916133Sralph autoid(p) register char *p; {/* 1-> uses autoincrement/autodecrement; 0->doesn't */ 148016133Sralph if (*p == '-' && *(p+1) == '(') return(1); 148116133Sralph while (*p) p++; 148216133Sralph if (*--p == '+' && *--p == ')') return(1); 148316133Sralph return(0); 148416133Sralph } 1485