Commit 505fd760 authored by Ken Thompson's avatar Ken Thompson

same speedup as 6l

R=rsc
http://go/go-review/1016050
parent 51c1bd22
...@@ -1035,27 +1035,31 @@ datblk(int32 s, int32 n) ...@@ -1035,27 +1035,31 @@ datblk(int32 s, int32 n)
char *cast; char *cast;
int32 l, fl, j; int32 l, fl, j;
int i, c; int i, c;
Adr *a;
memset(buf.dbuf, 0, n+Dbufslop); memset(buf.dbuf, 0, n+Dbufslop);
for(p = datap; p != P; p = p->link) { for(p = datap; p != P; p = p->link) {
curp = p; a = &p->from;
if(!p->from.sym->reachable)
diag("unreachable symbol in datblk - %s", p->from.sym->name); l = a->sym->value + a->offset - s;
if(p->from.sym->type == SMACHO) if(l >= n)
continue; continue;
l = p->from.sym->value + p->from.offset - s;
c = p->from.scale; c = a->scale;
i = 0; i = 0;
if(l < 0) { if(l < 0) {
if(l+c <= 0) if(l+c <= 0)
continue; continue;
while(l < 0) { i = -l;
l++; l = 0;
i++;
}
} }
if(l >= n)
curp = p;
if(!a->sym->reachable)
diag("unreachable symbol in datblk - %s", a->sym->name);
if(a->sym->type == SMACHO)
continue; continue;
if(p->as != AINIT && p->as != ADYNT) { if(p->as != AINIT && p->as != ADYNT) {
for(j=l+(c-i)-1; j>=l; j--) for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) { if(buf.dbuf[j]) {
...@@ -1071,12 +1075,6 @@ datblk(int32 s, int32 n) ...@@ -1071,12 +1075,6 @@ datblk(int32 s, int32 n)
case 4: case 4:
fl = ieeedtof(&p->to.ieee); fl = ieeedtof(&p->to.ieee);
cast = (char*)&fl; cast = (char*)&fl;
if(debug['a'] && i == 0) {
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[fnuxi4[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[fnuxi4[i]]; buf.dbuf[l] = cast[fnuxi4[i]];
l++; l++;
...@@ -1084,12 +1082,6 @@ datblk(int32 s, int32 n) ...@@ -1084,12 +1082,6 @@ datblk(int32 s, int32 n)
break; break;
case 8: case 8:
cast = (char*)&p->to.ieee; cast = (char*)&p->to.ieee;
if(debug['a'] && i == 0) {
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[fnuxi8[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[fnuxi8[i]]; buf.dbuf[l] = cast[fnuxi8[i]];
l++; l++;
...@@ -1099,12 +1091,6 @@ datblk(int32 s, int32 n) ...@@ -1099,12 +1091,6 @@ datblk(int32 s, int32 n)
break; break;
case D_SCONST: case D_SCONST:
if(debug['a'] && i == 0) {
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = p->to.scon[i]; buf.dbuf[l] = p->to.scon[i];
l++; l++;
...@@ -1134,36 +1120,18 @@ datblk(int32 s, int32 n) ...@@ -1134,36 +1120,18 @@ datblk(int32 s, int32 n)
diag("bad nuxi %d %d\n%P", c, i, curp); diag("bad nuxi %d %d\n%P", c, i, curp);
break; break;
case 1: case 1:
if(debug['a'] && i == 0) {
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[inuxi1[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi1[i]]; buf.dbuf[l] = cast[inuxi1[i]];
l++; l++;
} }
break; break;
case 2: case 2:
if(debug['a'] && i == 0) {
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[inuxi2[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi2[i]]; buf.dbuf[l] = cast[inuxi2[i]];
l++; l++;
} }
break; break;
case 4: case 4:
if(debug['a'] && i == 0) {
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[inuxi4[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
}
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi4[i]]; buf.dbuf[l] = cast[inuxi4[i]];
l++; l++;
...@@ -1173,7 +1141,97 @@ datblk(int32 s, int32 n) ...@@ -1173,7 +1141,97 @@ datblk(int32 s, int32 n)
break; break;
} }
} }
write(cout, buf.dbuf, n); write(cout, buf.dbuf, n);
if(!debug['a'])
return;
/*
* a second pass just to print the asm
*/
for(p = datap; p != P; p = p->link) {
a = &p->from;
l = a->sym->value + a->offset - s;
if(l < 0 || l >= n)
continue;
c = a->scale;
i = 0;
switch(p->to.type) {
case D_FCONST:
switch(c) {
default:
case 4:
fl = ieeedtof(&p->to.ieee);
cast = (char*)&fl;
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[fnuxi4[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
break;
case 8:
cast = (char*)&p->to.ieee;
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[fnuxi8[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
break;
}
break;
case D_SCONST:
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
Bprint(&bso, "\t%P\n", curp);
break;
default:
fl = p->to.offset;
if(p->to.type == D_SIZE)
fl += p->to.sym->size;
if(p->to.type == D_ADDR) {
if(p->to.index != D_STATIC && p->to.index != D_EXTERN)
diag("DADDR type%P", p);
if(p->to.sym) {
if(p->to.sym->type == SUNDEF)
ckoff(p->to.sym, fl);
fl += p->to.sym->value;
if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
fl += INITDAT;
if(dlm)
dynreloc(p->to.sym, l+s+INITDAT, 1);
}
}
cast = (char*)&fl;
switch(c) {
default:
diag("bad nuxi %d %d\n%P", c, i, curp);
break;
case 1:
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[inuxi1[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
break;
case 2:
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[inuxi2[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
break;
case 4:
Bprint(&bso, pcstr, l+s+INITDAT);
for(j=0; j<c; j++)
Bprint(&bso, "%.2ux", cast[inuxi4[j]] & 0xff);
Bprint(&bso, "\t%P\n", curp);
break;
}
break;
}
}
} }
int32 int32
......
...@@ -75,7 +75,6 @@ struct Adr ...@@ -75,7 +75,6 @@ struct Adr
uchar index; uchar index;
char scale; char scale;
int32 offset2; int32 offset2;
Sym* gotype;
}; };
#define offset u0.u0offset #define offset u0.u0offset
...@@ -97,11 +96,13 @@ struct Prog ...@@ -97,11 +96,13 @@ struct Prog
Prog* pcond; /* work on this */ Prog* pcond; /* work on this */
int32 pc; int32 pc;
int32 line; int32 line;
short as;
char width; /* fake for DATA */
char ft; /* oclass cache */
char tt;
uchar mark; /* work on these */ uchar mark; /* work on these */
uchar back; uchar back;
short as;
char width; /* fake for DATA */
}; };
struct Auto struct Auto
{ {
...@@ -302,6 +303,8 @@ EXTERN int version; ...@@ -302,6 +303,8 @@ EXTERN int version;
EXTERN Prog zprg; EXTERN Prog zprg;
EXTERN int dtype; EXTERN int dtype;
EXTERN int tlsoffset; EXTERN int tlsoffset;
EXTERN Sym* adrgotype; // type symbol on last Adr read
EXTERN Sym* fromgotype; // type symbol on last p->from read
EXTERN Adr* reloca; EXTERN Adr* reloca;
EXTERN int doexp, dlm; EXTERN int doexp, dlm;
......
...@@ -179,8 +179,8 @@ brk: ...@@ -179,8 +179,8 @@ brk:
} }
conv: conv:
fmtstrcpy(fp, str); fmtstrcpy(fp, str);
if(a->gotype) // if(a->gotype)
fmtprint(fp, "«%s»", a->gotype->name); // fmtprint(fp, "«%s»", a->gotype->name);
return 0; return 0;
} }
......
...@@ -401,12 +401,11 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -401,12 +401,11 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
Auto *u; Auto *u;
t = Bgetc(f); t = Bgetc(f);
a->index = D_NONE;
a->scale = 0;
if(t & T_INDEX) { if(t & T_INDEX) {
a->index = Bgetc(f); a->index = Bgetc(f);
a->scale = Bgetc(f); a->scale = Bgetc(f);
} else {
a->index = D_NONE;
a->scale = 0;
} }
a->type = D_NONE; a->type = D_NONE;
a->offset = 0; a->offset = 0;
...@@ -431,8 +430,9 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -431,8 +430,9 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
} }
if(t & T_TYPE) if(t & T_TYPE)
a->type = Bgetc(f); a->type = Bgetc(f);
adrgotype = S;
if(t & T_GOTYPE) if(t & T_GOTYPE)
a->gotype = h[Bgetc(f)]; adrgotype = h[Bgetc(f)];
t = a->type; t = a->type;
if(t == D_INDIR+D_GS) if(t == D_INDIR+D_GS)
...@@ -442,8 +442,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -442,8 +442,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
if(s == S) if(s == S)
return; return;
if(t != D_AUTO && t != D_PARAM) { if(t != D_AUTO && t != D_PARAM) {
if(a->gotype) if(adrgotype)
s->gotype = a->gotype; s->gotype = adrgotype;
return; return;
} }
l = a->offset; l = a->offset;
...@@ -452,8 +452,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -452,8 +452,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
if(u->type == t) { if(u->type == t) {
if(u->aoffset > l) if(u->aoffset > l)
u->aoffset = l; u->aoffset = l;
if(a->gotype) if(adrgotype)
u->gotype = a->gotype; u->gotype = adrgotype;
return; return;
} }
} }
...@@ -464,7 +464,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[]) ...@@ -464,7 +464,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
u->asym = s; u->asym = s;
u->aoffset = l; u->aoffset = l;
u->type = t; u->type = t;
u->gotype = a->gotype; u->gotype = adrgotype;
} }
void void
...@@ -570,7 +570,10 @@ loop: ...@@ -570,7 +570,10 @@ loop:
p->as = o; p->as = o;
p->line = Bget4(f); p->line = Bget4(f);
p->back = 2; p->back = 2;
p->ft = 0;
p->tt = 0;
zaddr(f, &p->from, h); zaddr(f, &p->from, h);
fromgotype = adrgotype;
zaddr(f, &p->to, h); zaddr(f, &p->to, h);
if(debug['W']) if(debug['W'])
...@@ -668,8 +671,8 @@ loop: ...@@ -668,8 +671,8 @@ loop:
// redefinitions. // redefinitions.
s = p->from.sym; s = p->from.sym;
if(s != S && s->dupok) { if(s != S && s->dupok) {
if(debug['v']) // if(debug['v'])
Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn); // Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
goto loop; goto loop;
} }
if(s != S) { if(s != S) {
......
...@@ -882,21 +882,33 @@ subreg(Prog *p, int from, int to) ...@@ -882,21 +882,33 @@ subreg(Prog *p, int from, int to)
if(debug['Q']) if(debug['Q'])
print("\n%P s/%R/%R/\n", p, from, to); print("\n%P s/%R/%R/\n", p, from, to);
if(p->from.type == from) if(p->from.type == from) {
p->from.type = to; p->from.type = to;
if(p->to.type == from) p->ft = 0;
}
if(p->to.type == from) {
p->to.type = to; p->to.type = to;
p->tt = 0;
}
if(p->from.index == from) if(p->from.index == from) {
p->from.index = to; p->from.index = to;
if(p->to.index == from) p->ft = 0;
}
if(p->to.index == from) {
p->to.index = to; p->to.index = to;
p->tt = 0;
}
from += D_INDIR; from += D_INDIR;
if(p->from.type == from) if(p->from.type == from) {
p->from.type = to+D_INDIR; p->from.type = to+D_INDIR;
if(p->to.type == from) p->ft = 0;
}
if(p->to.type == from) {
p->to.type = to+D_INDIR; p->to.type = to+D_INDIR;
p->tt = 0;
}
if(debug['Q']) if(debug['Q'])
print("%P\n", p); print("%P\n", p);
...@@ -934,9 +946,30 @@ doasm(Prog *p) ...@@ -934,9 +946,30 @@ doasm(Prog *p)
if(pre) if(pre)
*andptr++ = pre; *andptr++ = pre;
if(p->ft != 0) {
ft = oclass(&p->from);
if(ft != p->ft) {
print("***** %d %d %D\n", p->ft, ft, &p->from);
p->ft = ft;
}
}
if(p->tt != 0) {
tt = oclass(&p->to);
if(tt != p->tt) {
print("***** %d %d %D\n", p->tt, tt, &p->to);
p->tt = tt;
}
}
// if(p->ft == 0)
p->ft = oclass(&p->from);
// if(p->tt == 0)
p->tt = oclass(&p->to);
ft = p->ft * Ymax;
tt = p->tt * Ymax;
o = &optab[p->as]; o = &optab[p->as];
ft = oclass(&p->from) * Ymax;
tt = oclass(&p->to) * Ymax;
t = o->ytab; t = o->ytab;
if(t == 0) { if(t == 0) {
diag("asmins: noproto %P", p); diag("asmins: noproto %P", p);
...@@ -998,9 +1031,11 @@ found: ...@@ -998,9 +1031,11 @@ found:
diag("asmins: Zaut sb type ADDR"); diag("asmins: Zaut sb type ADDR");
p->from.type = p->from.index; p->from.type = p->from.index;
p->from.index = D_NONE; p->from.index = D_NONE;
p->ft = 0;
asmand(&p->from, reg[p->to.type]); asmand(&p->from, reg[p->to.type]);
p->from.index = p->from.type; p->from.index = p->from.type;
p->from.type = D_ADDR; p->from.type = D_ADDR;
p->ft = 0;
break; break;
case Zm_o: case Zm_o:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment