]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove a branch from funcdata
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 5 Oct 2021 17:21:54 +0000 (10:21 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 5 Oct 2021 20:35:48 +0000 (20:35 +0000)
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>
src/runtime/symtab.go

index cbfe604f1bb279f6b925ff4fd44993f7f698662d..f423957f88b519ac718c27a559d4ba4a40838055 100644 (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.