Skip to content

Commit 8c3c833

Browse files
erifan01cherrymui
erifan01
authored andcommitted
cmd/asm: enable several arm64 load & store instructions
Instructions LDARB, LDARH, LDAXPW, LDAXP, STLRB, STLRH, STLXP, STLXPW, STXP, STXPW have been added before, but they are not enabled. This CL enabled them. Change the form of LDXP and LDXPW to the form of LDP, and fix a bug of STLXP. Change-Id: I5d2b51494b92451bf6b072c65cfdd8acf07e9b54 Reviewed-on: https://go-review.googlesource.com/96215 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 1057624 commit 8c3c833

File tree

5 files changed

+106
-29
lines changed

5 files changed

+106
-29
lines changed

src/cmd/asm/internal/arch/arm64.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ func IsARM64CMP(op obj.As) bool {
7171
func IsARM64STLXR(op obj.As) bool {
7272
switch op {
7373
case arm64.ASTLXRB, arm64.ASTLXRH, arm64.ASTLXRW, arm64.ASTLXR,
74-
arm64.ASTXRB, arm64.ASTXRH, arm64.ASTXRW, arm64.ASTXR:
74+
arm64.ASTXRB, arm64.ASTXRH, arm64.ASTXRW, arm64.ASTXR,
75+
arm64.ASTXP, arm64.ASTXPW, arm64.ASTLXP, arm64.ASTLXPW:
7576
return true
7677
}
7778
return false

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,22 @@ again:
401401
// {
402402
// outcode($1, &$2, &$4, &$6);
403403
// }
404-
LDAXRW (R0), R2
405-
STLXRW R1, (R0), R3
404+
LDARB (R25), R2 // 22ffdf08
405+
LDARH (R5), R7 // a7fcdf48
406+
LDAXPW (R10), (R20, R16) // 54c17f88
407+
LDAXP (R25), (R30, R11) // 3eaf7fc8
408+
LDAXRW (R0), R2 // 02fc5f88
409+
LDXPW (R24), (R23, R11) // 172f7f88
410+
LDXP (R0), (R16, R13) // 10347fc8
411+
STLRB R11, (R22) // cbfe9f08
412+
STLRH R16, (R23) // f0fe9f48
413+
STLXP (R6, R3), (R10), R2 // 468d22c8
414+
STLXPW (R6, R11), (R22), R21 // c6ae3588
415+
STLXRW R1, (R0), R3 // 01fc0388
416+
STXP (R1, R2), (R3), R10 // 61082ac8
417+
STXP (R1, R2), (RSP), R10 // e10b2ac8
418+
STXPW (R1, R2), (R3), R10 // 61082a88
419+
STXPW (R1, R2), (RSP), R10 // e10b2a88
406420

407421
// RET
408422
//

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
153153
LDARW (R30), R22 // d6ffdf88
154154
LDARW (RSP), R22 // f6ffdf88
155155
LDAR (R27), R22 // 76ffdfc8
156-
//TODO LDARB (R25), R2 // 22ffdf08
157-
//TODO LDARH (R5), R7 // a7fcdf48
158-
//TODO LDAXPW (R10), R16, R20 // 54c17f88
159-
//TODO LDAXP (R25), R11, R30 // 3eaf7fc8
156+
LDARB (R25), R2 // 22ffdf08
157+
LDARH (R5), R7 // a7fcdf48
158+
//TODO LDAXPW (R10), (R20, R16) // 54c17f88
159+
//TODO LDAXP (R25), (R30, R11) // 3eaf7fc8
160160
LDAXRW (R15), R2 // e2fd5f88
161161
LDAXR (R15), R21 // f5fd5fc8
162162
LDAXRB (R19), R16 // 70fe5f08
@@ -216,8 +216,8 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
216216
//TODO LDURSH -0x49(R11), R28 // 7c71db78
217217
//TODO LDURSH -0x1f(R0), R29 // 1d109e78
218218
//TODO LDURSW 0x48(R6), R20 // d48084b8
219-
LDXPW (R24), R11, R23 // 172f7f88
220-
LDXP (R0), R13, R16 // 10347fc8
219+
//TODO LDXPW (R24), (R23, R11) // 172f7f88
220+
//TODO LDXP (R0), (R16, R13) // 10347fc8
221221
LDXRW (RSP), R30 // fe7f5f88
222222
LDXR (R27), R12 // 6c7f5fc8
223223
LDXRB (R0), R4 // 047c5f08
@@ -313,8 +313,8 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
313313
STLXRW R13, (R15), R14 // edfd0e88
314314
STLXRB R24, (R23), R8 // f8fe0808
315315
STLXRH R19, (R27), R11 // 73ff0b48
316-
//TODO STLXPW (R22), R11, R6, R21 // c6ae3588
317-
//TODO STLXP (R22), LR, R6, R2 // c6fa22c8
316+
//TODO STLXP (R6, R3), (R10), R2 // 468d22c8
317+
//TODO STLXPW (R6, R11), (R22), R21 // c6ae3588
318318
//TODO STNPW 44(R1), R3, R10 // 2a8c0528
319319
//TODO STNP 0x108(R3), ZR, R7 // 67fc10a8
320320
LDP.P -384(R3), (R22, R26) // 7668e8a8
@@ -343,8 +343,10 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8
343343
//TODO STTR 124(R5), R25 // b9c807f8
344344
//TODO STTRB -28(R23), R16 // f04a1e38
345345
//TODO STTRH 9(R10), R18 // 52990078
346-
//TODO STXP (R20), R18, R5, ZR // 854a3f88
347-
//TODO STXP (R22), R9, R17, R0 // d12620c8
346+
//TODO STXP (R1, R2), (R3), R10 // 61082ac8
347+
//TODO STXP (R1, R2), (RSP), R10 // e10b2ac8
348+
//TODO STXPW (R1, R2), (R3), R10 // 61082a88
349+
//TODO STXPW (R1, R2), (RSP), R10 // e10b2a88
348350
STXRW R2, (R19), R18 // 627e1288
349351
STXR R15, (R21), R13 // af7e0dc8
350352
STXRB R7, (R9), R24 // 277d1808

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,11 @@ var optab = []Optab{
571571
{ALDAR, C_ZOREG, C_NONE, C_REG, 58, 4, 0, 0, 0},
572572
{ALDXR, C_ZOREG, C_NONE, C_REG, 58, 4, 0, 0, 0},
573573
{ALDAXR, C_ZOREG, C_NONE, C_REG, 58, 4, 0, 0, 0},
574-
{ALDXP, C_ZOREG, C_REG, C_REG, 58, 4, 0, 0, 0},
574+
{ALDXP, C_ZOREG, C_NONE, C_PAIR, 58, 4, 0, 0, 0},
575575
{ASTLR, C_REG, C_NONE, C_ZOREG, 59, 4, 0, 0, 0}, // to3=C_NONE
576576
{ASTXR, C_REG, C_NONE, C_ZOREG, 59, 4, 0, 0, 0}, // to3=C_REG
577577
{ASTLXR, C_REG, C_NONE, C_ZOREG, 59, 4, 0, 0, 0}, // to3=C_REG
578-
579-
// { ASTXP, C_REG, C_NONE, C_ZOREG, 59, 4, 0 , 0}, // TODO(aram):
580-
578+
{ASTXP, C_PAIR, C_NONE, C_ZOREG, 59, 4, 0, 0, 0},
581579
{AAESD, C_VREG, C_NONE, C_VREG, 29, 4, 0, 0, 0}, // for compatibility with old code
582580
{AAESD, C_ARNG, C_NONE, C_ARNG, 29, 4, 0, 0, 0}, // recommend using the new one for better readability
583581
{ASHA1C, C_VREG, C_REG, C_VREG, 1, 4, 0, 0, 0},
@@ -2082,6 +2080,8 @@ func buildop(ctxt *obj.Link) {
20822080

20832081
case ALDAR:
20842082
oprangeset(ALDARW, t)
2083+
oprangeset(ALDARB, t)
2084+
oprangeset(ALDARH, t)
20852085
fallthrough
20862086

20872087
case ALDXR:
@@ -2096,8 +2096,12 @@ func buildop(ctxt *obj.Link) {
20962096

20972097
case ALDXP:
20982098
oprangeset(ALDXPW, t)
2099+
oprangeset(ALDAXP, t)
2100+
oprangeset(ALDAXPW, t)
20992101

21002102
case ASTLR:
2103+
oprangeset(ASTLRB, t)
2104+
oprangeset(ASTLRH, t)
21012105
oprangeset(ASTLRW, t)
21022106

21032107
case ASTXR:
@@ -2111,6 +2115,8 @@ func buildop(ctxt *obj.Link) {
21112115
oprangeset(ASTLXRW, t)
21122116

21132117
case ASTXP:
2118+
oprangeset(ASTLXP, t)
2119+
oprangeset(ASTLXPW, t)
21142120
oprangeset(ASTXPW, t)
21152121

21162122
case AVADDP:
@@ -3131,31 +3137,30 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) {
31313137
rt := int(p.GetFrom3().Reg)
31323138
o1 |= uint32(rf&31)<<16 | uint32(cond&15)<<12 | uint32(rt&31)<<5 | uint32(nzcv)
31333139

3134-
case 58: /* ldar/ldxr/ldaxr */
3140+
case 58: /* ldar/ldarb/ldarh/ldaxp/ldxp/ldaxr/ldxr */
31353141
o1 = c.opload(p, p.As)
31363142

31373143
o1 |= 0x1F << 16
31383144
o1 |= uint32(p.From.Reg&31) << 5
3139-
if p.Reg != 0 {
3140-
o1 |= uint32(p.Reg&31) << 10
3145+
if p.As == ALDXP || p.As == ALDXPW || p.As == ALDAXP || p.As == ALDAXPW {
3146+
o1 |= uint32(p.To.Offset&31) << 10
31413147
} else {
31423148
o1 |= 0x1F << 10
31433149
}
31443150
o1 |= uint32(p.To.Reg & 31)
31453151

3146-
case 59: /* stxr/stlxr */
3152+
case 59: /* stxr/stlxr/stxp/stlxp */
31473153
o1 = c.opstore(p, p.As)
31483154

31493155
if p.RegTo2 != obj.REG_NONE {
31503156
o1 |= uint32(p.RegTo2&31) << 16
31513157
} else {
31523158
o1 |= 0x1F << 16
31533159
}
3154-
3155-
// TODO(aram): add support for STXP
3156-
o1 |= uint32(p.To.Reg&31) << 5
3157-
3158-
o1 |= uint32(p.From.Reg & 31)
3160+
if p.As == ASTXP || p.As == ASTXPW || p.As == ASTLXP || p.As == ASTLXPW {
3161+
o1 |= uint32(p.From.Offset&31) << 10
3162+
}
3163+
o1 |= uint32(p.To.Reg&31) << 5 | uint32(p.From.Reg & 31)
31593164

31603165
case 60: /* adrp label,r */
31613166
d := c.brdist(p, 12, 21, 0)
@@ -5002,10 +5007,10 @@ func (c *ctxt7) opstore(p *obj.Prog, a obj.As) uint32 {
50025007
return LDSTX(2, 1, 0, 0, 1) | 0x1F<<10
50035008

50045009
case ASTLXP:
5005-
return LDSTX(2, 0, 0, 1, 1)
5010+
return LDSTX(3, 0, 0, 1, 1)
50065011

50075012
case ASTLXPW:
5008-
return LDSTX(3, 0, 0, 1, 1)
5013+
return LDSTX(2, 0, 0, 1, 1)
50095014

50105015
case ASTLXR:
50115016
return LDSTX(3, 0, 0, 0, 1) | 0x1F<<10

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,61 @@ Go Assembly for ARM64 Reference Manual
1919
PRFM imm(Rn), $imm
2020
$imm prefetch operation is encoded as an immediate.
2121
22+
LDARB: Load-Acquire Register Byte
23+
LDARB (<Rn>), <Rd>
24+
Loads a byte from memory, zero-extends it and writes it to Rd.
25+
26+
LDARH: Load-Acquire Register Halfword
27+
LDARH (<Rn>), <Rd>
28+
Loads a halfword from memory, zero-extends it and writes it to Rd.
29+
30+
LDAXP: Load-Acquire Exclusive Pair of Registers
31+
LDAXP (<Rn>), (<Rt1>, <Rt2>)
32+
Loads two 64-bit doublewords from memory, and writes them to Rt1 and Rt2.
33+
34+
LDAXPW: Load-Acquire Exclusive Pair of Registers
35+
LDAXPW (<Rn>), (<Rt1>, <Rt2>)
36+
Loads two 32-bit words from memory, and writes them to Rt1 and Rt2.
37+
38+
LDXP: 64-bit Load Exclusive Pair of Registers
39+
LDXP (<Rn>), (<Rt1>, <Rt2>)
40+
Loads two 64-bit doublewords from memory, and writes them to Rt1 and Rt2.
41+
42+
LDXPW: 32-bit Load Exclusive Pair of Registers
43+
LDXPW (<Rn>), (<Rt1>, <Rt2>)
44+
Loads two 32-bit words from memory, and writes them to Rt1 and Rt2.
45+
46+
STLRB: Store-Release Register Byte
47+
STLRB <Rd>, (<Rn>)
48+
Stores a byte from Rd to a memory location from Rn.
49+
50+
STLRH: Store-Release Register Halfword
51+
STLRH <Rd>, (<Rn>)
52+
Stores a halfword from Rd to a memory location from Rn.
53+
54+
STLXP: 64-bit Store-Release Exclusive Pair of registers
55+
STLXP (<Rt1>, <Rt2>), (<Rn>), <Rs>
56+
Stores two 64-bit doublewords from Rt1 and Rt2 to a memory location from Rn,
57+
and returns in Rs a status value of 0 if the store was successful, or of 1 if
58+
no store was performed.
59+
60+
STLXPW: 32-bit Store-Release Exclusive Pair of registers
61+
STLXPW (<Rt1>, <Rt2>), (<Rn>), <Rs>
62+
Stores two 32-bit words from Rt1 and Rt2 to a memory location from Rn, and
63+
returns in Rs a status value of 0 if the store was successful, or of 1 if no
64+
store was performed.
65+
66+
STXP: 64-bit Store Exclusive Pair of registers
67+
STXP (<Rt1>, <Rt2>), (<Rn>), <Rs>
68+
Stores two 64-bit doublewords from Rt1 and Rt2 to a memory location from Rn,
69+
and returns in Rs a status value of 0 if the store was successful, or of 1 if
70+
no store was performed.
71+
72+
STXPW: 32-bit Store Exclusive Pair of registers
73+
STXPW (<Rt1>, <Rt2>), (<Rn>), <Rs>
74+
Stores two 32-bit words from Rt1 and Rt2 to a memory location from Rn, and returns in
75+
a Rs a status value of 0 if the store was successful, or of 1 if no store was performed.
76+
2277
2. Alphabetical list of float-point instructions
2378
// TODO
2479
@@ -71,7 +126,7 @@ Go Assembly for ARM64 Reference Manual
71126
VADD: Add (vector).
72127
VADD <Vm>.T, <Vn>.<T>, <Vd>.<T>
73128
<T> Is an arrangement specifier and can have the following values:
74-
8B, 16B, H4, H8, S2, S4, D2
129+
B8, B16, H4, H8, S2, S4, D2
75130
76131
VADDP: Add Pairwise (vector)
77132
VADDP <Vm>.<T>, <Vn>.<T>, <Vd>.<T>

0 commit comments

Comments
 (0)