1
0
mirror of https://github.com/golang/go synced 2024-11-20 08:04:42 -07:00

cmd/5g: peep.c: reactivate some optimisations

Thanks to Minux and Remy for their advice.

The EOR optimisation is applied to a few places in the stdlib.

// hash/crc32/crc32.go
func update(crc uint32, tab *Table, p []byte) uint32 {
	crc = ^crc
	for _, v := range p {
        	crc = tab[byte(crc)^v] ^ (crc >> 8)
	}
	return ^crc
}

before:

--- prog list "update" ---
0164 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:101) TEXT        update+0(SB),$12-24
0165 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:101) MOVW        tab+4(FP),R8
0166 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:102) MOVW        crc+0(FP),R0
0167 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:102) EOR         $-1,R0,R5
0168 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:103) MOVW        p+8(FP),R0
0169 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:103) MOVW        R0,autotmp_0019+-12(SP)

after:

--- prog list "update" ---
0164 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:101) TEXT        update+0(SB),$12-24
0165 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:101) MOVW        tab+4(FP),R8
0166 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:102) MOVW        crc+0(FP),R0
0167 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:102) MVN         R0,R5
0168 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:103) MOVW        p+8(FP),R0
0169 (/home/dfc/go/src/pkg/hash/crc32/crc32.go:103) MOVW        R0,autotmp_0019+-12(SP)

After 5l has done its work,

        crc = ^crc
   3d710:       e59d0014        ldr     r0, [sp, #20]
   3d714:       e3e0b000        mvn     fp, #0
   3d718:       e020500b        eor     r5, r0, fp

becomes

        crc = ^crc
   3d710:       e59d0014        ldr     r0, [sp, #20]
   3d714:       e1e05000        mvn     r5, r0

The MOVB optimisation has a small impact on the stdlib, in strconv
and gzip.

// GZIP (RFC 1952) is little-endian, unlike ZLIB (RFC 1950).
func put2(p []byte, v uint16) {
        p[0] = uint8(v >> 0)
        p[1] = uint8(v >> 8)
}

before:

--- prog list "put2" ---
1369 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:76) TEXT       put2+0(SB),$0-16
1370 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:76) MOVHU      v+12(FP),R4
1371 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVHU      R4,R0
1372 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVHU      R0,R0
1373 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVBU      R0,R1
1374 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVBU      R1,R3
1375 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVW       $p+0(FP),R1

after:

--- prog list "put2" ---
1369 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:76) TEXT       put2+0(SB),$0-16
1370 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:76) MOVHU      v+12(FP),R4
1371 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVHU      R4,R0
1372 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVBU      R0,R1
1373 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVBU      R1,R3
1374 (/home/dfc/go/src/pkg/compress/gzip/gzip.go:77) MOVW       $p+0(FP),R1

R=remyoudompheng, rsc, minux.ma
CC=golang-dev
https://golang.org/cl/6674048
This commit is contained in:
Dave Cheney 2012-10-26 18:19:10 +11:00
parent 38070a72c5
commit 542dd8b9fb

View File

@ -133,26 +133,24 @@ loop1:
if(t) if(t)
goto loop1; goto loop1;
return;
#ifdef NOTDEF
for(r=firstr; r!=R; r=r->link) { for(r=firstr; r!=R; r=r->link) {
p = r->prog; p = r->prog;
switch(p->as) { switch(p->as) {
// case AEOR: case AEOR:
// /* /*
// * EOR -1,x,y => MVN x,y * EOR -1,x,y => MVN x,y
// */ */
// if(isdconst(&p->from) && p->from.offset == -1) { if(isdconst(&p->from) && p->from.offset == -1) {
// p->as = AMVN; p->as = AMVN;
// p->from.type = D_REG; p->from.type = D_REG;
// if(p->reg != NREG) if(p->reg != NREG)
// p->from.reg = p->reg; p->from.reg = p->reg;
// else else
// p->from.reg = p->to.reg; p->from.reg = p->to.reg;
// p->reg = NREG; p->reg = NREG;
// } }
// break; break;
case AMOVH: case AMOVH:
case AMOVHU: case AMOVHU:
@ -161,6 +159,7 @@ return;
/* /*
* look for MOVB x,R; MOVB R,R * look for MOVB x,R; MOVB R,R
*/ */
r1 = r->link;
if(p->to.type != D_REG) if(p->to.type != D_REG)
break; break;
if(r1 == R) if(r1 == R)
@ -175,8 +174,8 @@ return;
excise(r1); excise(r1);
break; break;
} }
r1 = r->link;
} }
#ifdef NOTDEF
// for(r=firstr; r!=R; r=r->link) { // for(r=firstr; r!=R; r=r->link) {
// p = r->prog; // p = r->prog;