From: Keith Randall Date: Wed, 19 Mar 2014 22:41:34 +0000 (-0700) Subject: cmd/6g: do small zeroings with straightline code. X-Git-Tag: go1.3beta1~319 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=14664050b9dc5284f120faa3ca054eb3d04b77bb;p=gostls13.git cmd/6g: do small zeroings with straightline code. Removes most uses of the REP prefix, which has a high startup cost. LGTM=iant R=golang-codereviews, iant, khr CC=golang-codereviews https://golang.org/cl/77920043 --- diff --git a/src/cmd/6g/ggen.c b/src/cmd/6g/ggen.c index b046ac5a42..6dcf263035 100644 --- a/src/cmd/6g/ggen.c +++ b/src/cmd/6g/ggen.c @@ -16,6 +16,7 @@ defframe(Prog *ptxt) { uint32 frame; Prog *p; + vlong i; // fill in argument size ptxt->to.offset = rnd(curfn->type->argwid, widthptr); @@ -29,12 +30,25 @@ defframe(Prog *ptxt) // so that garbage collector only sees initialized values // when it looks for pointers. p = ptxt; - if(stkzerosize > 0) { - p = appendpp(p, movptr, D_CONST, 0, D_AX, 0); - p = appendpp(p, movptr, D_CONST, stkzerosize/widthptr, D_CX, 0); - p = appendpp(p, leaptr, D_SP+D_INDIR, frame-stkzerosize, D_DI, 0); - p = appendpp(p, AREP, D_NONE, 0, D_NONE, 0); - appendpp(p, stosptr, D_NONE, 0, D_NONE, 0); + if(stkzerosize % widthreg != 0) + fatal("zero size not a multiple of ptr size"); + if(stkzerosize == 0) { + // nothing + } else if(stkzerosize <= 2*widthreg) { + for(i = 0; i < stkzerosize; i += widthreg) { + p = appendpp(p, AMOVQ, D_CONST, 0, D_SP+D_INDIR, frame-stkzerosize+i); + } + } else if(stkzerosize <= 16*widthreg) { + p = appendpp(p, AMOVQ, D_CONST, 0, D_AX, 0); + for(i = 0; i < stkzerosize; i += widthreg) { + p = appendpp(p, AMOVQ, D_AX, 0, D_SP+D_INDIR, frame-stkzerosize+i); + } + } else { + p = appendpp(p, AMOVQ, D_CONST, 0, D_AX, 0); + p = appendpp(p, AMOVQ, D_CONST, stkzerosize/widthreg, D_CX, 0); + p = appendpp(p, leaptr, D_SP+D_INDIR, frame-stkzerosize, D_DI, 0); + p = appendpp(p, AREP, D_NONE, 0, D_NONE, 0); + appendpp(p, ASTOSQ, D_NONE, 0, D_NONE, 0); } } diff --git a/src/cmd/8g/ggen.c b/src/cmd/8g/ggen.c index 997811af36..741564ad53 100644 --- a/src/cmd/8g/ggen.c +++ b/src/cmd/8g/ggen.c @@ -16,6 +16,7 @@ defframe(Prog *ptxt) { uint32 frame; Prog *p; + vlong i; // fill in argument size ptxt->to.offset2 = rnd(curfn->type->argwid, widthptr); @@ -28,7 +29,20 @@ defframe(Prog *ptxt) // so that garbage collector only sees initialized values // when it looks for pointers. p = ptxt; - if(stkzerosize > 0) { + if(stkzerosize % widthptr != 0) + fatal("zero size not a multiple of ptr size"); + if(stkzerosize == 0) { + // nothing + } else if(stkzerosize <= 2*widthptr) { + for(i = 0; i < stkzerosize; i += widthptr) { + p = appendpp(p, AMOVL, D_CONST, 0, D_SP+D_INDIR, frame-stkzerosize+i); + } + } else if(stkzerosize <= 16*widthptr) { + p = appendpp(p, AMOVL, D_CONST, 0, D_AX, 0); + for(i = 0; i < stkzerosize; i += widthptr) { + p = appendpp(p, AMOVL, D_AX, 0, D_SP+D_INDIR, frame-stkzerosize+i); + } + } else { p = appendpp(p, AMOVL, D_CONST, 0, D_AX, 0); p = appendpp(p, AMOVL, D_CONST, stkzerosize/widthptr, D_CX, 0); p = appendpp(p, ALEAL, D_SP+D_INDIR, frame-stkzerosize, D_DI, 0);