Skip to content

Commit 9f0f87c

Browse files
author
eric fang
committed
cmd/internal/obj/arm64: remove the transition from $0 to ZR
Previously we convert $0 to the ZR register for some reasons, which causes two problems: 1. Confusion, the special case of the ZR register needs to be considered when dealing with constants. For encoding, some places we encode ZR, and some places we encode $0, although we have converted $0 to ZR. 2. Unexpected instruction format. All instructions that support ZR register operands can be replaced by $0. This patch removes this conversion. Note that this patch may cause previously unintendedly supported instruction formats to no longer be supported. Change-Id: I3d8d2c06711b7614a38191397da7776417f1861c Reviewed-on: https://go-review.googlesource.com/c/go/+/404316 Reviewed-by: David Chase <drchase@google.com> Run-TryBot: Eric Fang <eric.fang@arm.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 0a52d80 commit 9f0f87c

File tree

7 files changed

+285
-255
lines changed

7 files changed

+285
-255
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
9595
// CLS
9696
CLSW R1, R2
9797
CLS R1, R2
98+
SBC $0, R1 // 21001fda
99+
SBCW $0, R1 // 21001f5a
100+
SBCS $0, R1 // 21001ffa
101+
SBCSW $0, R1 // 21001f7a
102+
ADC $0, R1 // 21001f9a
103+
ADCW $0, R1 // 21001f1a
104+
ADCS $0, R1 // 21001fba
105+
ADCSW $0, R1 // 21001f3a
98106

99107
// fp/simd instructions.
100108
VADDP V1.B16, V2.B16, V3.B16 // 43bc214e
@@ -386,7 +394,7 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
386394
MOVD $0x11110000, R1 // MOVD $286326784, R1 // 2122a2d2
387395
MOVD $0xaaaa0000aaaa1111, R1 // MOVD $-6149102338357718767, R1 // 212282d24155b5f24155f5f2
388396
MOVD $0x1111ffff1111aaaa, R1 // MOVD $1230045644216969898, R1 // a1aa8a922122a2f22122e2f2
389-
MOVD $0, R1 // 010080d2
397+
MOVD $0, R1 // e1031faa
390398
MOVD $-1, R1 // 01008092
391399
MOVD $0x210000, R0 // MOVD $2162688, R0 // 2004a0d2
392400
MOVD $0xffffffffffffaaaa, R1 // MOVD $-21846, R1 // a1aa8a92
@@ -496,6 +504,15 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8
496504
FMOVQ.P 11(R10), F13 // 4db5c03c
497505
FMOVQ.W 11(R20), F15 // 8fbec03c
498506

507+
// storing $0 to memory, $0 will be replaced with ZR.
508+
MOVD $0, (R1) // 3f0000f9
509+
MOVW $0, (R1) // 3f0000b9
510+
MOVWU $0, (R1) // 3f0000b9
511+
MOVH $0, (R1) // 3f000079
512+
MOVHU $0, (R1) // 3f000079
513+
MOVB $0, (R1) // 3f000039
514+
MOVBU $0, (R1) // 3f000039
515+
499516
// small offset fits into instructions
500517
MOVB R1, 1(R2) // 41040039
501518
MOVH R1, 1(R2) // 41100078

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
263263
MOVKW $(3905<<0), R21 // MOVKW $3905, R21 // 35e88172
264264
MOVKW $(3905<<16), R21 // MOVKW $255918080, R21 // 35e8a172
265265
MOVK $(3905<<32), R21 // MOVK $16771847290880, R21 // 35e8c1f2
266-
MOVD $0, R5 // 050080d2
266+
MOVD $0, R5 // e5031faa
267267
MSR $1, SPSel // bf4100d5
268268
MSR $9, DAIFSet // df4903d5
269269
MSR $6, DAIFClr // ff4603d5

src/cmd/internal/obj/arm64/a.out.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ const (
343343
// The more specific class needs to come earlier.
344344
C_NONE = iota
345345
C_REG // R0..R30
346+
C_ZREG // R0..R30, ZR
346347
C_RSP // R0..R30, RSP
347348
C_FREG // F0..F31
348349
C_VREG // V0..V31
@@ -356,7 +357,7 @@ const (
356357
C_ELEM // Vn.<T>[index]
357358
C_LIST // [V1, V2, V3]
358359

359-
C_ZCON // $0 or ZR
360+
C_ZCON // $0
360361
C_ABCON0 // could be C_ADDCON0 or C_BITCON
361362
C_ADDCON0 // 12-bit unsigned, unshifted
362363
C_ABCON // could be C_ADDCON or C_BITCON

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package arm64
88
var cnames7 = []string{
99
"NONE",
1010
"REG",
11+
"ZREG",
1112
"RSP",
1213
"FREG",
1314
"VREG",

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

Lines changed: 238 additions & 237 deletions
Large diffs are not rendered by default.

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,24 @@ var complements = []obj.As{
5151
ACMNW: ACMPW,
5252
}
5353

54-
// noZRreplace is the set of instructions for which $0 in the To operand
55-
// should NOT be replaced with REGZERO.
56-
var noZRreplace = map[obj.As]bool{
57-
APRFM: true,
54+
// zrReplace is the set of instructions for which $0 in the From operand
55+
// should be replaced with REGZERO.
56+
var zrReplace = map[obj.As]bool{
57+
AMOVD: true,
58+
AMOVW: true,
59+
AMOVWU: true,
60+
AMOVH: true,
61+
AMOVHU: true,
62+
AMOVB: true,
63+
AMOVBU: true,
64+
ASBC: true,
65+
ASBCW: true,
66+
ASBCS: true,
67+
ASBCSW: true,
68+
AADC: true,
69+
AADCW: true,
70+
AADCS: true,
71+
AADCSW: true,
5872
}
5973

6074
func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
@@ -301,18 +315,13 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) {
301315
p.From.Class = 0
302316
p.To.Class = 0
303317

304-
// $0 results in C_ZCON, which matches both C_REG and various
305-
// C_xCON, however the C_REG cases in asmout don't expect a
306-
// constant, so they will use the register fields and assemble
307-
// a R0. To prevent that, rewrite $0 as ZR.
308-
if p.From.Type == obj.TYPE_CONST && p.From.Offset == 0 {
318+
// Previously we rewrote $0 to ZR, but we have now removed this change.
319+
// In order to be compatible with some previous legal instruction formats,
320+
// reserve the previous conversion for some specific instructions.
321+
if p.From.Type == obj.TYPE_CONST && p.From.Offset == 0 && zrReplace[p.As] {
309322
p.From.Type = obj.TYPE_REG
310323
p.From.Reg = REGZERO
311324
}
312-
if p.To.Type == obj.TYPE_CONST && p.To.Offset == 0 && !noZRreplace[p.As] {
313-
p.To.Type = obj.TYPE_REG
314-
p.To.Reg = REGZERO
315-
}
316325

317326
// Rewrite BR/BL to symbol as TYPE_BRANCH.
318327
switch p.As {

test/codegen/bitfield.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ func sbfx1(x int64) int64 {
122122
}
123123

124124
func sbfx2(x int64) int64 {
125-
return (x << 60) >> 60 // arm64:"SBFX\tZR, R[0-9]+, [$]4",-"LSL",-"ASR"
125+
return (x << 60) >> 60 // arm64:"SBFX\t[$]0, R[0-9]+, [$]4",-"LSL",-"ASR"
126126
}
127127

128-
// merge shift and sign-extension into sbfx.
128+
// merge shift and sign-extension into sbfx.
129129
func sbfx3(x int32) int64 {
130130
return int64(x) >> 3 // arm64:"SBFX\t[$]3, R[0-9]+, [$]29",-"ASR"
131131
}
@@ -328,6 +328,7 @@ func ubfx16(x uint64) uint64 {
328328
}
329329

330330
// Check that we don't emit comparisons for constant shifts.
331+
//
331332
//go:nosplit
332333
func shift_no_cmp(x int) int {
333334
// arm64:`LSL\t[$]17`,-`CMP`

0 commit comments

Comments
 (0)