Closed
Description
package p
import "encoding/binary"
func f(key [4]byte, b []byte) {
k := binary.LittleEndian.Uint32(key[:])
v := binary.LittleEndian.Uint32(b)
binary.LittleEndian.PutUint32(b, v^k)
}
generates:
"".f STEXT nosplit size=62 args=0x20 locals=0x18
0x0000 00000 (x.go:5) TEXT "".f(SB), NOSPLIT|ABIInternal, $24-32
0x0000 00000 (x.go:5) SUBQ $24, SP
0x0004 00004 (x.go:5) MOVQ BP, 16(SP)
0x0009 00009 (x.go:5) LEAQ 16(SP), BP
0x000e 00014 (x.go:5) FUNCDATA $0, gclocals·09cf9819fc716118c209c2d2155a3632(SB)
0x000e 00014 (x.go:5) FUNCDATA $1, gclocals·69c1753bd5f81501d95132d08af04464(SB)
0x000e 00014 (x.go:5) FUNCDATA $2, gclocals·9fb7f0986f647f17cb53dda1484e0f7a(SB)
0x000e 00014 (x.go:6) PCDATA $0, $0
0x000e 00014 (x.go:6) PCDATA $1, $0
0x000e 00014 (x.go:6) XCHGL AX, AX
0x000f 00015 (x.go:7) XCHGL AX, AX
0x0010 00016 (x.go:6) MOVL "".key+32(SP), DX
0x0014 00020 ($GOROOT/src/encoding/binary/binary.go:63) MOVQ "".b+48(SP), CX
0x0019 00025 ($GOROOT/src/encoding/binary/binary.go:63) CMPQ CX, $3
0x001d 00029 ($GOROOT/src/encoding/binary/binary.go:63) JLS 51
0x001f 00031 (x.go:8) XCHGL AX, AX
0x0020 00032 (x.go:8) PCDATA $0, $1
0x0020 00032 (x.go:8) PCDATA $1, $1
0x0020 00032 (x.go:8) MOVQ "".b+40(SP), AX
0x0025 00037 (x.go:8) XORL (AX), DX
0x0027 00039 ($GOROOT/src/encoding/binary/binary.go:72) PCDATA $0, $0
0x0027 00039 ($GOROOT/src/encoding/binary/binary.go:72) MOVL DX, (AX)
0x0029 00041 (<unknown line number>) MOVQ 16(SP), BP
0x002e 00046 (<unknown line number>) ADDQ $24, SP
0x0032 00050 (<unknown line number>) RET
0x0033 00051 ($GOROOT/src/encoding/binary/binary.go:63) MOVL $3, AX
0x0038 00056 ($GOROOT/src/encoding/binary/binary.go:63) CALL runtime.panicIndex(SB)
0x003d 00061 ($GOROOT/src/encoding/binary/binary.go:63) XCHGL AX, AX
Note the side-by-side NOPs at 0x000e and 0x000f. (They do have different line numbers.) They are also at the beginning of the routine, before any other work has been done.
This makes me wonder whether we could eliminate either or both. @randall77 anything we can do here?