]> Cypherpunks repositories - gostls13.git/commitdiff
fix bugs compiling things like
authorKen Thompson <ken@golang.org>
Tue, 9 Mar 2010 21:39:45 +0000 (13:39 -0800)
committerKen Thompson <ken@golang.org>
Tue, 9 Mar 2010 21:39:45 +0000 (13:39 -0800)
c = cmplx(imag(c), real(c))
without a temporary

R=rsc
CC=golang-dev
https://golang.org/cl/360043

src/cmd/gc/cplx.c

index 23f339914a519dd0167f31eee3ad99a20990c956..7538a432a350b4b1c87c430c621d79170c268a3e 100644 (file)
@@ -123,7 +123,7 @@ complexgen(Node *n, Node *res)
 {
        Node *nl, *nr;
        Node tnl, tnr;
-       Node n1, n2;
+       Node n1, n2, tmp;
        int tl, tr;
 
        if(debug['g']) {
@@ -135,8 +135,10 @@ complexgen(Node *n, Node *res)
        switch(n->op) {
        case OCMPLX:
                subnode(&n1, &n2, res);
-               cgen(n->left, &n1);
+               tempname(&tmp, n1.type);
+               cgen(n->left, &tmp);
                cgen(n->right, &n2);
+               cgen(&tmp, &n1);
                return;
 
        case OREAL:
@@ -428,19 +430,21 @@ complexadd(int op, Node *nl, Node *nr, Node *res)
 }
 
 // build and execute tree
-//     real(res) = real(nl)*real(nr) - imag(nl)*imag(nr)
+//     tmp       = real(nl)*real(nr) - imag(nl)*imag(nr)
 //     imag(res) = real(nl)*imag(nr) + imag(nl)*real(nr)
+//     real(res) = tmp
 void
 complexmul(Node *nl, Node *nr, Node *res)
 {
        Node n1, n2, n3, n4, n5, n6;
-       Node rm1, rm2, ra;
+       Node rm1, rm2, ra, tmp;
 
        subnode(&n1, &n2, nl);
        subnode(&n3, &n4, nr);
        subnode(&n5, &n6, res);
+       tempname(&tmp, n5.type);
 
-       // real part
+       // real part -> tmp
        memset(&rm1, 0, sizeof(ra));
        rm1.op = OMUL;
        rm1.left = &n1;
@@ -458,7 +462,7 @@ complexmul(Node *nl, Node *nr, Node *res)
        ra.left = &rm1;
        ra.right = &rm2;
        ra.type = rm1.type;
-       cgen(&ra, &n5);
+       cgen(&ra, &tmp);
 
        // imag part
        memset(&rm1, 0, sizeof(ra));
@@ -479,4 +483,7 @@ complexmul(Node *nl, Node *nr, Node *res)
        ra.right = &rm2;
        ra.type = rm1.type;
        cgen(&ra, &n6);
+
+       // tmp ->real part
+       cgen(&tmp, &n5);
 }