mirror of
https://github.com/golang/go
synced 2024-11-26 09:18:07 -07:00
cmd/internal/obj/s390x: simplify huge frame prologue
CL 307010 for s390x. Change-Id: I43e1f93dd01c814417f8ef7480aa82c05b2b6b66 Reviewed-on: https://go-review.googlesource.com/c/go/+/307151 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
042f4cbb6f
commit
191167c2b2
@ -568,7 +568,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ctxtz) stacksplitPre(p *obj.Prog, framesize int32) (*obj.Prog, *obj.Prog) {
|
func (c *ctxtz) stacksplitPre(p *obj.Prog, framesize int32) (*obj.Prog, *obj.Prog) {
|
||||||
var q *obj.Prog
|
|
||||||
|
|
||||||
// MOVD g_stackguard(g), R3
|
// MOVD g_stackguard(g), R3
|
||||||
p = obj.Appendp(p, c.newprog)
|
p = obj.Appendp(p, c.newprog)
|
||||||
@ -589,97 +588,68 @@ func (c *ctxtz) stacksplitPre(p *obj.Prog, framesize int32) (*obj.Prog, *obj.Pro
|
|||||||
// unnecessarily. See issue #35470.
|
// unnecessarily. See issue #35470.
|
||||||
p = c.ctxt.StartUnsafePoint(p, c.newprog)
|
p = c.ctxt.StartUnsafePoint(p, c.newprog)
|
||||||
|
|
||||||
q = nil
|
|
||||||
if framesize <= objabi.StackSmall {
|
if framesize <= objabi.StackSmall {
|
||||||
// small stack: SP < stackguard
|
// small stack: SP < stackguard
|
||||||
// CMPUBGE stackguard, SP, label-of-call-to-morestack
|
// CMPUBGE stackguard, SP, label-of-call-to-morestack
|
||||||
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
p = obj.Appendp(p, c.newprog)
|
||||||
//q1 = p
|
|
||||||
p.From.Type = obj.TYPE_REG
|
p.From.Type = obj.TYPE_REG
|
||||||
p.From.Reg = REG_R3
|
p.From.Reg = REG_R3
|
||||||
p.Reg = REGSP
|
p.Reg = REGSP
|
||||||
p.As = ACMPUBGE
|
p.As = ACMPUBGE
|
||||||
p.To.Type = obj.TYPE_BRANCH
|
p.To.Type = obj.TYPE_BRANCH
|
||||||
|
|
||||||
} else if framesize <= objabi.StackBig {
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
// large stack: SP-framesize < stackguard-StackSmall
|
// large stack: SP-framesize < stackguard-StackSmall
|
||||||
// ADD $-(framesize-StackSmall), SP, R4
|
|
||||||
// CMPUBGE stackguard, R4, label-of-call-to-morestack
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
|
||||||
|
|
||||||
p.As = AADD
|
var q *obj.Prog
|
||||||
p.From.Type = obj.TYPE_CONST
|
offset := int64(framesize) - objabi.StackSmall
|
||||||
p.From.Offset = -(int64(framesize) - objabi.StackSmall)
|
if framesize > objabi.StackBig {
|
||||||
p.Reg = REGSP
|
// Such a large stack we need to protect against underflow.
|
||||||
p.To.Type = obj.TYPE_REG
|
// The runtime guarantees SP > objabi.StackBig, but
|
||||||
p.To.Reg = REG_R4
|
// framesize is large enough that SP-framesize may
|
||||||
|
// underflow, causing a direct comparison with the
|
||||||
p = obj.Appendp(p, c.newprog)
|
// stack guard to incorrectly succeed. We explicitly
|
||||||
p.From.Type = obj.TYPE_REG
|
// guard against underflow.
|
||||||
p.From.Reg = REG_R3
|
|
||||||
p.Reg = REG_R4
|
|
||||||
p.As = ACMPUBGE
|
|
||||||
p.To.Type = obj.TYPE_BRANCH
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Such a large stack we need to protect against wraparound.
|
|
||||||
// If SP is close to zero:
|
|
||||||
// SP-stackguard+StackGuard <= framesize + (StackGuard-StackSmall)
|
|
||||||
// The +StackGuard on both sides is required to keep the left side positive:
|
|
||||||
// SP is allowed to be slightly below stackguard. See stack.h.
|
|
||||||
//
|
//
|
||||||
// Preemption sets stackguard to StackPreempt, a very large value.
|
// MOVD $(framesize-StackSmall), R4
|
||||||
// That breaks the math above, so we have to check for that explicitly.
|
// CMPUBLT SP, R4, label-of-call-to-morestack
|
||||||
// // stackguard is R3
|
|
||||||
// CMP R3, $StackPreempt
|
|
||||||
// BEQ label-of-call-to-morestack
|
|
||||||
// ADD $StackGuard, SP, R4
|
|
||||||
// SUB R3, R4
|
|
||||||
// MOVD $(framesize+(StackGuard-StackSmall)), TEMP
|
|
||||||
// CMPUBGE TEMP, R4, label-of-call-to-morestack
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
|
||||||
|
|
||||||
p.As = ACMP
|
|
||||||
p.From.Type = obj.TYPE_REG
|
|
||||||
p.From.Reg = REG_R3
|
|
||||||
p.To.Type = obj.TYPE_CONST
|
|
||||||
p.To.Offset = objabi.StackPreempt
|
|
||||||
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
|
||||||
q = p
|
|
||||||
p.As = ABEQ
|
|
||||||
p.To.Type = obj.TYPE_BRANCH
|
|
||||||
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
|
||||||
p.As = AADD
|
|
||||||
p.From.Type = obj.TYPE_CONST
|
|
||||||
p.From.Offset = int64(objabi.StackGuard)
|
|
||||||
p.Reg = REGSP
|
|
||||||
p.To.Type = obj.TYPE_REG
|
|
||||||
p.To.Reg = REG_R4
|
|
||||||
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
|
||||||
p.As = ASUB
|
|
||||||
p.From.Type = obj.TYPE_REG
|
|
||||||
p.From.Reg = REG_R3
|
|
||||||
p.To.Type = obj.TYPE_REG
|
|
||||||
p.To.Reg = REG_R4
|
|
||||||
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
p = obj.Appendp(p, c.newprog)
|
||||||
p.As = AMOVD
|
p.As = AMOVD
|
||||||
p.From.Type = obj.TYPE_CONST
|
p.From.Type = obj.TYPE_CONST
|
||||||
p.From.Offset = int64(framesize) + int64(objabi.StackGuard) - objabi.StackSmall
|
p.From.Offset = offset
|
||||||
p.To.Type = obj.TYPE_REG
|
p.To.Type = obj.TYPE_REG
|
||||||
p.To.Reg = REGTMP
|
p.To.Reg = REG_R4
|
||||||
|
|
||||||
|
p = obj.Appendp(p, c.newprog)
|
||||||
|
q = p
|
||||||
|
p.As = ACMPUBLT
|
||||||
|
p.From.Type = obj.TYPE_REG
|
||||||
|
p.From.Reg = REGSP
|
||||||
|
p.Reg = REG_R4
|
||||||
|
p.To.Type = obj.TYPE_BRANCH
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check against the stack guard. We've ensured this won't underflow.
|
||||||
|
// ADD $-(framesize-StackSmall), SP, R4
|
||||||
|
// CMPUBGE stackguard, R4, label-of-call-to-morestack
|
||||||
|
p = obj.Appendp(p, c.newprog)
|
||||||
|
p.As = AADD
|
||||||
|
p.From.Type = obj.TYPE_CONST
|
||||||
|
p.From.Offset = -offset
|
||||||
|
p.Reg = REGSP
|
||||||
|
p.To.Type = obj.TYPE_REG
|
||||||
|
p.To.Reg = REG_R4
|
||||||
|
|
||||||
p = obj.Appendp(p, c.newprog)
|
p = obj.Appendp(p, c.newprog)
|
||||||
p.From.Type = obj.TYPE_REG
|
p.From.Type = obj.TYPE_REG
|
||||||
p.From.Reg = REGTMP
|
p.From.Reg = REG_R3
|
||||||
p.Reg = REG_R4
|
p.Reg = REG_R4
|
||||||
p.As = ACMPUBGE
|
p.As = ACMPUBGE
|
||||||
p.To.Type = obj.TYPE_BRANCH
|
p.To.Type = obj.TYPE_BRANCH
|
||||||
}
|
|
||||||
|
|
||||||
return p, q
|
return p, q
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user