1
0
mirror of https://github.com/golang/go synced 2024-11-25 17:17:56 -07:00

speed up 6l

hopefully no change

R=rsc
http://go/go-review/1017035
This commit is contained in:
Ken Thompson 2009-11-04 18:17:57 -08:00
parent cc1a979272
commit 9c7535432a
5 changed files with 126 additions and 46 deletions

View File

@ -925,16 +925,17 @@ datblk(int32 s, int32 n)
int32 l, fl, j; int32 l, fl, j;
vlong o; vlong o;
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)
@ -942,8 +943,13 @@ datblk(int32 s, int32 n)
i = -l; i = -l;
l = 0; 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; 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]) {
@ -960,8 +966,6 @@ datblk(int32 s, int32 n)
case 4: case 4:
fl = ieeedtof(&p->to.ieee); fl = ieeedtof(&p->to.ieee);
cast = (uchar*)&fl; cast = (uchar*)&fl;
if(debug['a'] && i == 0)
outa(c, cast, fnuxi4, l+s+INITDAT);
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[fnuxi4[i]]; buf.dbuf[l] = cast[fnuxi4[i]];
l++; l++;
@ -969,8 +973,6 @@ datblk(int32 s, int32 n)
break; break;
case 8: case 8:
cast = (uchar*)&p->to.ieee; cast = (uchar*)&p->to.ieee;
if(debug['a'] && i == 0)
outa(c, cast, fnuxi8, l+s+INITDAT);
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[fnuxi8[i]]; buf.dbuf[l] = cast[fnuxi8[i]];
l++; l++;
@ -980,8 +982,6 @@ datblk(int32 s, int32 n)
break; break;
case D_SCONST: case D_SCONST:
if(debug['a'] && i == 0)
outa(c, (uchar*)p->to.scon, nil, l+s+INITDAT);
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = p->to.scon[i]; buf.dbuf[l] = p->to.scon[i];
l++; l++;
@ -1016,24 +1016,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)
outa(c, cast, inuxi1, l+s+INITDAT);
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)
outa(c, cast, inuxi2, l+s+INITDAT);
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)
outa(c, cast, inuxi4, l+s+INITDAT);
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi4[i]]; buf.dbuf[l] = cast[inuxi4[i]];
l++; l++;
@ -1041,8 +1035,6 @@ datblk(int32 s, int32 n)
break; break;
case 8: case 8:
cast = (uchar*)&o; cast = (uchar*)&o;
if(debug['a'] && i == 0)
outa(c, cast, inuxi8, l+s+INITDAT);
for(; i<c; i++) { for(; i<c; i++) {
buf.dbuf[l] = cast[inuxi8[i]]; buf.dbuf[l] = cast[inuxi8[i]];
l++; l++;
@ -1052,7 +1044,80 @@ 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 >= n)
continue;
c = a->scale;
i = 0;
if(l < 0)
continue;
if(a->sym->type == SMACHO)
continue;
switch(p->to.type) {
case D_FCONST:
switch(c) {
default:
case 4:
fl = ieeedtof(&p->to.ieee);
cast = (uchar*)&fl;
outa(c, cast, fnuxi4, l+s+INITDAT);
break;
case 8:
cast = (uchar*)&p->to.ieee;
outa(c, cast, fnuxi8, l+s+INITDAT);
break;
}
break;
case D_SCONST:
outa(c, (uchar*)p->to.scon, nil, l+s+INITDAT);
break;
default:
o = p->to.offset;
if(p->to.type == D_SIZE)
o += p->to.sym->size;
if(p->to.type == D_ADDR) {
if(p->to.sym) {
o += p->to.sym->value;
if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
o += INITDAT;
}
}
fl = o;
cast = (uchar*)&fl;
switch(c) {
case 1:
outa(c, cast, inuxi1, l+s+INITDAT);
break;
case 2:
outa(c, cast, inuxi2, l+s+INITDAT);
break;
case 4:
outa(c, cast, inuxi4, l+s+INITDAT);
break;
case 8:
cast = (uchar*)&o;
outa(c, cast, inuxi8, l+s+INITDAT);
break;
}
break;
}
}
} }
vlong vlong

View File

@ -75,7 +75,6 @@ struct Adr
short type; short type;
char index; char index;
char scale; char scale;
Sym* gotype;
}; };
#define offset u0.u0offset #define offset u0.u0offset
@ -97,10 +96,12 @@ struct Prog
Prog* pcond; /* work on this */ Prog* pcond; /* work on this */
vlong pc; vlong pc;
int32 line; int32 line;
short as;
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 */ char width; /* fake for DATA */
char mode; /* 16, 32, or 64 */ char mode; /* 16, 32, or 64 */
}; };
@ -338,6 +339,8 @@ EXTERN int version;
EXTERN Prog zprg; EXTERN Prog zprg;
EXTERN int dtype; EXTERN int dtype;
EXTERN char* paramspace; EXTERN char* paramspace;
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; // export table EXTERN int doexp; // export table

View File

@ -209,8 +209,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;
} }

View File

@ -408,12 +408,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->offset = 0; a->offset = 0;
if(t & T_OFFSET) { if(t & T_OFFSET) {
@ -438,16 +437,17 @@ 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)];
s = a->sym; s = a->sym;
if(s == S) if(s == S)
return; return;
t = a->type; t = a->type;
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;
@ -456,8 +456,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;
} }
} }
@ -468,7 +468,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
@ -575,7 +575,10 @@ loop:
p->line = Bget4(f); p->line = Bget4(f);
p->back = 2; p->back = 2;
p->mode = mode; p->mode = mode;
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'])
@ -673,8 +676,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) {
@ -720,10 +723,10 @@ loop:
} }
diag("%s: redefinition: %s\n%P", pn, s->name, p); diag("%s: redefinition: %s\n%P", pn, s->name, p);
} }
if(p->from.gotype) { if(fromgotype) {
if(s->gotype && s->gotype != p->from.gotype) if(s->gotype && s->gotype != fromgotype)
diag("%s: type mismatch for %s", pn, s->name); diag("%s: type mismatch for %s", pn, s->name);
s->gotype = p->from.gotype; s->gotype = fromgotype;
} }
newtext(p, s); newtext(p, s);
goto loop; goto loop;

View File

@ -952,10 +952,12 @@ asmando(Adr *a, int o)
} }
static void static void
bytereg(Adr *a) bytereg(Adr *a, char *t)
{ {
if(a->index == D_NONE && (a->type >= D_AX && a->type <= D_R15)) if(a->index == D_NONE && (a->type >= D_AX && a->type <= D_R15)) {
a->type = D_AL + (a->type-D_AX); a->type = D_AL + (a->type-D_AX);
*t = 0;
}
} }
#define E 0xff #define E 0xff
@ -1171,8 +1173,15 @@ doasm(Prog *p)
diag("asmins: missing op %P", p); diag("asmins: missing op %P", p);
return; return;
} }
ft = oclass(&p->from) * Ymax;
tt = oclass(&p->to) * Ymax; 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;
t = o->ytab; t = o->ytab;
if(t == 0) { if(t == 0) {
diag("asmins: noproto %P", p); diag("asmins: noproto %P", p);
@ -1213,8 +1222,8 @@ found:
break; break;
case Pb: /* botch */ case Pb: /* botch */
bytereg(&p->from); bytereg(&p->from, &p->ft);
bytereg(&p->to); bytereg(&p->to, &p->tt);
break; break;
case P32: /* 32 bit but illegal if 64-bit mode */ case P32: /* 32 bit but illegal if 64-bit mode */
@ -1247,7 +1256,7 @@ found:
break; break;
case Zmb_r: case Zmb_r:
bytereg(&p->from); bytereg(&p->from, &p->ft);
/* fall through */ /* fall through */
case Zm_r: case Zm_r:
*andptr++ = op; *andptr++ = op;