Skip to content

Commit 441cb98

Browse files
committed
cmd/internal/obj/arm64: fix encoding of 32-bit negated logical instructions
32-bit negated logical instructions (BICW, ORNW, EONW) with constants were mis-encoded, because they were missing in the cases where we handle 32-bit logical instructions. This CL adds the missing cases. Fixes golang#28548 Change-Id: I3d6acde7d3b72bb7d3d5d00a9df698a72c806ad5 Reviewed-on: https://go-review.googlesource.com/c/147077 Run-TryBot: Cherry Zhang <[email protected]> Run-TryBot: Ben Shi <[email protected]> Reviewed-by: Ben Shi <[email protected]>
1 parent 1645dfa commit 441cb98

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
222222
EOR $(1<<63), R1 // EOR $-9223372036854775808, R1 // 210041d2
223223
EOR $(1<<63-1), R1 // EOR $9223372036854775807, R1 // 21f840d2
224224

225+
ANDW $0x3ff00000, R2 // ANDW $1072693248, R2 // 42240c12
226+
BICW $0x3ff00000, R2 // BICW $1072693248, R2 // 42540212
227+
ORRW $0x3ff00000, R2 // ORRW $1072693248, R2 // 42240c32
228+
ORNW $0x3ff00000, R2 // ORNW $1072693248, R2 // 42540232
229+
EORW $0x3ff00000, R2 // EORW $1072693248, R2 // 42240c52
230+
EONW $0x3ff00000, R2 // EONW $1072693248, R2 // 42540252
231+
225232
AND $0x22220000, R3, R4 // AND $572653568, R3, R4 // 5b44a4d264001b8a
226233
ORR $0x22220000, R3, R4 // ORR $572653568, R3, R4 // 5b44a4d264001baa
227234
EOR $0x22220000, R3, R4 // EOR $572653568, R3, R4 // 5b44a4d264001bca

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,21 +1689,14 @@ func (c *ctxt7) oplook(p *obj.Prog) *Optab {
16891689
a1 = ra0 + 1
16901690
p.From.Class = int8(a1)
16911691
}
1692-
if isANDWop(p.As) {
1693-
switch p.As {
1694-
case AANDW, AORRW, AEORW, AANDSW, ATSTW:
1695-
// For 32-bit logical instruction with constant,
1696-
// rewrite the high 32-bit to be a copy of the low
1697-
// 32-bit, so that the BITCON test can be shared
1698-
// for both 32-bit and 64-bit.
1699-
if a0 == C_BITCON {
1700-
break
1701-
}
1702-
fallthrough
1703-
default:
1704-
a1 = c.con32class(&p.From) + 1
1705-
p.From.Class = int8(a1)
1706-
}
1692+
if isANDWop(p.As) && a0 != C_BITCON {
1693+
// For 32-bit logical instruction with constant,
1694+
// the BITCON test is special in that it looks at
1695+
// the 64-bit which has the high 32-bit as a copy
1696+
// of the low 32-bit. We have handled that and
1697+
// don't pass it to con32class.
1698+
a1 = c.con32class(&p.From) + 1
1699+
p.From.Class = int8(a1)
17071700
}
17081701
}
17091702
}

src/cmd/internal/obj/arm64/obj7.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,9 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
311311
// shared for both 32-bit and 64-bit. 32-bit ops
312312
// will zero the high 32-bit of the destination
313313
// register anyway.
314-
switch p.As {
315-
case AANDW, AORRW, AEORW, AANDSW, ATSTW:
316-
if p.From.Type == obj.TYPE_CONST {
317-
v := p.From.Offset & 0xffffffff
318-
p.From.Offset = v | v<<32
319-
}
314+
if isANDWop(p.As) && p.From.Type == obj.TYPE_CONST {
315+
v := p.From.Offset & 0xffffffff
316+
p.From.Offset = v | v<<32
320317
}
321318

322319
if c.ctxt.Flag_dynlink {

0 commit comments

Comments
 (0)