src/cmd/internal/obj/arm64/asm7.go | 11 +++++++++-- src/cmd/internal/obj/arm64/asm_test.go | 1 + diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index ca81238c93e93fe81f154bfb1011253a5184d771..b1ee5524897550bcc76a2408d0efc735b58fd24b 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -696,9 +696,16 @@ p.Pc = pc o = c.oplook(p) /* very large branches */ - if (o.type_ == 7 || o.type_ == 39) && p.Pcond != nil { // 7: BEQ and like, 39: CBZ and like + if (o.type_ == 7 || o.type_ == 39 || o.type_ == 40) && p.Pcond != nil { // 7: BEQ and like, 39: CBZ and like, 40: TBZ and like otxt := p.Pcond.Pc - pc - if otxt <= -(1<<18)+10 || otxt >= (1<<18)-10 { + var toofar bool + switch o.type_ { + case 7, 39: // branch instruction encodes 19 bits + toofar = otxt <= -(1<<20)+10 || otxt >= (1<<20)-10 + case 40: // branch instruction encodes 14 bits + toofar = otxt <= -(1<<15)+10 || otxt >= (1<<15)-10 + } + if toofar { q := c.newprog() q.Link = p.Link p.Link = q diff --git a/src/cmd/internal/obj/arm64/asm_test.go b/src/cmd/internal/obj/arm64/asm_test.go index 369c48f510b42912f538a1e8e7e2233f4331cd3c..3e0c9c13a6957e73f7e9b64af9bbb7abd47468a4 100644 --- a/src/cmd/internal/obj/arm64/asm_test.go +++ b/src/cmd/internal/obj/arm64/asm_test.go @@ -52,6 +52,7 @@ // gen generates a very large program, with a very far conditional branch. func gen(buf *bytes.Buffer) { fmt.Fprintln(buf, "TEXT f(SB),0,$0-0") + fmt.Fprintln(buf, "TBZ $5, R0, label") fmt.Fprintln(buf, "CBZ R0, label") fmt.Fprintln(buf, "BEQ label") for i := 0; i < 1<<19; i++ {