Commit 14664050 authored by Keith Randall's avatar Keith Randall

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
parent b00d9677
...@@ -16,6 +16,7 @@ defframe(Prog *ptxt) ...@@ -16,6 +16,7 @@ defframe(Prog *ptxt)
{ {
uint32 frame; uint32 frame;
Prog *p; Prog *p;
vlong i;
// fill in argument size // fill in argument size
ptxt->to.offset = rnd(curfn->type->argwid, widthptr); ptxt->to.offset = rnd(curfn->type->argwid, widthptr);
...@@ -29,12 +30,25 @@ defframe(Prog *ptxt) ...@@ -29,12 +30,25 @@ defframe(Prog *ptxt)
// so that garbage collector only sees initialized values // so that garbage collector only sees initialized values
// when it looks for pointers. // when it looks for pointers.
p = ptxt; p = ptxt;
if(stkzerosize > 0) { if(stkzerosize % widthreg != 0)
p = appendpp(p, movptr, D_CONST, 0, D_AX, 0); fatal("zero size not a multiple of ptr size");
p = appendpp(p, movptr, D_CONST, stkzerosize/widthptr, D_CX, 0); if(stkzerosize == 0) {
p = appendpp(p, leaptr, D_SP+D_INDIR, frame-stkzerosize, D_DI, 0); // nothing
p = appendpp(p, AREP, D_NONE, 0, D_NONE, 0); } else if(stkzerosize <= 2*widthreg) {
appendpp(p, stosptr, D_NONE, 0, D_NONE, 0); 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);
} }
} }
......
...@@ -16,6 +16,7 @@ defframe(Prog *ptxt) ...@@ -16,6 +16,7 @@ defframe(Prog *ptxt)
{ {
uint32 frame; uint32 frame;
Prog *p; Prog *p;
vlong i;
// fill in argument size // fill in argument size
ptxt->to.offset2 = rnd(curfn->type->argwid, widthptr); ptxt->to.offset2 = rnd(curfn->type->argwid, widthptr);
...@@ -28,7 +29,20 @@ defframe(Prog *ptxt) ...@@ -28,7 +29,20 @@ defframe(Prog *ptxt)
// so that garbage collector only sees initialized values // so that garbage collector only sees initialized values
// when it looks for pointers. // when it looks for pointers.
p = ptxt; 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, 0, D_AX, 0);
p = appendpp(p, AMOVL, D_CONST, stkzerosize/widthptr, D_CX, 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); p = appendpp(p, ALEAL, D_SP+D_INDIR, frame-stkzerosize, D_DI, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment