]> Cypherpunks repositories - gostls13.git/commitdiff
speed up 6l
authorKen Thompson <ken@golang.org>
Thu, 5 Nov 2009 02:17:57 +0000 (18:17 -0800)
committerKen Thompson <ken@golang.org>
Thu, 5 Nov 2009 02:17:57 +0000 (18:17 -0800)
hopefully no change

R=rsc
http://go/go-review/1017035

src/cmd/6l/asm.c
src/cmd/6l/l.h
src/cmd/6l/list.c
src/cmd/6l/obj.c
src/cmd/6l/span.c

index 077755105dab228b02333268d242734a992318cd..e5aa42c71bb3455e53d860f14b7cd05c40e91d2e 100644 (file)
@@ -925,16 +925,17 @@ datblk(int32 s, int32 n)
        int32 l, fl, j;
        vlong o;
        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)
@@ -942,8 +943,13 @@ datblk(int32 s, int32 n)
                        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]) {
@@ -960,8 +966,6 @@ datblk(int32 s, int32 n)
                        case 4:
                                fl = ieeedtof(&p->to.ieee);
                                cast = (uchar*)&fl;
-                               if(debug['a'] && i == 0)
-                                       outa(c, cast, fnuxi4, l+s+INITDAT);
                                for(; i<c; i++) {
                                        buf.dbuf[l] = cast[fnuxi4[i]];
                                        l++;
@@ -969,8 +973,6 @@ datblk(int32 s, int32 n)
                                break;
                        case 8:
                                cast = (uchar*)&p->to.ieee;
-                               if(debug['a'] && i == 0)
-                                       outa(c, cast, fnuxi8, l+s+INITDAT);
                                for(; i<c; i++) {
                                        buf.dbuf[l] = cast[fnuxi8[i]];
                                        l++;
@@ -980,8 +982,6 @@ datblk(int32 s, int32 n)
                        break;
 
                case D_SCONST:
-                       if(debug['a'] && i == 0)
-                               outa(c, (uchar*)p->to.scon, nil, l+s+INITDAT);
                        for(; i<c; i++) {
                                buf.dbuf[l] = p->to.scon[i];
                                l++;
@@ -1016,24 +1016,18 @@ datblk(int32 s, int32 n)
                                diag("bad nuxi %d %d\n%P", c, i, curp);
                                break;
                        case 1:
-                               if(debug['a'] && i == 0)
-                                       outa(c, cast, inuxi1, l+s+INITDAT);
                                for(; i<c; i++) {
                                        buf.dbuf[l] = cast[inuxi1[i]];
                                        l++;
                                }
                                break;
                        case 2:
-                               if(debug['a'] && i == 0)
-                                       outa(c, cast, inuxi2, l+s+INITDAT);
                                for(; i<c; i++) {
                                        buf.dbuf[l] = cast[inuxi2[i]];
                                        l++;
                                }
                                break;
                        case 4:
-                               if(debug['a'] && i == 0)
-                                       outa(c, cast, inuxi4, l+s+INITDAT);
                                for(; i<c; i++) {
                                        buf.dbuf[l] = cast[inuxi4[i]];
                                        l++;
@@ -1041,8 +1035,6 @@ datblk(int32 s, int32 n)
                                break;
                        case 8:
                                cast = (uchar*)&o;
-                               if(debug['a'] && i == 0)
-                                       outa(c, cast, inuxi8, l+s+INITDAT);
                                for(; i<c; i++) {
                                        buf.dbuf[l] = cast[inuxi8[i]];
                                        l++;
@@ -1052,7 +1044,80 @@ 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 >= 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
index 91cfbabfd1017a1d772197b98f5e02decf4cbb45..be1aa41781b514e09ac1bb4f7f5b0d6d55ae81ac 100644 (file)
@@ -75,7 +75,6 @@ struct        Adr
        short   type;
        char    index;
        char    scale;
-       Sym*    gotype;
 };
 
 #define        offset  u0.u0offset
@@ -97,10 +96,12 @@ struct      Prog
        Prog*   pcond;  /* work on this */
        vlong   pc;
        int32   line;
+       short   as;
+       char    ft;     /* oclass cache */
+       char    tt;
        uchar   mark;   /* work on these */
        uchar   back;
 
-       short   as;
        char    width;          /* fake for DATA */
        char    mode;   /* 16, 32, or 64 */
 };
@@ -338,6 +339,8 @@ EXTERN      int     version;
 EXTERN Prog    zprg;
 EXTERN int     dtype;
 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 int     doexp;          // export table
index 286bba69cf0170373f900a4ad5dbe31eeca11889..34b66c0c8090c04188c60171daa7f60745c6b863 100644 (file)
@@ -209,8 +209,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;
 
 }
index 7098b42ebc34190bd48660238bee325a851de669..ffe93fce4dc152de861c52dc1291abb101290ca1 100644 (file)
@@ -408,12 +408,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->offset = 0;
        if(t & T_OFFSET) {
@@ -438,16 +437,17 @@ 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)];
        s = a->sym;
        if(s == S)
                return;
 
        t = a->type;
        if(t != D_AUTO && t != D_PARAM) {
-               if(a->gotype)
-                       s->gotype = a->gotype;
+               if(adrgotype)
+                       s->gotype = adrgotype;
                return;
        }
        l = a->offset;
@@ -456,8 +456,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;
                }
        }
@@ -468,7 +468,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
@@ -575,7 +575,10 @@ loop:
        p->line = Bget4(f);
        p->back = 2;
        p->mode = mode;
+       p->ft = 0;
+       p->tt = 0;
        zaddr(f, &p->from, h);
+       fromgotype = adrgotype;
        zaddr(f, &p->to, h);
 
        if(debug['W'])
@@ -673,8 +676,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) {
@@ -720,10 +723,10 @@ loop:
                        }
                        diag("%s: redefinition: %s\n%P", pn, s->name, p);
                }
-               if(p->from.gotype) {
-                       if(s->gotype && s->gotype != p->from.gotype)
+               if(fromgotype) {
+                       if(s->gotype && s->gotype != fromgotype)
                                diag("%s: type mismatch for %s", pn, s->name);
-                       s->gotype = p->from.gotype;
+                       s->gotype = fromgotype;
                }
                newtext(p, s);
                goto loop;
index 4930e545b37f09538f6e7af2a9547a0fdb100727..237a81fffdb558d5fc6358f2cbca34af1f671716 100644 (file)
@@ -952,10 +952,12 @@ asmando(Adr *a, int o)
 }
 
 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);
+               *t = 0;
+       }
 }
 
 #define        E       0xff
@@ -1171,8 +1173,15 @@ doasm(Prog *p)
                diag("asmins: missing op %P", p);
                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;
        if(t == 0) {
                diag("asmins: noproto %P", p);
@@ -1213,8 +1222,8 @@ found:
                break;
 
        case Pb:        /* botch */
-               bytereg(&p->from);
-               bytereg(&p->to);
+               bytereg(&p->from, &p->ft);
+               bytereg(&p->to, &p->tt);
                break;
 
        case P32:       /* 32 bit but illegal if 64-bit mode */
@@ -1247,7 +1256,7 @@ found:
                break;
 
        case Zmb_r:
-               bytereg(&p->from);
+               bytereg(&p->from, &p->ft);
                /* fall through */
        case Zm_r:
                *andptr++ = op;