1
0
mirror of https://github.com/golang/go synced 2024-11-26 22:01:27 -07:00

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
This commit is contained in:
Dave Cheney 2012-12-12 19:25:22 +11:00
parent 11999306df
commit 5bdf40dcca
2 changed files with 14 additions and 7 deletions

View 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

View 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):