From 113b52979f48331b611e0fe7dadff97d6393ca27 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 5 Oct 2021 10:21:54 -0700 Subject: [PATCH] runtime: remove a branch from funcdata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/runtime/symtab.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index cbfe604f1bb..f423957f88b 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.