]> Cypherpunks repositories - gostls13.git/commitdiff
minor cleanup, 64-bit /= and %= on 32-bit
authorRuss Cox <rsc@golang.org>
Wed, 3 Jun 2009 06:21:58 +0000 (23:21 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 3 Jun 2009 06:21:58 +0000 (23:21 -0700)
R=ken
OCL=29806
CL=29808

src/cmd/6g/cgen.c
src/cmd/6g/ggen.c
src/cmd/gc/go.h
src/cmd/gc/subr.c
src/cmd/gc/walk.c

index 5ac8b0f9cc9f52fce5f93029b6b2a09f14c44033..1bc399c1706205848148e25e11cbc23df755d771 100644 (file)
@@ -224,7 +224,7 @@ cgen(Node *n, Node *res)
 
        case OLEN:
                if(istype(nl->type, TMAP)) {
-                       // map hsd len in the first 32-bit word.
+                       // map has len in the first 32-bit word.
                        // a zero pointer means zero length
                        regalloc(&n1, types[tptr], res);
                        cgen(nl, &n1);
@@ -245,7 +245,7 @@ cgen(Node *n, Node *res)
                        break;
                }
                if(istype(nl->type, TSTRING) || isslice(nl->type)) {
-                       // both slice and string have len in the first 32-bit word.
+                       // both slice and string have len one pointer into the struct.
                        // a zero pointer means zero length
                        regalloc(&n1, types[tptr], res);
                        agen(nl, &n1);
@@ -835,7 +835,7 @@ stkof(Node *n)
 
 /*
  * block copy:
- *     memmove(&n, &ns, w);
+ *     memmove(&ns, &n, w);
  */
 void
 sgen(Node *n, Node *ns, int32 w)
index b92d24ebcd88a36cc0b6e1ab62992799d1745ec7..05a79ced380dde822f348a7e041fa103f30fd3ab 100644 (file)
@@ -127,8 +127,11 @@ ginscall(Node *f, int proc)
                gins(APUSHQ, &con, N);
                if(proc == 1)
                        ginscall(newproc, 0);
-               else
+               else {
+                       if(!hasdefer)
+                               fatal("hasdefer=0 but has defer");
                        ginscall(deferproc, 0);
+               }
                gins(APOPQ, N, &reg);
                gins(APOPQ, N, &reg);
                break;
@@ -176,7 +179,7 @@ cgen_callinter(Node *n, Node *res, int proc)
        nodo.xoffset -= widthptr;
        cgen(&nodo, &nodr);     // REG = 0(REG) -- i.m
 
-       nodo.xoffset = n->left->xoffset + 4*widthptr;
+       nodo.xoffset = n->left->xoffset + 3*widthptr + 8;
        cgen(&nodo, &nodr);     // REG = 32+offset(REG) -- i.m->fun[f]
 
        // BOTCH nodr.type = fntype;
@@ -852,10 +855,6 @@ lit:
                p->from.scale = types[TINT32]->width;
                p->from.offset += types[tptr]->width;
 //print("%P\n", p);
-
-               p = gins(ADATA, &nam, &nod1);
-               p->from.scale = types[TINT32]->width;
-               p->from.offset += types[tptr]->width+types[TINT32]->width;
                break;
        }
 
index 5abdfcce07179dbbd3e26958e32647db850cfb24..e35721e7e4db522695a93c864012cdd0af7554dd 100644 (file)
@@ -755,6 +755,9 @@ void        tempname(Node*, Type*);
 Node*  staticname(Type*);
 int    iscomposite(Type*);
 Node*  callnew(Type*);
+Node*  saferef(Node*);
+int    is64(Type*);
+int    noconv(Type*, Type*);
 
 Type** getthis(Type*);
 Type** getoutarg(Type*);
index dcaa11a004398686be2c2e9201a4970eeebf4484..96d6b4deb3c2074199ff7efbf28a2dd041dc0dcd 100644 (file)
@@ -1806,6 +1806,62 @@ loop:
        return 1;
 }
 
+/*
+ * Is this a 64-bit type?
+ */
+int
+is64(Type *t)
+{
+       if(t == T)
+               return 0;
+       switch(simtype[t->etype]) {
+       case TINT64:
+       case TUINT64:
+       case TPTR64:
+               return 1;
+       }
+       return 0;
+}
+
+/*
+ * Is a conversion between t1 and t2 a no-op?
+ */
+int
+noconv(Type *t1, Type *t2)
+{
+       int e1, e2;
+
+       e1 = simtype[t1->etype];
+       e2 = simtype[t2->etype];
+
+       switch(e1) {
+       case TINT8:
+       case TUINT8:
+               return e2 == TINT8 || e2 == TUINT8;
+
+       case TINT16:
+       case TUINT16:
+               return e2 == TINT16 || e2 == TUINT16;
+
+       case TINT32:
+       case TUINT32:
+       case TPTR32:
+               return e2 == TINT32 || e2 == TUINT32 || e2 == TPTR32;
+
+       case TINT64:
+       case TUINT64:
+       case TPTR64:
+               return e2 == TINT64 || e2 == TUINT64 || e2 == TPTR64;
+
+       case TFLOAT32:
+               return e2 == TFLOAT32;
+
+       case TFLOAT64:
+               return e2 == TFLOAT64;
+       }
+       return 0;
+}
+
 void
 argtype(Node *on, Type *t)
 {
@@ -2417,6 +2473,42 @@ staticname(Type *t)
        return n;
 }
 
+/*
+ * return side effect-free n, moving side effects to top.
+ */
+Node*
+saferef(Node *n)
+{
+       Node *l;
+       Node *r;
+
+       switch(n->op) {
+       case ONAME:
+               return n;
+       case ODOT:
+               l = saferef(n->left);
+               if(l == n->left)
+                       return n;
+               r = nod(OXXX, N, N);
+               *r = *n;
+               r->left = l;
+               walktype(r, Elv);
+               return r;
+
+       case OINDEX:
+       case ODOTPTR:
+       case OIND:
+               l = nod(OXXX, N, N);
+               tempname(l, ptrto(n->type));
+               addtotop(nod(OAS, l, nod(OADDR, n, N)));
+               r = nod(OIND, l, N);
+               walktype(r, Elv);
+               return r;
+       }
+       fatal("saferef %N", n);
+       return N;
+}
+
 void
 setmaxarg(Type *t)
 {
index c552c0928d78a802aa28c6c8eaced5e2860e64c0..4cb412c6cb170dc3bddd1b16bbce16289dc82bb9 100644 (file)
@@ -1143,10 +1143,10 @@ loop:
         * rewrite div and mod into function calls
         * on 32-bit architectures.
         */
-       switch(n->op) {
-       case ODIV:
-       case OMOD:
-               et = n->left->type->etype;
+       switch(n->op) {
+       case ODIV:
+       case OMOD:
+               et = n->left->type->etype;
                if(widthptr > 4 || (et != TUINT64 && et != TINT64))
                        break;
                if(et == TINT64)
@@ -1163,9 +1163,21 @@ loop:
                n->right = nod(OCONV, n->right, N);
                n->right->type = types[et];
                r = nod(OCALL, l, list(n->left, n->right));
+               r = nod(OCONV, r, N);
+               r->type = n->left->left->type;
                walktype(r, Erv);
                indir(n, r);
                goto ret;
+
+       case OASOP:
+               et = n->left->type->etype;
+               if(widthptr > 4 || (et != TUINT64 && et != TINT64))
+                       break;
+               l = saferef(n->left);
+               r = nod(OAS, l, nod(n->etype, l, n->right));
+               walktype(r, Etop);
+               indir(n, r);
+               goto ret;
        }
 
        if(t == T)