]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/5g: avoid temporary during OMINUS
authorDave Cheney <dave@cheney.net>
Wed, 12 Dec 2012 08:25:22 +0000 (19:25 +1100)
committerDave Cheney <dave@cheney.net>
Wed, 12 Dec 2012 08:25:22 +0000 (19:25 +1100)
Saves one MOVW and one register during the fast div/mod introduced in CL 6819123.

linux/arm (armv5)

benchmark               old ns/op    new ns/op    delta
BenchmarkInt64Mod1             12           12   +7.50%
BenchmarkUint16Mod2             7            7   +0.28%
BenchmarkUint16Mod4             7            7   -0.28%
BenchmarkUint64Mod1            15           11  -23.72%
BenchmarkInt8Neg                8            7  -17.66%
BenchmarkInt16Neg               8            7  -17.66%
BenchmarkInt32Neg               5            5   -9.04%
BenchmarkUint8Neg               7            6  -14.35%
BenchmarkUint16Neg              8            7  -17.66%
BenchmarkUint32Neg              5            5   -9.04%

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

src/cmd/5g/cgen.c
src/cmd/5g/gsubr.c

index af5df7274917323d11333fa6dacc9993362f0014..93257410591cf3f2ba799b0181337deb2daf928f 100644 (file)
@@ -15,7 +15,7 @@ void
 cgen(Node *n, Node *res)
 {
        Node *nl, *nr, *r;
-       Node n1, n2, n3, f0, f1;
+       Node n1, n2, f0, f1;
        int a, w, rg;
        Prog *p1, *p2, *p3;
        Addr addr;
@@ -240,13 +240,10 @@ cgen(Node *n, Node *res)
        case OMINUS:
                regalloc(&n1, nl->type, N);
                cgen(nl, &n1);
-               nodconst(&n3, nl->type, 0);
-               regalloc(&n2, nl->type, res);
-               gmove(&n3, &n2);
-               gins(optoas(OSUB, nl->type), &n1, &n2);
-               gmove(&n2, res);
+               nodconst(&n2, nl->type, 0);
+               gins(optoas(OMINUS, nl->type), &n2, &n1);
+               gmove(&n1, res);
                regfree(&n1);
-               regfree(&n2);
                goto ret;
 
        // symmetric binary
index bf4dded8f85c9de27fa11da85e25613f21be3eab..0885601225116227f04d96b7bd751a2f0ebc3782 100644 (file)
@@ -1611,6 +1611,16 @@ optoas(int op, Type *t)
                a = ASUBD;
                break;
 
+       case CASE(OMINUS, TINT8):
+       case CASE(OMINUS, TUINT8):
+       case CASE(OMINUS, TINT16):
+       case CASE(OMINUS, TUINT16):
+       case CASE(OMINUS, TINT32):
+       case CASE(OMINUS, TUINT32):
+       case CASE(OMINUS, TPTR32):
+               a = ARSB;
+               break;
+
        case CASE(OAND, TINT8):
        case CASE(OAND, TUINT8):
        case CASE(OAND, TINT16):