]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/6c, cmd/8c: avoid generating long multiplication when not necessary.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Tue, 4 Jun 2013 06:33:00 +0000 (08:33 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Tue, 4 Jun 2013 06:33:00 +0000 (08:33 +0200)
On amd64
benchmark                        old ns/op    new ns/op    delta
BenchmarkHashStringSpeed                91           74  -18.49%
BenchmarkHashInt32Speed                 54           45  -17.88%
BenchmarkHashInt64Speed                 76           58  -23.53%
BenchmarkHashStringArraySpeed          231          188  -18.61%

Fixes #5367.

R=golang-dev, iant, dave, daniel.morsing, ality, rsc
CC=golang-dev
https://golang.org/cl/9040043

src/cmd/6c/cgen.c
src/cmd/8c/cgen.c

index 95400c445357e317892b1d6e84fb1836b1ad607d..7afacb21778f2187a5fe78b2844e3d71d50dad76 100644 (file)
@@ -392,13 +392,13 @@ cgen(Node *n, Node *nn)
                        }
                }
 
-               if(o == OMUL) {
+               if(o == OMUL || o == OLMUL) {
                        if(l->addable >= INDEXED) {
                                t = l;
                                l = r;
                                r = t;
                        }
-                       /* should favour AX */
+                       reg[D_DX]++; // for gopcode case OMUL
                        regalloc(&nod, l, nn);
                        cgen(l, &nod);
                        if(r->addable < INDEXED || hardconst(r)) {
@@ -410,6 +410,7 @@ cgen(Node *n, Node *nn)
                                gopcode(OMUL, n->type, r, &nod);        /* addressible */
                        gmove(&nod, nn);
                        regfree(&nod);
+                       reg[D_DX]--;
                        break;
                }
 
index 78eb7ecedb3b7f6f4b71d8d748bf9a0c519f576c..4d4ae13abeebe1d6b63cc3e5885973393cb3f5fa 100644 (file)
@@ -404,13 +404,13 @@ cgen(Node *n, Node *nn)
                        }
                }
 
-               if(o == OMUL) {
+               if(o == OMUL || o == OLMUL) {
                        if(l->addable >= INDEXED) {
                                t = l;
                                l = r;
                                r = t;
                        }
-                       /* should favour AX */
+                       reg[D_DX]++; // for gopcode case OMUL
                        regalloc(&nod, l, nn);
                        cgen(l, &nod);
                        if(r->addable < INDEXED) {
@@ -422,6 +422,7 @@ cgen(Node *n, Node *nn)
                                gopcode(OMUL, n->type, r, &nod);        /* addressible */
                        gmove(&nod, nn);
                        regfree(&nod);
+                       reg[D_DX]--;
                        break;
                }