118381Sralph #ifndef lint 2*27461Sdonn static char sccsid[] = "@(#)c21.c 4.19 04/27/86"; 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 */ 226958Srrh 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) { 5801496Sbill if (equtype(p->subop,regs[r][0]) 5811496Sbill || ((p->op==CVT || p->op==MOVZ) 5821496Sbill && 0xf®s[r][0] && compat(0xf&(p->subop>>4),regs[r][0]))) { 5831496Sbill register int r2; 5841496Sbill if (regs[r][1]!=0) {/* send directly to destination */ 5851496Sbill if (p->op==INC || p->op==DEC) { 5861496Sbill if (p->op==DEC) p->op=SUB; else p->op=ADD; 5871496Sbill p->subop=(OP2<<4)+(p->subop&0xF); /* use 2 now, convert to 3 later */ 5881496Sbill p->pop=0; 5891496Sbill cp1=lastrand; cp2=regs[RT2]; while (*cp2++= *cp1++); /* copy reg */ 5901496Sbill cp1=lastrand; *cp1++='$'; *cp1++='1'; *cp1=0; 5911496Sbill } 5921496Sbill cp1=regs[r]+1; cp2=lastrand; 5931496Sbill if (OP2==(p->subop>>4)) {/* use 3 operand form of instruction */ 5941496Sbill p->pop=0; 5951496Sbill p->subop += (OP3-OP2)<<4; lastrand=cp2=regs[RT3]; 5961496Sbill } 5971496Sbill while (*cp2++= *cp1++); 5981496Sbill if (p->op==MOVA && p->forw->op==PUSH) { 5991496Sbill p->op=PUSHA; *regs[RT2]=0; p->pop=0; 6001496Sbill } else if (p->op==MOV && p->forw->op==PUSH) { 6011496Sbill p->op=PUSH ; *regs[RT2]=0; p->pop=0; 6021496Sbill } 6031496Sbill delnode(p->forw); 6041496Sbill if (0<=(r2=isreg(lastrand)) && r2<NUSE) { 6051496Sbill uses[r2]=uses[r]; uses[r]=0; 6061496Sbill } 60718381Sralph (void) redun3(p,0); 6081496Sbill newcode(p); redunm++; flow=r; 6091496Sbill } else if (p->op==MOV && p->forw->op!=EXTV && p->forw->op!=EXTZV) { 6101496Sbill /* superfluous fetch */ 6111496Sbill int nmatch; 6122829Stoy char src[C2_ASIZE]; 6131496Sbill movit: 6141496Sbill cp2=src; cp1=regs[RT1]; while (*cp2++= *cp1++); 6151496Sbill splitrand(p->forw); 6161496Sbill if (p->forw->op != INC && p->forw->op != DEC) 6171496Sbill lastrand=byondrd(p->forw); 6181496Sbill nmatch=0; 6191496Sbill for (preg=regs+RT1;*preg!=lastrand;preg++) 6201496Sbill if (r==isreg(*preg)) { 6211496Sbill cp2= *preg; cp1=src; while (*cp2++= *cp1++); ++nmatch; 6221496Sbill } 6231496Sbill if (nmatch==1) { 6241496Sbill if (OP2==(p->forw->subop>>4) && equstr(src,regs[RT2])) { 6251496Sbill p->forw->pop=0; 6261496Sbill p->forw->subop += (OP3-OP2)<<4; cp1=regs[RT3]; 6271496Sbill *cp1++='r'; *cp1++=r+'0'; *cp1=0; 6281496Sbill } 6291496Sbill delnode(p); p=p->forw; 6301496Sbill if (0<=(r2=isreg(src)) && r2<NUSE) { 6311496Sbill uses[r2]=uses[r]; uses[r]=0; 6321496Sbill } 63318381Sralph (void) redun3(p,0); 6341496Sbill newcode(p); redunm++; flow=r; 6351496Sbill } else splitrand(p); 6361496Sbill } 6371496Sbill } else if (p->op==MOV && (p->forw->op==CVT || p->forw->op==MOVZ) 6381496Sbill && p->forw->subop&0xf /* if base or index, then forget it */ 6391496Sbill && compat(p->subop,p->forw->subop) && !source(cp1=regs[RT1]) 6401496Sbill && !indexa(cp1)) goto movit; 6411496Sbill } 6421496Sbill /* adjust 'lastrand' past any 'read' or 'modify' operands. */ 6431496Sbill lastrand=byondrd(p); 6441496Sbill /* a 'write' clobbers the register. */ 6451496Sbill if (0<=(r=isreg(lastrand)) && r<NUSE 6461496Sbill || OP2==(p->subop>>4) && 0<=(r=isreg(regs[RT2])) && r<NUSE && uses[r]==0) { 6471496Sbill /* writing a dead register is useless, but watch side effects */ 6481496Sbill switch (p->op) { 6491498Sbill case ACB: 6501496Sbill case AOBLEQ: case AOBLSS: case SOBGTR: case SOBGEQ: break; 6511498Sbill default: 6521496Sbill if (uses[r]==0) {/* no direct uses, check for use of condition codes */ 6531496Sbill register struct node *q=p; 6541496Sbill while ((q=nonlab(q->forw))->combop==JBR) q=q->ref; /* cc unused, unchanged */ 6551496Sbill if (q->op!=CBR) {/* ... and destroyed */ 6561496Sbill preg=regs+RT1; 6571496Sbill while (cp1= *preg++) { 6581496Sbill if (cp1==lastrand) {redunm++; delnode(p); return(p->forw);} 6591496Sbill if (source(cp1) || equstr(cp1,lastrand)) break; 6601496Sbill } 6611496Sbill } 6621496Sbill } 6631496Sbill flow=r; 6641496Sbill } 6651496Sbill } 66618381Sralph if (0<=(r=flow)) { 66718381Sralph olduse=uses[r]; 66818381Sralph uses[r]=0; 66918381Sralph regs[r][0]=regs[r][1]=0; 67018381Sralph } 6711496Sbill /* these two are here, rather than in bmove(), 6721496Sbill /* because I decided that it was better to go for 3-address code 6731496Sbill /* (save time) rather than fancy jbxx (save 1 byte) 6741496Sbill /* on sequences like bisl2 $64,r0; movl r0,foo 6751496Sbill */ 6761496Sbill if (p->op==BIC) {p=bicopt(p); splitrand(p); lastrand=byondrd(p);} 67718381Sralph if (p->op==BIS) {(void) bixprep(p,JBSS); lastrand=byondrd(p);} 6781496Sbill /* now look for 'read' or 'modify' (read & write) uses */ 6791496Sbill preg=regs+RT1; 6801496Sbill while (*(cp1= *preg++)) { 6811496Sbill /* check for r */ 6821496Sbill if (lastrand!=cp1 && 0<=(r=isreg(cp1)) && r<NUSE && uses[r]==0) { 6831496Sbill uses[r]=p; cp2=regs[r]; *cp2++=p->subop; 6841506Sbill if (p->op==ASH && preg==(regs+RT1+1)) cp2[-1]=BYTE; /* stupid DEC */ 6851496Sbill if (p->op==MOV || p->op==PUSH || p->op==CVT || p->op==MOVZ || p->op==COM || p->op==NEG) { 6861496Sbill if (p->op==PUSH) cp1="-(sp)"; 6871496Sbill else { 6881496Sbill cp1=regs[RT2]; 6891496Sbill if (0<=(r=isreg(cp1)) && r<NUSE && uses[r]==0) 6901496Sbill uses[r]=olduse; /* reincarnation!! */ 6911496Sbill /* as in addl2 r0,r1; movl r1,r0; ret */ 6921496Sbill if (p->op!=MOV) cp1=0; 6931496Sbill } 6941496Sbill if (cp1) while (*cp2++= *cp1++); 6951506Sbill else *cp2=0; 6961506Sbill } else *cp2=0; 6971496Sbill continue; 6981496Sbill } 6991496Sbill /* check for (r),(r)+,-(r),[r] */ 7001496Sbill do if (*cp1=='(' || *cp1=='[') {/* get register number */ 7011496Sbill char t; 7021496Sbill cp2= ++cp1; while (*++cp1!=')' && *cp1!=']'); t= *cp1; *cp1=0; 7031496Sbill if (0<=(r=isreg(cp2)) && r<NUSE && (uses[r]==0 || uses[r]==p)) { 7041496Sbill uses[r]=p; regs[r][0]=(*--cp2=='[' ? OPX<<4 : OPB<<4); 7051496Sbill } 7061496Sbill *cp1=t; 7071496Sbill } while (*++cp1); 7081496Sbill } 7091496Sbill /* pushax or movax possibility? */ 7101496Sbill cp1=regs[RT1]; 7111496Sbill if (*cp1++=='$' && isstatic(cp1) && natural(regs[RT1])) { 7121496Sbill if (p->combop==T(MOV,LONG)) { 7131496Sbill if (regs[RT1][1]=='L' && 0!=(p->labno=getnum(regs[RT1]+2))) { 7141496Sbill cp1=p->code; while (*cp1++!=','); p->code= --cp1; 7151496Sbill } 7161496Sbill p->combop=T(MOVA,LONG); ++p->code; p->pop=0; 7171496Sbill } else if (p->combop==T(PUSH,LONG)) { 7181496Sbill p->combop=T(PUSHA,LONG); ++p->code; p->pop=0; 7191496Sbill } else if ((p->combop&0xFFFF)==T(ADD,U(LONG,OP3)) 7201496Sbill && 0<=(r=isreg(regs[RT2]))) { 7211496Sbill cp1=cp2=p->code; ++cp1; 7221496Sbill do *cp2++= *cp1; while (*cp1++!=','); cp2[-1]='['; 7231496Sbill do *cp2++= *cp1; while (*cp1++!=','); cp2[-1]=']'; 7241496Sbill if (!equstr(regs[RT3],"-(sp)")) p->combop=T(MOVA,BYTE); 7251496Sbill else {p->combop=T(PUSHA,BYTE); *cp2=0;} 72624399Smckusick if (r < NUSE && uses[r] == 0) { 72724399Smckusick uses[r]=p; 72824399Smckusick regs[r][0]=OPX<<4; 72924399Smckusick } 7301496Sbill p->pop=0; 7311496Sbill } 7321496Sbill } 7331496Sbill return(p); 7341496Sbill } 7351496Sbill 7361496Sbill ispow2(n) register long n; {/* -1 -> no; else -> log to base 2 */ 7371496Sbill register int log; 7381496Sbill if (n==0 || n&(n-1)) return(-1); log=0; 7391496Sbill for (;;) {n >>= 1; if (n==0) return(log); ++log; if (n== -1) return(log);} 7401496Sbill } 7411496Sbill 7421496Sbill bitopt(p) register struct node *p; { 7431496Sbill /* change "bitx $<power_of_2>,a" followed by JEQ or JNE 7441496Sbill /* into JBC or JBS. watch out for I/O registers. (?) 7451496Sbill /* assumes that 'splitrand' has already been called. 7461496Sbill */ 7471496Sbill register char *cp1,*cp2; int b; 7481496Sbill cp1=regs[RT1]; cp2=regs[RT2]; 7491496Sbill if (*cp1++!='$' || !okio(cp2) || p->forw->op!=CBR || p->forw->subop&-2 || 750*27461Sdonn 0>(b=ispow2(getnum(cp1)))) return; 751*27461Sdonn if (p->subop!=BYTE && !(b==0 && p->subop==LONG) && 752*27461Sdonn (source(cp2) || indexa(cp2))) return; 7531496Sbill if (b>=bitsize[p->subop]) {/* you dummy! */ 7541496Sbill if (source(cp2)) {/* side effect: auto increment or decrement */ 7551496Sbill p->pop=0; 7561496Sbill p->op=TST; --cp1; while (*cp1++= *cp2++); 7571496Sbill regs[RT2][0]=0; newcode(p); 7581496Sbill } else delnode(p); 7591496Sbill p = p->forw; 7601496Sbill if (p->subop==JEQ) {p->combop=JBR; p->pop=0;} 7611496Sbill else delnode(p); 7621496Sbill nchange++; nbj++; return; 7631496Sbill } 7641496Sbill if (cp1=p->forw->code) {/* destination is not an internal label */ 7651496Sbill cp2=regs[RT3]; while (*cp2++= *cp1++); 7661496Sbill } 767*27461Sdonn if (b==0 && (p->subop==LONG || !(source(regs[RT2]) || indexa(regs[RT2])))) { 768*27461Sdonn /* JLB optimization, ala BLISS */ 7691496Sbill cp2=regs[RT1]; cp1=regs[RT2]; while (*cp2++= *cp1++); 7701496Sbill cp2=regs[RT2]; cp1=regs[RT3]; while (*cp2++= *cp1++); 7711496Sbill *(regs[RT3])=0; p->forw->subop += JLBC-JBC; 7721496Sbill p->forw->pop=0; 7731496Sbill } else { 7741496Sbill cp1=regs[RT1]+1; 7751496Sbill if (b>9) *cp1++= b/10 +'0'; *cp1++= b%10 +'0'; *cp1=0; /* $<bit_number> */ 7761496Sbill } 7771496Sbill nbj++; newcode(p); p->combop = p->forw->combop+((JBC-JEQ)<<8); 7781496Sbill p->labno = p->forw->labno; delnode(p->forw); 7791496Sbill p->pop=0; 7801496Sbill } 7811496Sbill 7821496Sbill isfield(n) register long n; {/* -1 -> no; else -> position of low bit */ 78318381Sralph register int p; register long t; 7841496Sbill t= ((n-1)|n) +1; 78516832Sralph if (n!=0 && (0==t || 0<=ispow2(t))) { 78618381Sralph p=0; while(!(n&1)) {n >>= 1; ++p;} return(p); 7871496Sbill } else return(-1); 7881496Sbill } 7891496Sbill 7901496Sbill bixprep(p,bix) register struct node *p; { 7911496Sbill /* initial setup, single-bit checking for bisopt, bicopt. 7921496Sbill /* return: 0->don't bother any more; 1->worthwhile trying 7931496Sbill */ 7941496Sbill register char *cp1,*cp2; 7951496Sbill splitrand(p); cp1=regs[RT1]; cp2=regs[RT2]; 7961496Sbill if (*cp1++!='$' || 0>(pos=isfield(f=getnum(cp1))) 7971496Sbill || !okio(cp2) || indexa(cp2) || source(cp2) || !okio(lastrand)) return(0); 7981496Sbill f |= f-1; if (++f==0) siz=32-pos; else siz=ispow2(f)-pos; 7991496Sbill if (siz==1 && pos>5 && (p->subop>>4)==OP2 && (p->subop&0xF)!=BYTE 8001496Sbill && pos<bitsize[p->subop&0xF]) { 8011496Sbill p->ref = insertl(p->forw); p->combop = CBR | (bix<<8); 8021496Sbill p->pop=0; 8031496Sbill p->labno = p->ref->labno; 8041496Sbill if (pos>9) {*cp1++= pos/10 +'0'; pos %= 10;} 8051496Sbill *cp1++=pos+'0'; *cp1=0; newcode(p); nbj++; return(0); 8061496Sbill } 8071496Sbill return(1); 8081496Sbill } 8091496Sbill 8101496Sbill 8111496Sbill struct node * 8121496Sbill bicopt(p) register struct node *p; { 8131496Sbill /* use field operations or MOVZ if possible. done as part of 'bflow'. 8141496Sbill */ 8151496Sbill register char *cp1,*cp2; int r; 8163933Sroot char src[C2_ASIZE]; 81718381Sralph char lhssiz, sop; 8181496Sbill if (!bixprep(p,JBCC)) return(p); 8191496Sbill if (f==0) {/* the BIC isolates low order bits */ 8201496Sbill siz=pos; pos=0; 8211496Sbill if ((p->subop&0xF)==LONG && *(regs[RT2])!='$') {/* result of EXTZV is long */ 8221496Sbill /* save source of BICL in 'src' */ 8231496Sbill cp1=regs[RT2]; cp2=src; while (*cp2++= *cp1++); 8241496Sbill if (p->back->op==ASH) {/* try for more */ 8251496Sbill splitrand(p->back); cp1=regs[RT1]; cp2=regs[RT3]; 8261496Sbill if (*cp1++=='$' && *(regs[RT2])!='$' && !indexa(regs[RT2]) 8271496Sbill && 0>(f=getnum(cp1)) && equstr(src,cp2) 82816832Sralph && 0<=(r=isreg(cp2)) && r<NUSE 82916832Sralph && siz-f <= 32) { /* a good ASH */ 8301496Sbill pos -= f; cp1=regs[RT2]; cp2=src; while (*cp2++= *cp1++); 8311496Sbill delnode(p->back); 8321496Sbill } 8331496Sbill } 83416133Sralph /* 83516133Sralph * 'pos', 'siz' known; find out the size of the 83616133Sralph * left-hand operand of what the bicl will turn into. 83716133Sralph */ 83816133Sralph if (pos==0 && siz==16) 83916133Sralph lhssiz = WORD; /* movzwl */ 84016133Sralph else 84116133Sralph lhssiz = BYTE; /* movzbl or extzvl */ 8421496Sbill if (p->back->op==CVT || p->back->op==MOVZ) {/* greedy, aren't we? */ 8431496Sbill splitrand(p->back); cp1=regs[RT1]; cp2=regs[RT2]; 84416133Sralph /* 84516133Sralph * If indexa(cp1) || autoid(cp1), the fold may 84616133Sralph * still be OK if the CVT/MOVZ has the same 84716133Sralph * size operand on its left size as what we 84816133Sralph * will turn the bicl into. 84916133Sralph * However, if the CVT is from a float or 85016133Sralph * double, forget it! 85116133Sralph */ 85218381Sralph sop = p->back->subop&0xF; /* type of LHS of CVT/MOVZ */ 85316133Sralph if (equstr(src,cp2) && okio(cp1) 85418381Sralph && sop != FFLOAT && sop != DFLOAT 85518381Sralph && sop != GFLOAT && sop != HFLOAT 85618381Sralph && ((!indexa(cp1) && !autoid(cp1)) || lhssiz == sop) 8571496Sbill && 0<=(r=isreg(cp2)) && r<NUSE 85818381Sralph && bitsize[sop]>=(pos+siz) 8591496Sbill && bitsize[p->back->subop>>4]>=(pos+siz)) {/* good CVT */ 8601496Sbill cp1=regs[RT1]; cp2=src; while (*cp2++= *cp1++); 8611496Sbill delnode(p->back); 8621496Sbill } 8631496Sbill } 8641496Sbill /* 'pos', 'siz' known; source of field is in 'src' */ 8651496Sbill splitrand(p); /* retrieve destination of BICL */ 86616133Sralph if ((siz==8 || siz==16) && pos==0) { 86716133Sralph p->combop = T(MOVZ,U(lhssiz,LONG)); 8681496Sbill sprintf(line,"%s,%s",src,lastrand); 8691496Sbill } else { 8701496Sbill p->combop = T(EXTZV,LONG); 8711496Sbill sprintf(line,"$%d,$%d,%s,%s",pos,siz,src,lastrand); 8721496Sbill } 8731496Sbill p->pop=0; 8741496Sbill p->code = copy(line); nfield++; return(p); 8751496Sbill }/* end EXTZV possibility */ 8761496Sbill }/* end low order bits */ 8771496Sbill /* unfortunately, INSV clears the condition codes, thus cannot be used */ 8781496Sbill /* else {/* see if BICL2 of positive field should be INSV $0 */ 8791496Sbill /* if (p->subop==(LONG | (OP2<<4)) && 6<=(pos+siz)) { 8801496Sbill /* p->combop = INSV; 8811496Sbill /* sprintf(line,"$0,$%d,$%d,%s",pos,siz,lastrand); 8821496Sbill /* p->code = copy(line); nfield++; return(p); 8831496Sbill /* } 8841496Sbill /* } 8851496Sbill */ 8861496Sbill return(p); 8871496Sbill } 8881496Sbill 8891496Sbill jumpsw() 8901496Sbill { 8911496Sbill register struct node *p, *p1; 89218381Sralph register struct node *tp; 89318381Sralph long tl; 89418381Sralph char *tcp; 89518381Sralph int ti; 8961496Sbill int nj; 8971496Sbill 89818381Sralph ti = 0; 8991496Sbill nj = 0; 9001496Sbill for (p=first.forw; p!=0; p = p->forw) 90118381Sralph p->seq = ++ti; 9021496Sbill for (p=first.forw; p!=0; p = p1) { 9031496Sbill p1 = p->forw; 9041496Sbill if (p->op == CBR && p1->op==JBR && p->ref && p1->ref 9051496Sbill && abs(p->seq - p->ref->seq) > abs(p1->seq - p1->ref->seq)) { 9061496Sbill if (p->ref==p1->ref) 9071496Sbill continue; 9081496Sbill p->subop = revbr[p->subop]; 9091496Sbill p->pop=0; 91018381Sralph tp = p1->ref; 9111496Sbill p1->ref = p->ref; 91218381Sralph p->ref = tp; 91318381Sralph tl = p1->labno; 9141496Sbill p1->labno = p->labno; 91518381Sralph p->labno = tl; 9161496Sbill #ifdef COPYCODE 9171496Sbill if (p->labno == 0) { 91818381Sralph tcp = p1->code; 91918381Sralph p1->code = p->code; 92018381Sralph p->code = tcp; 9211496Sbill } 9221496Sbill #endif 9231496Sbill nrevbr++; 9241496Sbill nj++; 9251496Sbill } 9261496Sbill } 9271496Sbill return(nj); 9281496Sbill } 9291496Sbill 9301496Sbill addsob() 9311496Sbill { 9321496Sbill register struct node *p, *p1, *p2, *p3; 9331496Sbill 9341496Sbill for (p = &first; (p1 = p->forw)!=0; p = p1) { 9351496Sbill if (p->combop==T(DEC,LONG) && p1->op==CBR) { 9363933Sroot if (abs(p->seq - p1->ref->seq) > 8) continue; 9371496Sbill if (p1->subop==JGE || p1->subop==JGT) { 9381496Sbill if (p1->subop==JGE) p->combop=SOBGEQ; else p->combop=SOBGTR; 9391496Sbill p->pop=0; 9401496Sbill p->labno = p1->labno; delnode(p1); nsob++; 9411496Sbill } 9421496Sbill } else if (p->combop==T(INC,LONG)) { 9431496Sbill if (p1->op==LABEL && p1->refc==1 && p1->forw->combop==T(CMP,LONG) 9441496Sbill && (p2=p1->forw->forw)->combop==T(CBR,JLE) 9451496Sbill && (p3=p2->ref->back)->combop==JBR && p3->ref==p1 9461496Sbill && p3->forw->op==LABEL && p3->forw==p2->ref) { 9471496Sbill /* change INC LAB: CMP to LAB: INC CMP */ 9481496Sbill p->back->forw=p1; p1->back=p->back; 9491496Sbill p->forw=p1->forw; p1->forw->back=p; 9501496Sbill p->back=p1; p1->forw=p; 9511496Sbill p1=p->forw; 9521496Sbill /* adjust beginning value by 1 */ 9531496Sbill p2=alloc(sizeof first); p2->combop=T(DEC,LONG); 9541496Sbill p2->pop=0; 9551496Sbill p2->forw=p3; p2->back=p3->back; p3->back->forw=p2; 9561496Sbill p3->back=p2; p2->code=p->code; p2->labno=0; 9571496Sbill } 9581496Sbill if (p1->combop==T(CMP,LONG) && (p2=p1->forw)->op==CBR) { 9591496Sbill register char *cp1,*cp2; 9601496Sbill splitrand(p1); if (!equstr(p->code,regs[RT1])) continue; 9613933Sroot if (abs(p->seq - p2->ref->seq)>8) {/* outside byte displ range */ 9621496Sbill if (p2->subop!=JLE) continue; 9631496Sbill p->combop=T(ACB,LONG); 9641496Sbill cp2=regs[RT1]; cp1=regs[RT2]; while (*cp2++= *cp1++); /* limit */ 9651496Sbill cp2=regs[RT2]; cp1="$1"; while (*cp2++= *cp1++); /* increment */ 9661496Sbill cp2=regs[RT3]; cp1=p->code; while (*cp2++= *cp1++); /* index */ 9671496Sbill p->pop=0; newcode(p); 9681496Sbill p->labno = p2->labno; delnode(p2); delnode(p1); nsob++; 9691496Sbill } else if (p2->subop==JLE || p2->subop==JLT) { 9701496Sbill if (p2->subop==JLE) p->combop=AOBLEQ; else p->combop=AOBLSS; 9711496Sbill cp2=regs[RT1]; cp1=regs[RT2]; while (*cp2++= *cp1++); /* limit */ 9721496Sbill cp2=regs[RT2]; cp1=p->code; while (*cp2++= *cp1++); /* index */ 9731496Sbill p->pop=0; newcode(p); 9741496Sbill p->labno = p2->labno; delnode(p2); delnode(p1); nsob++; 9751496Sbill } 9761496Sbill } 9771496Sbill } 9781496Sbill } 9791496Sbill } 9801496Sbill 9811496Sbill equop(p1, p2) 9821496Sbill register struct node *p1; 9831496Sbill struct node *p2; 9841496Sbill { 9851496Sbill register char *cp1, *cp2; 9861496Sbill 9871496Sbill if (p1->combop != p2->combop) 9881496Sbill return(0); 9891496Sbill if (p1->op>0 && p1->op<MOV) 9901496Sbill return(0); 99118381Sralph switch (p1->combop) { 99218381Sralph case EROU: case JSW: case TEXT: case DATA: 99318381Sralph case BSS: case ALIGN: case WGEN: case END: 99418381Sralph /* 99518381Sralph * Consider all pseudo-ops to be unique. 99618381Sralph */ 99718381Sralph return(0); 99818381Sralph } 9991496Sbill if (p1->op==MOVA && p1->labno!=p2->labno) return(0); 10001496Sbill cp1 = p1->code; 10011496Sbill cp2 = p2->code; 10021496Sbill if (cp1==0 && cp2==0) 10031496Sbill return(1); 10041496Sbill if (cp1==0 || cp2==0) 10051496Sbill return(0); 10061496Sbill while (*cp1 == *cp2++) 10071496Sbill if (*cp1++ == 0) 10081496Sbill return(1); 10091496Sbill return(0); 10101496Sbill } 10111496Sbill 101218381Sralph #ifndef delnode 10131496Sbill delnode(p) register struct node *p; { 10141496Sbill p->back->forw = p->forw; 10151496Sbill p->forw->back = p->back; 10161496Sbill } 101718381Sralph #endif 10181496Sbill 101918381Sralph #ifndef decref 10201496Sbill decref(p) 10211496Sbill register struct node *p; 10221496Sbill { 10231496Sbill if (p && --p->refc <= 0) { 10241496Sbill nrlab++; 10251496Sbill delnode(p); 10261496Sbill } 10271496Sbill } 102818381Sralph #endif 10291496Sbill 10301496Sbill struct node * 10311496Sbill nonlab(ap) 10321496Sbill struct node *ap; 10331496Sbill { 10341496Sbill register struct node *p; 10351496Sbill 10361496Sbill p = ap; 10371496Sbill while (p && p->op==LABEL) 10381496Sbill p = p->forw; 10391496Sbill return(p); 10401496Sbill } 10411496Sbill 10421496Sbill clearuse() { 10431496Sbill register struct node **i; 10441496Sbill for (i=uses+NUSE; i>uses;) *--i=0; 10451496Sbill } 10461496Sbill 10471496Sbill clearreg() { 104818381Sralph register char **i; 104918381Sralph for (i=regs; i<regs+NREG; ++i) { 105018381Sralph **i = 0; 105118381Sralph *(*i+1) = 0; 105218381Sralph } 105318381Sralph conloc[0] = 0; 105418381Sralph ccloc[0] = 0; 10551496Sbill } 10561496Sbill 10571496Sbill savereg(ai, s, type) 10581496Sbill register char *s; 10591496Sbill { 10601496Sbill register char *p, *sp; 10611496Sbill 10621496Sbill sp = p = regs[ai]; 10631496Sbill if (source(s)) /* side effects in addressing */ 10641496Sbill return; 10651496Sbill /* if any indexing, must be parameter or local */ 10661496Sbill /* indirection (as in "*-4(fp)") is ok, however */ 10671496Sbill *p++ = type; 10681496Sbill while (*p++ = *s) 10691496Sbill if (*s=='[' || *s++=='(' && *s!='a' && *s!='f') {*sp = 0; return;} 10701496Sbill } 10711496Sbill 10721496Sbill dest(s,type) 10731496Sbill register char *s; 10741496Sbill { 10751496Sbill register int i; 10761496Sbill 107718381Sralph (void) source(s); /* handle addressing side effects */ 107817210Sralph if (!natural(s)) { 107917210Sralph /* wild store, everything except constants vanishes */ 108017210Sralph for (i=NREG; --i>=0;) 108118381Sralph if (regs[i][1] != '$') 108218381Sralph regs[i][0] = regs[i][1] = 0; 108317210Sralph conloc[0] = 0; ccloc[0] = 0; 108417210Sralph return; 108517210Sralph } 10861496Sbill if ((i = isreg(s)) >= 0) { 108718381Sralph /* if register destination, that reg is a goner */ 108818381Sralph regs[i][0] = regs[i][1] = 0; 10895794Sroot switch(type & 0xF){ 10905794Sroot case DFLOAT: /* clobber two at once */ 10915794Sroot /*FALLTHROUGH*/ 10925794Sroot case GFLOAT: 109318381Sralph regs[i+1][0] = regs[i+1][1] = 0; 10945794Sroot break; 10955794Sroot case HFLOAT: /* clobber four at once */ 109618381Sralph regs[i+1][0] = regs[i+1][1] = 0; 109718381Sralph regs[i+2][0] = regs[i+2][1] = 0; 109818381Sralph regs[i+3][0] = regs[i+3][1] = 0; 10995794Sroot break; 11005794Sroot } 11015794Sroot switch((type>>4)&0xF){ 11025794Sroot case DFLOAT: /* clobber two at once */ 11035794Sroot /*FALLTHROUGH*/ 11045794Sroot case GFLOAT: 110518381Sralph regs[i+1][0] = regs[i+1][1] = 0; 11065794Sroot break; 11075794Sroot case HFLOAT: /* clobber four at once */ 110818381Sralph regs[i+1][0] = regs[i+1][1] = 0; 110918381Sralph regs[i+2][0] = regs[i+2][1] = 0; 111018381Sralph regs[i+3][0] = regs[i+3][1] = 0; 11115794Sroot break; 11125794Sroot } 11131496Sbill } 11141496Sbill for (i=NREG; --i>=0;) 11151496Sbill if (regs[i][1]=='*' && equstr(s, regs[i]+2)) 111618381Sralph regs[i][0] = regs[i][1] = 0; /* previous indirection through destination is invalid */ 11171496Sbill while ((i = findrand(s,0)) >= 0) /* previous values of destination are invalid */ 111818381Sralph regs[i][0] = regs[i][1] = 0; 111917210Sralph if (*conloc && equstr(conloc, s)) 112017210Sralph conloc[0] = 0; 112117210Sralph setcc(s, type); /* natural destinations set condition codes */ 11221496Sbill } 11231496Sbill 112417210Sralph /* separate operands at commas, set up 'regs' and 'lastrand' */ 11251496Sbill splitrand(p) struct node *p; { 112617210Sralph register char *p1, *p2; 112717210Sralph register char **preg; 112817210Sralph 112917210Sralph preg = regs+RT1; 113017210Sralph if (p1 = p->code) 113117210Sralph while (*p1) { 113217210Sralph lastrand = p2 = *preg++; 113317210Sralph while (*p1) 113417210Sralph if (',' == (*p2++ = *p1++)) { 113517210Sralph --p2; 113617210Sralph break; 113717210Sralph } 113817210Sralph *p2 = 0; 113917210Sralph } 114017210Sralph while (preg < (regs+RT1+5)) 114117210Sralph *(*preg++) = 0; 11421496Sbill } 11431496Sbill 11441496Sbill compat(have, want) { 11451496Sbill register int hsrc, hdst; 11461496Sbill if (0==(want &= 0xF)) return(1); /* anything satisfies a wildcard want */ 114726407Sdonn hsrc=have&0xF; 114826407Sdonn if (0==(hdst=((have>>4)&0xF)) || (hdst>=OP2 && hdst<=OPX)) hdst=hsrc; 11495794Sroot if (want>=FFLOAT) return(hdst==want && hsrc==want); 11505794Sroot /* FLOAT, DFLOAT not compat: rounding */ 11515794Sroot return(hsrc>=want && hdst>=want && hdst<FFLOAT); 11521496Sbill } 11531496Sbill 11541496Sbill equtype(t1,t2) {return(compat(t1,t2) && compat(t2,t1));} 11551496Sbill 11561496Sbill findrand(as, type) 11571496Sbill char *as; 11581496Sbill { 11591496Sbill register char **i; 11601496Sbill for (i = regs+NREG; --i>=regs;) { 11611496Sbill if (**i && equstr(*i+1, as) && compat(**i,type)) 11621496Sbill return(i-regs); 11631496Sbill } 11641496Sbill return(-1); 11651496Sbill } 11661496Sbill 11671496Sbill isreg(s) 11681496Sbill register char *s; 11691496Sbill { 11701496Sbill if (*s++!='r' || !isdigit(*s++)) return(-1); 11711496Sbill if (*s==0) return(*--s-'0'); 11721496Sbill if (*(s-1)=='1' && isdigit(*s++) && *s==0) return(10+*--s-'0'); 11731496Sbill return(-1); 11741496Sbill } 11751496Sbill 11761496Sbill check() 11771496Sbill { 11781496Sbill register struct node *p, *lp; 11791496Sbill 11801496Sbill lp = &first; 11811496Sbill for (p=first.forw; p!=0; p = p->forw) { 118218381Sralph if (p->back != lp) { 118318381Sralph fprintf(stderr, "c2: failed internal consistency check -- help!\n"); 118418381Sralph exit(-1); 118518381Sralph } 11861496Sbill lp = p; 11871496Sbill } 11881496Sbill } 11891496Sbill 11901496Sbill source(ap) 11911496Sbill char *ap; 11921496Sbill { 11931496Sbill register char *p1, *p2; 11941496Sbill 11951496Sbill p1 = ap; 11961496Sbill p2 = p1; 11971496Sbill if (*p1==0) 11981496Sbill return(0); 11991496Sbill while (*p2++ && *(p2-1)!='['); 12001496Sbill if (*p1=='-' && *(p1+1)=='(' 12011496Sbill || *p1=='*' && *(p1+1)=='-' && *(p1+2)=='(' 12021496Sbill || *(p2-2)=='+') { 12031496Sbill while (*p1 && *p1++!='r'); 12041496Sbill if (isdigit(*p1++)) 120518381Sralph if (isdigit(*p1)) 120618381Sralph regs[10+*p1-'0'][0] = regs[10+*p1-'0'][1] = 0; 120718381Sralph else { 120818381Sralph --p1; 120918381Sralph regs[*p1-'0'][0] = regs[*p1-'0'][1] = 0; 121018381Sralph } 12111496Sbill return(1); 12121496Sbill } 12131496Sbill return(0); 12141496Sbill } 12151496Sbill 12161496Sbill newcode(p) struct node *p; { 12171496Sbill register char *p1,*p2,**preg; 12181496Sbill preg=regs+RT1; p2=line; 12191496Sbill while (*(p1= *preg++)) {while (*p2++= *p1++); *(p2-1)=',';} 12201496Sbill *--p2=0; 12211496Sbill p->code=copy(line); 12221496Sbill } 12231496Sbill 12241496Sbill repladdr(p) 12251496Sbill struct node *p; 12261496Sbill { 12271496Sbill register r; 122818381Sralph register char *p1; 12291496Sbill char **preg; int nrepl; 12301496Sbill 12311496Sbill preg=regs+RT1; nrepl=0; 12321496Sbill while (lastrand!=(p1= *preg++)) 12331496Sbill if (!source(p1) && 0<=(r=findrand(p1,p->subop))) { 12341496Sbill *p1++='r'; if (r>9) {*p1++='1'; r -= 10;} *p1++=r+'0'; *p1=0; 12351496Sbill nrepl++; nsaddr++; 12361496Sbill } 12371496Sbill if (nrepl) newcode(p); 12381496Sbill } 12391496Sbill 12401496Sbill /* movedat() 12411496Sbill /* { 12421496Sbill /* register struct node *p1, *p2; 12431496Sbill /* struct node *p3; 12441496Sbill /* register seg; 12451496Sbill /* struct node data; 12461496Sbill /* struct node *datp; 12471496Sbill /* 12481496Sbill /* if (first.forw == 0) 12491496Sbill /* return; 12501496Sbill /* datp = &data; 12511496Sbill /* for (p1 = first.forw; p1!=0; p1 = p1->forw) { 12521496Sbill /* if (p1->op == DATA) { 12531496Sbill /* p2 = p1->forw; 12541496Sbill /* while (p2 && p2->op!=TEXT) 12551496Sbill /* p2 = p2->forw; 12561496Sbill /* if (p2==0) 12571496Sbill /* break; 12581496Sbill /* p3 = p1->back; 12591496Sbill /* p1->back->forw = p2->forw; 12601496Sbill /* p2->forw->back = p3; 12611496Sbill /* p2->forw = 0; 12621496Sbill /* datp->forw = p1; 12631496Sbill /* p1->back = datp; 12641496Sbill /* p1 = p3; 12651496Sbill /* datp = p2; 12661496Sbill /* } 12671496Sbill /* } 12681496Sbill /* if (data.forw) { 12691496Sbill /* datp->forw = first.forw; 12701496Sbill /* first.forw->back = datp; 12711496Sbill /* data.forw->back = &first; 12721496Sbill /* first.forw = data.forw; 12731496Sbill /* } 12741496Sbill /* seg = -1; 12751496Sbill /* for (p1 = first.forw; p1!=0; p1 = p1->forw) { 12761496Sbill /* if (p1->op==TEXT||p1->op==DATA||p1->op==BSS) { 12771496Sbill /* if (p1->op == seg || p1->forw&&p1->forw->op==seg) { 12781496Sbill /* p1->back->forw = p1->forw; 12791496Sbill /* p1->forw->back = p1->back; 12801496Sbill /* p1 = p1->back; 12811496Sbill /* continue; 12821496Sbill /* } 12831496Sbill /* seg = p1->op; 12841496Sbill /* } 12851496Sbill /* } 12861496Sbill /* } 12871496Sbill */ 12881496Sbill 12891496Sbill redunbr(p) 12901496Sbill register struct node *p; 12911496Sbill { 12921496Sbill register struct node *p1; 12931496Sbill register char *ap1; 12941496Sbill char *ap2; 12951496Sbill 12961496Sbill if ((p1 = p->ref) == 0) 12971496Sbill return; 12981496Sbill p1 = nonlab(p1); 12991496Sbill if (p1->op==TST) { 13001496Sbill splitrand(p1); 13011496Sbill savereg(RT2, "$0", p1->subop); 13021496Sbill } else if (p1->op==CMP) 13031496Sbill splitrand(p1); 13041496Sbill else 13051496Sbill return; 13061496Sbill if (p1->forw->op==CBR) { 13071496Sbill ap1 = findcon(RT1, p1->subop); 13081496Sbill ap2 = findcon(RT2, p1->subop); 13091496Sbill p1 = p1->forw; 13101496Sbill if (compare(p1->subop, ap1, ap2)) { 13111496Sbill nredunj++; 13121496Sbill nchange++; 13131496Sbill decref(p->ref); 13141496Sbill p->ref = p1->ref; 13151496Sbill p->labno = p1->labno; 13161496Sbill #ifdef COPYCODE 13171496Sbill if (p->labno == 0) 13181496Sbill p->code = p1->code; 131917210Sralph #endif 13201496Sbill if (p->ref) 13211496Sbill p->ref->refc++; 13221496Sbill } 13231496Sbill } else if (p1->op==TST && equstr(regs[RT1],ccloc+1) && 13241496Sbill equtype(ccloc[0],p1->subop)) { 13251496Sbill p1=insertl(p1->forw); decref(p->ref); p->ref=p1; 13261496Sbill nrtst++; nchange++; 13271496Sbill } 13281496Sbill } 13291496Sbill 13301496Sbill char * 13311496Sbill findcon(i, type) 13321496Sbill { 13331496Sbill register char *p; 13341496Sbill register r; 13351496Sbill 13361496Sbill p = regs[i]; 13371496Sbill if (*p=='$') 13381496Sbill return(p); 13391496Sbill if ((r = isreg(p)) >= 0 && compat(regs[r][0],type)) 13401496Sbill return(regs[r]+1); 13411496Sbill if (equstr(p, conloc)) 13421496Sbill return(conval+1); 13431496Sbill return(p); 13441496Sbill } 13451496Sbill 134618381Sralph compare(opc, acp1, acp2) 13471496Sbill char *acp1, *acp2; 13481496Sbill { 13491496Sbill register char *cp1, *cp2; 13501496Sbill register n1; 13511496Sbill int n2; int sign; 13521496Sbill 13531496Sbill cp1 = acp1; 13541496Sbill cp2 = acp2; 13551496Sbill if (*cp1++ != '$' || *cp2++ != '$') 13561496Sbill return(0); 13571496Sbill n1 = 0; sign=1; if (*cp2=='-') {++cp2; sign= -1;} 13581496Sbill while (isdigit(*cp2)) {n1 *= 10; n1 += (*cp2++ - '0')*sign;} 13591496Sbill n2 = n1; 13601496Sbill n1 = 0; sign=1; if (*cp1=='-') {++cp1; sign= -1;} 13611496Sbill while (isdigit(*cp1)) {n1 *= 10; n1 += (*cp1++ - '0')*sign;} 13621496Sbill if (*cp1=='+') 13631496Sbill cp1++; 13641496Sbill if (*cp2=='+') 13651496Sbill cp2++; 13661496Sbill do { 13671496Sbill if (*cp1++ != *cp2) 13681496Sbill return(0); 13691496Sbill } while (*cp2++); 137018381Sralph switch(opc) { 13711496Sbill 13721496Sbill case JEQ: 137318381Sralph return(n1 == n2); 13741496Sbill case JNE: 137518381Sralph return(n1 != n2); 13761496Sbill case JLE: 137718381Sralph return(n1 <= n2); 13781496Sbill case JGE: 137918381Sralph return(n1 >= n2); 13801496Sbill case JLT: 138118381Sralph return(n1 < n2); 13821496Sbill case JGT: 138318381Sralph return(n1 > n2); 13841496Sbill case JLO: 138518381Sralph return((unsigned) n1 < (unsigned) n2); 13861496Sbill case JHI: 138718381Sralph return((unsigned) n1 > (unsigned) n2); 13881496Sbill case JLOS: 138918381Sralph return((unsigned) n1 <= (unsigned) n2); 13901496Sbill case JHIS: 139118381Sralph return((unsigned) n1 >= (unsigned) n2); 13921496Sbill } 13931496Sbill return(0); 13941496Sbill } 13951496Sbill 13961496Sbill setcon(cv, cl, type) 13971496Sbill register char *cv, *cl; 13981496Sbill { 13991496Sbill register char *p; 14001496Sbill 14011496Sbill if (*cv != '$') 14021496Sbill return; 14031496Sbill if (!natural(cl)) 14041496Sbill return; 14051496Sbill p = conloc; 14061496Sbill while (*p++ = *cl++); 14071496Sbill p = conval; 14081496Sbill *p++ = type; 14091496Sbill while (*p++ = *cv++); 14101496Sbill } 14111496Sbill 14121496Sbill equstr(p1, p2) 14131496Sbill register char *p1, *p2; 14141496Sbill { 14151496Sbill do { 14161496Sbill if (*p1++ != *p2) 14171496Sbill return(0); 14181496Sbill } while (*p2++); 14191496Sbill return(1); 14201496Sbill } 14211496Sbill 14221496Sbill setcc(ap,type) 14231496Sbill char *ap; 14241496Sbill { 14251496Sbill register char *p, *p1; 14261496Sbill 14271496Sbill p = ap; 14281496Sbill if (!natural(p)) { 14291496Sbill ccloc[0] = 0; 14301496Sbill return; 14311496Sbill } 14321496Sbill p1 = ccloc; 14331496Sbill *p1++ = type; 14341496Sbill while (*p1++ = *p++); 14351496Sbill } 14361496Sbill 14371496Sbill okio(p) register char *p; {/* 0->probable I/O space address; 1->not */ 14381496Sbill if (ioflag && (!natural(p) || 0>getnum(p))) return(0); 14391496Sbill return(1); 14401496Sbill } 14411496Sbill 14421496Sbill indexa(p) register char *p; {/* 1-> uses [r] addressing mode; 0->doesn't */ 14431496Sbill while (*p) if (*p++=='[') return(1); 14441496Sbill return(0); 14451496Sbill } 14461496Sbill 14471496Sbill natural(p) 14481496Sbill register char *p; 14491496Sbill {/* 1->simple local, parameter, global, or register; 0->otherwise */ 145017210Sralph if (*p=='*' || *p=='(' || *p=='-'&&p[1]=='(' || *p=='$'&&getnum(p+1)) 14511496Sbill return(0); 14521496Sbill while (*p++); 14531496Sbill p--; 145417210Sralph if (*--p=='+' || *p==']' || *p==')' && p[-2]!='a' && p[-2]!='f') 14551496Sbill return(0); 14561496Sbill return(1); 14571496Sbill } 14581496Sbill 14591496Sbill /* 14601496Sbill ** Tell if an argument is most likely static. 14611496Sbill */ 14621496Sbill 14631496Sbill isstatic(cp) 14641496Sbill register char *cp; 14651496Sbill { 14661496Sbill if (*cp == '_' || *cp == 'L' || (*cp++ == 'v' && *cp == '.')) 14671496Sbill return (1); 14681496Sbill return (0); 14691496Sbill } 147016133Sralph 147116133Sralph autoid(p) register char *p; {/* 1-> uses autoincrement/autodecrement; 0->doesn't */ 147216133Sralph if (*p == '-' && *(p+1) == '(') return(1); 147316133Sralph while (*p) p++; 147416133Sralph if (*--p == '+' && *--p == ')') return(1); 147516133Sralph return(0); 147616133Sralph } 1477