]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/arm64: simplify huge frame prologue
authorAustin Clements <austin@google.com>
Fri, 2 Apr 2021 21:20:15 +0000 (17:20 -0400)
committerAustin Clements <austin@google.com>
Mon, 5 Apr 2021 16:22:13 +0000 (16:22 +0000)
CL 307010 for arm64.

Change-Id: I6c6e1bd6065df059e50c3632a9eb669b64fce899
Reviewed-on: https://go-review.googlesource.com/c/go/+/307050
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>
src/cmd/internal/obj/arm64/obj7.go

index bed21dbe53295f5827a197d344be3839bcd1cf02..514991e3408e440415c0baabfdfe358a19e18868 100644 (file)
@@ -107,55 +107,35 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.From.Reg = REG_R1
                p.Reg = REG_R2
        } 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.
-               //      CMP     $StackPreempt, R1
-               //      BEQ     label_of_call_to_morestack
-               //      ADD     $StackGuard, SP, R2
-               //      SUB     R1, R2
-               //      MOV     $(framesize+(StackGuard-StackSmall)), R3
-               //      CMP     R3, R2
-               p = obj.Appendp(p, c.newprog)
-
-               p.As = ACMP
-               p.From.Type = obj.TYPE_CONST
-               p.From.Offset = objabi.StackPreempt
-               p.Reg = REG_R1
-
-               p = obj.Appendp(p, c.newprog)
-               q = p
-               p.As = ABEQ
-               p.To.Type = obj.TYPE_BRANCH
+               // Such a large stack we need to protect against underflow.
+               // The runtime guarantees SP > objabi.StackBig, but
+               // framesize is large enough that SP-framesize may
+               // underflow, causing a direct comparison with the
+               // stack guard to incorrectly succeed. We explicitly
+               // guard against underflow.
+               //
+               //      SUBS    $(framesize-StackSmall), SP, R2
+               //      // On underflow, jump to morestack
+               //      BLO     label_of_call_to_morestack
+               //      CMP     stackguard, R2
 
                p = obj.Appendp(p, c.newprog)
-               p.As = AADD
+               p.As = ASUBS
                p.From.Type = obj.TYPE_CONST
-               p.From.Offset = int64(objabi.StackGuard)
+               p.From.Offset = int64(framesize) - objabi.StackSmall
                p.Reg = REGSP
                p.To.Type = obj.TYPE_REG
                p.To.Reg = REG_R2
 
                p = obj.Appendp(p, c.newprog)
-               p.As = ASUB
-               p.From.Type = obj.TYPE_REG
-               p.From.Reg = REG_R1
-               p.To.Type = obj.TYPE_REG
-               p.To.Reg = REG_R2
-
-               p = obj.Appendp(p, c.newprog)
-               p.As = AMOVD
-               p.From.Type = obj.TYPE_CONST
-               p.From.Offset = int64(framesize) + (int64(objabi.StackGuard) - objabi.StackSmall)
-               p.To.Type = obj.TYPE_REG
-               p.To.Reg = REG_R3
+               q = p
+               p.As = ABLO
+               p.To.Type = obj.TYPE_BRANCH
 
                p = obj.Appendp(p, c.newprog)
                p.As = ACMP
                p.From.Type = obj.TYPE_REG
-               p.From.Reg = REG_R3
+               p.From.Reg = REG_R1
                p.Reg = REG_R2
        }