Skip to content

Commit 1f5f489

Browse files
authored
Fix mips64 instruction UNPREDICTABLE bug
Replace `addu` with a `sll` instruction with a definite behavior (`sll` will discard the upper 32 bits of the 64 bits, then do sign extensions, with certain behavior). It won't have any UNPREDICTABLE expectation.
1 parent 93f882c commit 1f5f489

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/cmd/internal/obj/mips/asm0.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,11 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
11201120
case 1: /* mov r1,r2 ==> OR r1,r0,r2 */
11211121
a := AOR
11221122
if p.As == AMOVW && c.ctxt.Arch.Family == sys.MIPS64 {
1123-
a = AADDU // sign-extended to high 32 bits
1124-
}
1125-
o1 = OP_RRR(c.oprrr(a), uint32(REGZERO), uint32(p.From.Reg), uint32(p.To.Reg))
1123+
a = ASLL // sign-extended to high 32 bits
1124+
o1 = OP_RRR(c.oprrr(a), uint32(p.From.Reg), uint32(REGZERO), uint32(p.To.Reg))
1125+
} else {
1126+
o1 = OP_RRR(c.oprrr(a), uint32(REGZERO), uint32(p.From.Reg), uint32(p.To.Reg))
1127+
}
11261128

11271129
case 2: /* add/sub r1,[r2],r3 */
11281130
r := int(p.Reg)

0 commit comments

Comments
 (0)