]> Cypherpunks repositories - gostls13.git/commitdiff
same speedup as 6l
authorKen Thompson <ken@golang.org>
Thu, 5 Nov 2009 20:47:22 +0000 (12:47 -0800)
committerKen Thompson <ken@golang.org>
Thu, 5 Nov 2009 20:47:22 +0000 (12:47 -0800)
R=rsc
http://go/go-review/1016050

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

index 6dfdc387a869ca66fa1045bfd91b45b518a03b91..7f101b74eab6dbc6ac9fab11092c24bba632f7f7 100644 (file)
@@ -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
index a648770a084d028f8a0adc9958b276c150854b5f..adc3f4dee1d3a8a5f1054e05a5604abd8e14885c 100644 (file)
@@ -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;
index a8a042fc64a13dc4685ab4a5fcfa6adca9567bda..94ef97624c5ac61e4df4c53b0f078793498b4e30 100644 (file)
@@ -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;
 }
 
index d60b9eaba5811b3d83d058dfe92f7bd6f4f4dae1..88925e691ddeee817bba1a30f772653808bf3090 100644 (file)
@@ -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) {
index 0204caa1e8c4b134f260deb5f54722c1563b39a4..370ae67d333d52d4db71ac3ae61fb3bcd1d6ddad 100644 (file)
@@ -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: