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)
char *cast;
int32 l, fl, j;
int i, c;
Adr *a;
memset(buf.dbuf, 0, n+Dbufslop);
for(p = datap; p != P; p = p->link) {
curp = p;
if(!p->from.sym->reachable)
diag("unreachable symbol in datblk - %s", p->from.sym->name);
if(p->from.sym->type == SMACHO)
a = &p->from;
l = a->sym->value + a->offset - s;
if(l >= n)
continue;
l = p->from.sym->value + p->from.offset - s;
c = p->from.scale;
c = a->scale;
i = 0;
if(l < 0) {
if(l+c <= 0)
continue;
while(l < 0) {
l++;
i++;
}
i = -l;
l = 0;
}
if(l >= n)
curp = p;
if(!a->sym->reachable)
diag("unreachable symbol in datblk - %s", a->sym->name);
if(a->sym->type == SMACHO)
continue;
if(p->as != AINIT && p->as != ADYNT) {
for(j=l+(c-i)-1; j>=l; j--)
if(buf.dbuf[j]) {
......@@ -1071,12 +1075,6 @@ datblk(int32 s, int32 n)
case 4:
fl = ieeedtof(&p->to.ieee);
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++) {
buf.dbuf[l] = cast[fnuxi4[i]];
l++;
......@@ -1084,12 +1082,6 @@ datblk(int32 s, int32 n)
break;
case 8:
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++) {
buf.dbuf[l] = cast[fnuxi8[i]];
l++;
......@@ -1099,12 +1091,6 @@ datblk(int32 s, int32 n)
break;
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++) {
buf.dbuf[l] = p->to.scon[i];
l++;
......@@ -1134,36 +1120,18 @@ datblk(int32 s, int32 n)
diag("bad nuxi %d %d\n%P", c, i, curp);
break;
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++) {
buf.dbuf[l] = cast[inuxi1[i]];
l++;
}
break;
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++) {
buf.dbuf[l] = cast[inuxi2[i]];
l++;
}
break;
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++) {
buf.dbuf[l] = cast[inuxi4[i]];
l++;
......@@ -1173,7 +1141,97 @@ datblk(int32 s, int32 n)
break;
}
}
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
......
......@@ -75,7 +75,6 @@ struct Adr
uchar index;
char scale;
int32 offset2;
Sym* gotype;
};
#define offset u0.u0offset
......@@ -97,11 +96,13 @@ struct Prog
Prog* pcond; /* work on this */
int32 pc;
int32 line;
short as;
char width; /* fake for DATA */
char ft; /* oclass cache */
char tt;
uchar mark; /* work on these */
uchar back;
short as;
char width; /* fake for DATA */
};
struct Auto
{
......@@ -302,6 +303,8 @@ EXTERN int version;
EXTERN Prog zprg;
EXTERN int dtype;
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 int doexp, dlm;
......
......@@ -179,8 +179,8 @@ brk:
}
conv:
fmtstrcpy(fp, str);
if(a->gotype)
fmtprint(fp, "«%s»", a->gotype->name);
// if(a->gotype)
// fmtprint(fp, "«%s»", a->gotype->name);
return 0;
}
......
......@@ -401,12 +401,11 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
Auto *u;
t = Bgetc(f);
a->index = D_NONE;
a->scale = 0;
if(t & T_INDEX) {
a->index = Bgetc(f);
a->scale = Bgetc(f);
} else {
a->index = D_NONE;
a->scale = 0;
}
a->type = D_NONE;
a->offset = 0;
......@@ -431,8 +430,9 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
}
if(t & T_TYPE)
a->type = Bgetc(f);
adrgotype = S;
if(t & T_GOTYPE)
a->gotype = h[Bgetc(f)];
adrgotype = h[Bgetc(f)];
t = a->type;
if(t == D_INDIR+D_GS)
......@@ -442,8 +442,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
if(s == S)
return;
if(t != D_AUTO && t != D_PARAM) {
if(a->gotype)
s->gotype = a->gotype;
if(adrgotype)
s->gotype = adrgotype;
return;
}
l = a->offset;
......@@ -452,8 +452,8 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
if(u->type == t) {
if(u->aoffset > l)
u->aoffset = l;
if(a->gotype)
u->gotype = a->gotype;
if(adrgotype)
u->gotype = adrgotype;
return;
}
}
......@@ -464,7 +464,7 @@ zaddr(Biobuf *f, Adr *a, Sym *h[])
u->asym = s;
u->aoffset = l;
u->type = t;
u->gotype = a->gotype;
u->gotype = adrgotype;
}
void
......@@ -570,7 +570,10 @@ loop:
p->as = o;
p->line = Bget4(f);
p->back = 2;
p->ft = 0;
p->tt = 0;
zaddr(f, &p->from, h);
fromgotype = adrgotype;
zaddr(f, &p->to, h);
if(debug['W'])
......@@ -668,8 +671,8 @@ loop:
// redefinitions.
s = p->from.sym;
if(s != S && s->dupok) {
if(debug['v'])
Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
// if(debug['v'])
// Bprint(&bso, "skipping %s in %s: dupok\n", s->name, pn);
goto loop;
}
if(s != S) {
......
......@@ -882,21 +882,33 @@ subreg(Prog *p, int from, int to)
if(debug['Q'])
print("\n%P s/%R/%R/\n", p, from, to);
if(p->from.type == from)
if(p->from.type == from) {
p->from.type = to;
if(p->to.type == from)
p->ft = 0;
}
if(p->to.type == from) {
p->to.type = to;
p->tt = 0;
}
if(p->from.index == from)
if(p->from.index == from) {
p->from.index = to;
if(p->to.index == from)
p->ft = 0;
}
if(p->to.index == from) {
p->to.index = to;
p->tt = 0;
}
from += D_INDIR;
if(p->from.type == from)
if(p->from.type == from) {
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->tt = 0;
}
if(debug['Q'])
print("%P\n", p);
......@@ -934,9 +946,30 @@ doasm(Prog *p)
if(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];
ft = oclass(&p->from) * Ymax;
tt = oclass(&p->to) * Ymax;
t = o->ytab;
if(t == 0) {
diag("asmins: noproto %P", p);
......@@ -998,9 +1031,11 @@ found:
diag("asmins: Zaut sb type ADDR");
p->from.type = p->from.index;
p->from.index = D_NONE;
p->ft = 0;
asmand(&p->from, reg[p->to.type]);
p->from.index = p->from.type;
p->from.type = D_ADDR;
p->ft = 0;
break;
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