runtime: implement getcallersp in Go

This makes it possible to inline getcallersp. getcallersp is on the
hot path of defers, so this slightly speeds up defer:

name           old time/op  new time/op  delta
Defer-4        78.3ns ± 2%  75.1ns ± 1%  -4.00%   (p=0.000 n=9+8)

Updates #14939.

Change-Id: Icc1cc4cd2f0a81fc4c8344432d0b2e783accacdd
Reviewed-on: https://go-review.googlesource.com/29655
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Austin Clements 2016-09-22 17:02:22 -04:00
parent aaf4099a5c
commit d211c2d377
9 changed files with 8 additions and 48 deletions

View file

@ -808,11 +808,6 @@ setbar:
CALL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB), NOSPLIT, $0-8
MOVL argp+0(FP), AX
MOVL AX, ret+4(FP)
RET
// func cputicks() int64
TEXT runtime·cputicks(SB),NOSPLIT,$0-8
TESTL $0x4000000, runtime·cpuid_edx(SB) // no sse2, no mfence

View file

@ -825,11 +825,6 @@ setbar:
CALL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
MOVQ argp+0(FP), AX
MOVQ AX, ret+8(FP)
RET
// func cputicks() int64
TEXT runtime·cputicks(SB),NOSPLIT,$0-0
CMPB runtime·lfenceBeforeRdtsc(SB), $1

View file

@ -521,11 +521,6 @@ setbar:
CALL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-12
MOVL argp+0(FP), AX
MOVL AX, ret+8(FP)
RET
// int64 runtime·cputicks(void)
TEXT runtime·cputicks(SB),NOSPLIT,$0-0
RDTSC

View file

@ -695,12 +695,6 @@ setbar:
BL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$-4-8
MOVW argp+0(FP), R0
MOVW $-4(R0), R0
MOVW R0, ret+4(FP)
RET
TEXT runtime·emptyfunc(SB),0,$0-0
RET

View file

@ -731,12 +731,6 @@ setbar:
BL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
MOVD argp+0(FP), R0
SUB $8, R0
MOVD R0, ret+8(FP)
RET
TEXT runtime·abort(SB),NOSPLIT,$-8-0
B (ZR)
UNDEF

View file

@ -643,12 +643,6 @@ setbar:
JAL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
MOVV argp+0(FP), R1
ADDV $-8, R1
MOVV R1, ret+8(FP)
RET
TEXT runtime·abort(SB),NOSPLIT,$-8-0
MOVW (R0), R0
UNDEF

View file

@ -742,12 +742,6 @@ setbar:
BL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
MOVD argp+0(FP), R3
SUB $FIXED_FRAME, R3
MOVD R3, ret+8(FP)
RET
TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
MOVW (R0), R0
UNDEF

View file

@ -715,12 +715,6 @@ setbar:
BL runtime·setNextBarrierPC(SB)
RET
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
MOVD argp+0(FP), R3
SUB $8, R3
MOVD R3, ret+8(FP)
RET
TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
MOVW (R0), R0
UNDEF

View file

@ -4,7 +4,10 @@
package runtime
import "unsafe"
import (
"runtime/internal/sys"
"unsafe"
)
// Should be a built-in for unsafe.Pointer?
//go:nosplit
@ -196,8 +199,10 @@ func setcallerpc(argp unsafe.Pointer, pc uintptr)
//go:noescape
func getcallerpc(argp unsafe.Pointer) uintptr
//go:noescape
func getcallersp(argp unsafe.Pointer) uintptr
//go:nosplit
func getcallersp(argp unsafe.Pointer) uintptr {
return uintptr(argp) - sys.MinFrameSize
}
//go:noescape
func asmcgocall(fn, arg unsafe.Pointer) int32