Skip to content

Commit f8170cc

Browse files
committed
cmd/asm: for arm, rewrite argument shifted right by 0 to left by 0.
Right shift by 0 has bad semantics. Make sure if we try to right shift by 0, do a left shift by 0 instead. CL 549955 handled full instructions with this strange no-op encoding. This CL handles the shift done to instruction register inputs. (The former is implemented using the latter, but not until deep inside the assembler.) Update #64715 Change-Id: Ibfabb4b13e2595551e58b977162fe005aaaa0ad1 Reviewed-on: https://go-review.googlesource.com/c/go/+/550335 Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 3313bbb commit f8170cc

File tree

2 files changed

+32
-0
lines changed
  • src/cmd

2 files changed

+32
-0
lines changed

src/cmd/asm/internal/asm/testdata/arm.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,20 @@ jmp_label_3:
943943
SLL R5, R7 // 1775a0e1
944944
SLL.S R5, R7 // 1775b0e1
945945

946+
// Ops with zero shifts should encode as left shifts
947+
ADD R0<<0, R1, R2 // 002081e0
948+
ADD R0>>0, R1, R2 // 002081e0
949+
ADD R0->0, R1, R2 // 002081e0
950+
ADD R0@>0, R1, R2 // 002081e0
951+
MOVW R0<<0(R1), R2 // 002091e7
952+
MOVW R0>>0(R1), R2 // 002091e7
953+
MOVW R0->0(R1), R2 // 002091e7
954+
MOVW R0@>0(R1), R2 // 002091e7
955+
MOVW R0, R1<<0(R2) // 010082e7
956+
MOVW R0, R1>>0(R2) // 010082e7
957+
MOVW R0, R1->0(R2) // 010082e7
958+
MOVW R0, R1@>0(R2) // 010082e7
959+
946960
// MULA / MULS
947961
MULAWT R1, R2, R3, R4 // c23124e1
948962
MULAWB R1, R2, R3, R4 // 823124e1

src/cmd/internal/obj/arm/asm5.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,24 @@ func (c *ctxt5) oplook(p *obj.Prog) *Optab {
11061106
// TODO: rotate by 0? Not currently supported, but if we ever do then include it here.
11071107
p.As = ASLL
11081108
}
1109+
if p.As != AMOVB && p.As != AMOVBS && p.As != AMOVBU && p.As != AMOVH && p.As != AMOVHS && p.As != AMOVHU && p.As != AXTAB && p.As != AXTABU && p.As != AXTAH && p.As != AXTAHU {
1110+
// Same here, but for shifts encoded in Addrs.
1111+
// Don't do it for the extension ops, which
1112+
// need to keep their RR shifts.
1113+
fixShift := func(a *obj.Addr) {
1114+
if a.Type == obj.TYPE_SHIFT {
1115+
typ := a.Offset & SHIFT_RR
1116+
isConst := a.Offset&(1<<4) == 0
1117+
amount := a.Offset >> 7 & 0x1f
1118+
if isConst && amount == 0 && (typ == SHIFT_LR || typ == SHIFT_AR || typ == SHIFT_RR) {
1119+
a.Offset -= typ
1120+
a.Offset += SHIFT_LL
1121+
}
1122+
}
1123+
}
1124+
fixShift(&p.From)
1125+
fixShift(&p.To)
1126+
}
11091127

11101128
ops := oprange[p.As&obj.AMask]
11111129
c1 := &xcmp[a1]

0 commit comments

Comments
 (0)