]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/6g: do small zeroings with straightline code.
authorKeith Randall <khr@golang.org>
Wed, 19 Mar 2014 22:41:34 +0000 (15:41 -0700)
committerKeith Randall <khr@golang.org>
Wed, 19 Mar 2014 22:41:34 +0000 (15:41 -0700)
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

src/cmd/6g/ggen.c
src/cmd/8g/ggen.c

index b046ac5a425c70020fb37ff8c5c8ab0be1d988e1..6dcf26303505a9249ff3d56f9ce00be6040359a7 100644 (file)
@@ -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);
        }
 }
 
index 997811af36fb3c13c0087db25da885665dd2a521..741564ad53e6fd0863a90062d12ece8ca9ec1664 100644 (file)
@@ -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);