Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d211c2d

Browse files
committed
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 <[email protected]> Run-TryBot: Austin Clements <[email protected]> Reviewed-by: David Crawshaw <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent aaf4099 commit d211c2d

File tree

9 files changed

+8
-48
lines changed

9 files changed

+8
-48
lines changed

src/runtime/asm_386.s

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,6 @@ setbar:
808808
CALL runtime·setNextBarrierPC(SB)
809809
RET
810810

811-
TEXT runtime·getcallersp(SB), NOSPLIT, $0-8
812-
MOVL argp+0(FP), AX
813-
MOVL AX, ret+4(FP)
814-
RET
815-
816811
// func cputicks() int64
817812
TEXT runtime·cputicks(SB),NOSPLIT,$0-8
818813
TESTL $0x4000000, runtime·cpuid_edx(SB) // no sse2, no mfence

src/runtime/asm_amd64.s

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,6 @@ setbar:
825825
CALL runtime·setNextBarrierPC(SB)
826826
RET
827827

828-
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
829-
MOVQ argp+0(FP), AX
830-
MOVQ AX, ret+8(FP)
831-
RET
832-
833828
// func cputicks() int64
834829
TEXT runtime·cputicks(SB),NOSPLIT,$0-0
835830
CMPB runtime·lfenceBeforeRdtsc(SB), $1

src/runtime/asm_amd64p32.s

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,6 @@ setbar:
521521
CALL runtime·setNextBarrierPC(SB)
522522
RET
523523

524-
TEXT runtime·getcallersp(SB),NOSPLIT,$0-12
525-
MOVL argp+0(FP), AX
526-
MOVL AX, ret+8(FP)
527-
RET
528-
529524
// int64 runtime·cputicks(void)
530525
TEXT runtime·cputicks(SB),NOSPLIT,$0-0
531526
RDTSC

src/runtime/asm_arm.s

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,6 @@ setbar:
695695
BL runtime·setNextBarrierPC(SB)
696696
RET
697697

698-
TEXT runtime·getcallersp(SB),NOSPLIT,$-4-8
699-
MOVW argp+0(FP), R0
700-
MOVW $-4(R0), R0
701-
MOVW R0, ret+4(FP)
702-
RET
703-
704698
TEXT runtime·emptyfunc(SB),0,$0-0
705699
RET
706700

src/runtime/asm_arm64.s

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,6 @@ setbar:
731731
BL runtime·setNextBarrierPC(SB)
732732
RET
733733

734-
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
735-
MOVD argp+0(FP), R0
736-
SUB $8, R0
737-
MOVD R0, ret+8(FP)
738-
RET
739-
740734
TEXT runtime·abort(SB),NOSPLIT,$-8-0
741735
B (ZR)
742736
UNDEF

src/runtime/asm_mips64x.s

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,6 @@ setbar:
643643
JAL runtime·setNextBarrierPC(SB)
644644
RET
645645

646-
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
647-
MOVV argp+0(FP), R1
648-
ADDV $-8, R1
649-
MOVV R1, ret+8(FP)
650-
RET
651-
652646
TEXT runtime·abort(SB),NOSPLIT,$-8-0
653647
MOVW (R0), R0
654648
UNDEF

src/runtime/asm_ppc64x.s

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,6 @@ setbar:
742742
BL runtime·setNextBarrierPC(SB)
743743
RET
744744

745-
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
746-
MOVD argp+0(FP), R3
747-
SUB $FIXED_FRAME, R3
748-
MOVD R3, ret+8(FP)
749-
RET
750-
751745
TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
752746
MOVW (R0), R0
753747
UNDEF

src/runtime/asm_s390x.s

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,6 @@ setbar:
715715
BL runtime·setNextBarrierPC(SB)
716716
RET
717717

718-
TEXT runtime·getcallersp(SB),NOSPLIT,$0-16
719-
MOVD argp+0(FP), R3
720-
SUB $8, R3
721-
MOVD R3, ret+8(FP)
722-
RET
723-
724718
TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
725719
MOVW (R0), R0
726720
UNDEF

src/runtime/stubs.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package runtime
66

7-
import "unsafe"
7+
import (
8+
"runtime/internal/sys"
9+
"unsafe"
10+
)
811

912
// Should be a built-in for unsafe.Pointer?
1013
//go:nosplit
@@ -196,8 +199,10 @@ func setcallerpc(argp unsafe.Pointer, pc uintptr)
196199
//go:noescape
197200
func getcallerpc(argp unsafe.Pointer) uintptr
198201

199-
//go:noescape
200-
func getcallersp(argp unsafe.Pointer) uintptr
202+
//go:nosplit
203+
func getcallersp(argp unsafe.Pointer) uintptr {
204+
return uintptr(argp) - sys.MinFrameSize
205+
}
201206

202207
//go:noescape
203208
func asmcgocall(fn, arg unsafe.Pointer) int32

0 commit comments

Comments
 (0)