runtime: remove a branch from funcdata

name                   old time/op  new time/op  delta
StackCopyWithStkobj-8  12.1ms ± 7%  11.6ms ± 8%  -3.88%  (p=0.002 n=19+19)

Change-Id: Idf810017d541eba70bcf9c736267de9efae916d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/354072
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Josh Bleecher Snyder 2021-10-05 10:21:54 -07:00
parent 75773b0e7b
commit 113b52979f

View file

@ -1090,10 +1090,15 @@ func funcdata(f funcInfo, i uint8) unsafe.Pointer {
}
p = add(p, uintptr(i)*4)
off := *(*uint32)(p)
// Return off == ^uint32(0) ? 0 : f.datap.gofunc + uintptr(off), but without branches.
// The compiler calculates mask on most architectures using conditional assignment.
var mask uintptr
if off == ^uint32(0) {
return nil
mask = 1
}
return unsafe.Pointer(f.datap.gofunc + uintptr(off))
mask--
raw := f.datap.gofunc + uintptr(off)
return unsafe.Pointer(raw & mask)
}
// step advances to the next pc, value pair in the encoded table.