From: Josh Bleecher Snyder Date: Tue, 5 Oct 2021 17:21:54 +0000 (-0700) Subject: runtime: remove a branch from funcdata X-Git-Tag: go1.18beta1~1042 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=113b52979f48331b611e0fe7dadff97d6393ca27;p=gostls13.git 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 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Go Bot Reviewed-by: Cherry Mui --- diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index cbfe604f1b..f423957f88 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -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.