Skip to content

Commit 3b795dc

Browse files
committed
cmd/internal/obj/loong64: clean up code for short conditional branches
Untangle the logic so the preparation of operands and actual assembling (branch range checking included) are properly separated, making future changes easier to review and maintain. No functional change intended. Change-Id: I1f73282f9d92ff23d84846453d3597ba66d207d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/478376 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: abner chenc <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> (cherry picked from commit 1ae306a)
1 parent 2a30538 commit 3b795dc

File tree

1 file changed

+15
-15
lines changed
  • src/cmd/internal/obj/loong64

1 file changed

+15
-15
lines changed

src/cmd/internal/obj/loong64/asm.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,26 +1179,26 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
11791179

11801180
case 6: // beq r1,[r2],sbra
11811181
v := int32(0)
1182-
vcmp := int32(0)
11831182
if p.To.Target() != nil {
11841183
v = int32(p.To.Target().Pc-p.Pc) >> 2
11851184
}
1186-
if v < 0 {
1187-
vcmp = -v
1188-
}
1189-
if (p.As == ABFPT || p.As == ABFPF) && ((uint32(vcmp))>>21)&0x7FF != 0 {
1190-
c.ctxt.Diag("21 bit-width, short branch too far\n%v", p)
1191-
} else if p.As != ABFPT && p.As != ABFPF && (v<<16)>>16 != v {
1192-
c.ctxt.Diag("16 bit-width, short branch too far\n%v", p)
1193-
}
1185+
rd, rj := p.Reg, p.From.Reg
11941186
if p.As == ABGTZ || p.As == ABLEZ {
1195-
o1 = OP_16IRR(c.opirr(p.As), uint32(v), uint32(p.Reg), uint32(p.From.Reg))
1196-
} else if p.As == ABFPT || p.As == ABFPF {
1197-
// BCNEZ cj offset21 ,cj = fcc0
1198-
// BCEQZ cj offset21 ,cj = fcc0
1187+
rd, rj = rj, rd
1188+
}
1189+
switch p.As {
1190+
case ABFPT, ABFPF:
1191+
if (v<<11)>>11 != v {
1192+
c.ctxt.Diag("21 bit-width, short branch too far\n%v", p)
1193+
}
1194+
// FCC0 is the implicit source operand, now that we
1195+
// don't register-allocate from the FCC bank.
11991196
o1 = OP_16IR_5I(c.opirr(p.As), uint32(v), uint32(REG_FCC0))
1200-
} else {
1201-
o1 = OP_16IRR(c.opirr(p.As), uint32(v), uint32(p.From.Reg), uint32(p.Reg))
1197+
default:
1198+
if (v<<16)>>16 != v {
1199+
c.ctxt.Diag("16 bit-width, short branch too far\n%v", p)
1200+
}
1201+
o1 = OP_16IRR(c.opirr(p.As), uint32(v), uint32(rj), uint32(rd))
12021202
}
12031203

12041204
case 7: // mov r, soreg

0 commit comments

Comments
 (0)