Commit c5d6c42d authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

runtime: improve 386/amd64 systemstack

Minor improvements, noticed while investigating other things.

Shorten the prologue.

Make branch direction better for static branch prediction;
the most common case by far is switching stacks (g==curg).

Change-Id: Ib2211d3efecb60446355cda56194221ccb78057d
Reviewed-on: https://go-review.googlesource.com/97377
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent f399af31
...@@ -424,24 +424,17 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-4 ...@@ -424,24 +424,17 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-4
MOVL g(CX), AX // AX = g MOVL g(CX), AX // AX = g
MOVL g_m(AX), BX // BX = m MOVL g_m(AX), BX // BX = m
MOVL m_gsignal(BX), DX // DX = gsignal CMPL AX, m_gsignal(BX)
CMPL AX, DX
JEQ noswitch JEQ noswitch
MOVL m_g0(BX), DX // DX = g0 MOVL m_g0(BX), DX // DX = g0
CMPL AX, DX CMPL AX, DX
JEQ noswitch JEQ noswitch
MOVL m_curg(BX), BP CMPL AX, m_curg(BX)
CMPL AX, BP JNE bad
JEQ switch
// Bad: g is not gsignal, not g0, not curg. What is it?
// Hide call from linker nosplit analysis.
MOVL $runtime·badsystemstack(SB), AX
CALL AX
switch: // switch stacks
// save our state in g->sched. Pretend to // save our state in g->sched. Pretend to
// be systemstack_switch if the G stack is scanned. // be systemstack_switch if the G stack is scanned.
MOVL $runtime·systemstack_switch(SB), (g_sched+gobuf_pc)(AX) MOVL $runtime·systemstack_switch(SB), (g_sched+gobuf_pc)(AX)
...@@ -481,6 +474,12 @@ noswitch: ...@@ -481,6 +474,12 @@ noswitch:
MOVL 0(DI), DI MOVL 0(DI), DI
JMP DI JMP DI
bad:
// Bad: g is not gsignal, not g0, not curg. What is it?
// Hide call from linker nosplit analysis.
MOVL $runtime·badsystemstack(SB), AX
CALL AX
/* /*
* support for morestack * support for morestack
*/ */
......
...@@ -369,23 +369,17 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-8 ...@@ -369,23 +369,17 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-8
MOVQ g(CX), AX // AX = g MOVQ g(CX), AX // AX = g
MOVQ g_m(AX), BX // BX = m MOVQ g_m(AX), BX // BX = m
MOVQ m_gsignal(BX), DX // DX = gsignal CMPQ AX, m_gsignal(BX)
CMPQ AX, DX
JEQ noswitch JEQ noswitch
MOVQ m_g0(BX), DX // DX = g0 MOVQ m_g0(BX), DX // DX = g0
CMPQ AX, DX CMPQ AX, DX
JEQ noswitch JEQ noswitch
MOVQ m_curg(BX), R8 CMPQ AX, m_curg(BX)
CMPQ AX, R8 JNE bad
JEQ switch
// Bad: g is not gsignal, not g0, not curg. What is it?
MOVQ $runtime·badsystemstack(SB), AX
CALL AX
switch: // switch stacks
// save our state in g->sched. Pretend to // save our state in g->sched. Pretend to
// be systemstack_switch if the G stack is scanned. // be systemstack_switch if the G stack is scanned.
MOVQ $runtime·systemstack_switch(SB), SI MOVQ $runtime·systemstack_switch(SB), SI
...@@ -426,6 +420,12 @@ noswitch: ...@@ -426,6 +420,12 @@ noswitch:
MOVQ 0(DI), DI MOVQ 0(DI), DI
JMP DI JMP DI
bad:
// Bad: g is not gsignal, not g0, not curg. What is it?
MOVQ $runtime·badsystemstack(SB), AX
CALL AX
/* /*
* support for morestack * support for morestack
*/ */
......
...@@ -260,24 +260,17 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-4 ...@@ -260,24 +260,17 @@ TEXT runtime·systemstack(SB), NOSPLIT, $0-4
MOVL g(CX), AX // AX = g MOVL g(CX), AX // AX = g
MOVL g_m(AX), BX // BX = m MOVL g_m(AX), BX // BX = m
MOVL m_gsignal(BX), DX // DX = gsignal CMPL AX, m_gsignal(BX)
CMPL AX, DX
JEQ noswitch JEQ noswitch
MOVL m_g0(BX), DX // DX = g0 MOVL m_g0(BX), DX // DX = g0
CMPL AX, DX CMPL AX, DX
JEQ noswitch JEQ noswitch
MOVL m_curg(BX), R8 CMPL AX, m_curg(BX)
CMPL AX, R8 JNE bad
JEQ switch
// Not g0, not curg. Must be gsignal, but that's not allowed.
// Hide call from linker nosplit analysis.
MOVL $runtime·badsystemstack(SB), AX
CALL AX
switch: // switch stacks
// save our state in g->sched. Pretend to // save our state in g->sched. Pretend to
// be systemstack_switch if the G stack is scanned. // be systemstack_switch if the G stack is scanned.
MOVL $runtime·systemstack_switch(SB), SI MOVL $runtime·systemstack_switch(SB), SI
...@@ -312,6 +305,12 @@ noswitch: ...@@ -312,6 +305,12 @@ noswitch:
MOVL 0(DI), DI MOVL 0(DI), DI
JMP DI JMP DI
bad:
// Not g0, not curg. Must be gsignal, but that's not allowed.
// Hide call from linker nosplit analysis.
MOVL $runtime·badsystemstack(SB), AX
CALL AX
/* /*
* support for morestack * support for morestack
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment