From 372b5cebe7ba84218fdc724b2f17279a53293836 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Wed, 13 Aug 2014 01:22:34 -0400 Subject: [PATCH] [dev.power64] cmd/9g: use loops to do memmove in sgen() LGTM=rsc R=rsc, iant CC=golang-codereviews https://golang.org/cl/128130044 --- src/cmd/9g/cgen.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/cmd/9g/cgen.c b/src/cmd/9g/cgen.c index f8078aece3..a8d628f43b 100644 --- a/src/cmd/9g/cgen.c +++ b/src/cmd/9g/cgen.c @@ -1344,10 +1344,10 @@ stkof(Node *n) void sgen(Node *n, Node *ns, int64 w) { - Node dst, src, tmp; + Node dst, src, tmp, nend; int32 c, odst, osrc; int dir, align, op; - Prog *p; + Prog *p, *ploop; NodeList *l; Node *res = ns; @@ -1447,19 +1447,15 @@ sgen(Node *n, Node *ns, int64 w) regalloc(&tmp, types[tptr], N); // set up end marker - //memset(&nend, 0, sizeof nend); - //if(c >= 4) { - // regalloc(&nend, types[tptr], N); - // p = gins(AMOVD, &src, &nend); - // p->from.type = D_CONST; - // if(dir < 0) - // p->from.offset = dir; - // else - // p->from.offset = w; - //} + memset(&nend, 0, sizeof nend); // move src and dest to the end of block if necessary if(dir < 0) { + if(c >= 4) { + regalloc(&nend, types[tptr], N); + p = gins(AMOVD, &src, &nend); + } + p = gins(AADD, N, &src); p->from.type = D_CONST; p->from.offset = w; @@ -1475,11 +1471,19 @@ sgen(Node *n, Node *ns, int64 w) p = gins(AADD, N, &dst); p->from.type = D_CONST; p->from.offset = -dir; + + if(c >= 4) { + regalloc(&nend, types[tptr], N); + p = gins(AMOVD, &src, &nend); + p->from.type = D_CONST; + p->from.offset = w; + } } - + + // move - // TODO: enable loops and duffcopy for larger copies. - /*if(c >= 4) { + // TODO: enable duffcopy for larger copies. + if(c >= 4) { p = gins(op, &src, &tmp); p->from.type = D_OREG; p->from.offset = dir; @@ -1489,12 +1493,11 @@ sgen(Node *n, Node *ns, int64 w) p->to.type = D_OREG; p->to.offset = dir; - p = gins(ACMP, &src, N); - raddr(&nend, p); + p = gins(ACMP, &src, &nend); patch(gbranch(ABNE, T, 0), ploop); regfree(&nend); - } else*/ { + } else { while(c-- > 0) { p = gins(op, &src, &tmp); p->from.type = D_OREG;