From: Dave Cheney Date: Wed, 12 Dec 2012 08:25:22 +0000 (+1100) Subject: cmd/5g: avoid temporary during OMINUS X-Git-Tag: go1.1rc2~1656 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5bdf40dccab1fec0660c4374be9046d82a1a004f;p=gostls13.git cmd/5g: avoid temporary during OMINUS 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 --- diff --git a/src/cmd/5g/cgen.c b/src/cmd/5g/cgen.c index af5df72749..9325741059 100644 --- a/src/cmd/5g/cgen.c +++ b/src/cmd/5g/cgen.c @@ -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 diff --git a/src/cmd/5g/gsubr.c b/src/cmd/5g/gsubr.c index bf4dded8f8..0885601225 100644 --- a/src/cmd/5g/gsubr.c +++ b/src/cmd/5g/gsubr.c @@ -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):