cmd/compile,runtime: pass only ptr and len to some runtime calls

Some runtime calls accept a slice, but only use ptr and len.
This change modifies most such routines to accept only ptr and len.

After this change, the only runtime calls that accept an unnecessary
cap arg are concatstrings and slicerunetostring.
Neither is particularly common, and both are complicated to modify.

Negligible compiler performance impact. Shrinks binaries a little.
There are only a few regressions; the one I investigated was
due to register allocation fluctuation.

Passes 'go test -race std cmd', modulo #38265 and #38266.
Wow, does that take a long time to run.

Updates #36890

file      before    after     Δ       %       
compile   19655024  19655152  +128    +0.001% 
cover     5244840   5236648   -8192   -0.156% 
dist      3662376   3658280   -4096   -0.112% 
link      6680056   6675960   -4096   -0.061% 
pprof     14789844  14777556  -12288  -0.083% 
test2json 2824744   2820648   -4096   -0.145% 
trace     11647876  11639684  -8192   -0.070% 
vet       8260472   8256376   -4096   -0.050% 
total     115163736 115118808 -44928  -0.039% 

Change-Id: Idb29fa6a81d6a82bfd3b65740b98cf3275ca0a78
Reviewed-on: https://go-review.googlesource.com/c/go/+/227163
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2020-01-31 21:01:55 -08:00
parent ade0811dc8
commit b6feb03b24
10 changed files with 153 additions and 109 deletions

View file

@ -194,14 +194,14 @@ func isPowerOfTwo(x uintptr) bool {
return x&(x-1) == 0
}
func slicecopy(to, fm slice, width uintptr) int {
if fm.len == 0 || to.len == 0 {
func slicecopy(toPtr unsafe.Pointer, toLen int, fmPtr unsafe.Pointer, fmLen int, width uintptr) int {
if fmLen == 0 || toLen == 0 {
return 0
}
n := fm.len
if to.len < n {
n = to.len
n := fmLen
if toLen < n {
n = toLen
}
if width == 0 {
@ -211,43 +211,43 @@ func slicecopy(to, fm slice, width uintptr) int {
if raceenabled {
callerpc := getcallerpc()
pc := funcPC(slicecopy)
racereadrangepc(fm.array, uintptr(n*int(width)), callerpc, pc)
racewriterangepc(to.array, uintptr(n*int(width)), callerpc, pc)
racereadrangepc(fmPtr, uintptr(n*int(width)), callerpc, pc)
racewriterangepc(toPtr, uintptr(n*int(width)), callerpc, pc)
}
if msanenabled {
msanread(fm.array, uintptr(n*int(width)))
msanwrite(to.array, uintptr(n*int(width)))
msanread(fmPtr, uintptr(n*int(width)))
msanwrite(toPtr, uintptr(n*int(width)))
}
size := uintptr(n) * width
if size == 1 { // common case worth about 2x to do here
// TODO: is this still worth it with new memmove impl?
*(*byte)(to.array) = *(*byte)(fm.array) // known to be a byte pointer
*(*byte)(toPtr) = *(*byte)(fmPtr) // known to be a byte pointer
} else {
memmove(to.array, fm.array, size)
memmove(toPtr, fmPtr, size)
}
return n
}
func slicestringcopy(to []byte, fm string) int {
if len(fm) == 0 || len(to) == 0 {
func slicestringcopy(toPtr *byte, toLen int, fm string) int {
if len(fm) == 0 || toLen == 0 {
return 0
}
n := len(fm)
if len(to) < n {
n = len(to)
if toLen < n {
n = toLen
}
if raceenabled {
callerpc := getcallerpc()
pc := funcPC(slicestringcopy)
racewriterangepc(unsafe.Pointer(&to[0]), uintptr(n), callerpc, pc)
racewriterangepc(unsafe.Pointer(toPtr), uintptr(n), callerpc, pc)
}
if msanenabled {
msanwrite(unsafe.Pointer(&to[0]), uintptr(n))
msanwrite(unsafe.Pointer(toPtr), uintptr(n))
}
memmove(unsafe.Pointer(&to[0]), stringStructOf(&fm).str, uintptr(n))
memmove(unsafe.Pointer(toPtr), stringStructOf(&fm).str, uintptr(n))
return n
}