Skip to content

Commit 882335e

Browse files
sophie-zhaoabner-chenc
authored andcommitted
cmd/internal/obj/loong64: add LDPTR.{W/D} and STPTR.{W/D} instructions support
Go asm syntax: MOVWP 4(R4), R5 MOVVP 8(R4), R5 MOVWP R4, 12(R5) MOVVP R4, 16(R5) Equivalent platform assembler syntax: ldptr.w r5, r4, $1 ldptr.d r5, r4, $2 stptr.w r4, r5, $3 stptr.d r4, r5, $4 Change-Id: I50a341cee2d875cb7c5da9db08b23799c9dc6c64 Reviewed-on: https://go-review.googlesource.com/c/go/+/699055 Reviewed-by: abner chenc <[email protected]> Reviewed-by: Meidan Li <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent d4b17f5 commit 882335e

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,28 @@ lable2:
260260
MOVV FCC0, R4 // 04dc1401
261261
MOVV R4, FCC0 // 80d81401
262262

263+
// LDPTR.{W/D} and STPTR.{W/D} instructions
264+
MOVWP R5, -32768(R4) // 85008025
265+
MOVWP R5, 32764(R4) // 85fc7f25
266+
MOVWP R5, 32(R4) // 85200025
267+
MOVWP R5, 4(R4) // 85040025
268+
MOVWP R5, (R4) // 85000025
269+
MOVVP R5, -32768(R4) // 85008027
270+
MOVVP R5, 32764(R4) // 85fc7f27
271+
MOVVP R5, 32(R4) // 85200027
272+
MOVVP R5, 4(R4) // 85040027
273+
MOVVP R5, (R4) // 85000027
274+
MOVWP -32768(R5), R4 // a4008024
275+
MOVWP 32764(R5), R4 // a4fc7f24
276+
MOVWP 32(R5), R4 // a4200024
277+
MOVWP 4(R5), R4 // a4040024
278+
MOVWP (R5), R4 // a4000024
279+
MOVVP -32768(R5), R4 // a4008026
280+
MOVVP 32764(R5), R4 // a4fc7f26
281+
MOVVP 32(R5), R4 // a4200026
282+
MOVVP 4(R5), R4 // a4040026
283+
MOVVP (R5), R4 // a4000026
284+
263285
// Loong64 atomic memory access instructions
264286
AMSWAPB R14, (R13), R12 // ac395c38
265287
AMSWAPH R14, (R13), R12 // acb95c38

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ const (
666666
ABSTRPICKW
667667
ABSTRPICKV
668668

669+
// 2.2.5.3
670+
AMOVWP
671+
AMOVVP
672+
669673
// 2.2.5.4. Prefetch Instructions
670674
APRELD
671675
APRELDX

src/cmd/internal/obj/loong64/anames.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/internal/obj/loong64/asm.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ var optab = []Optab{
212212
{AMOVV, C_REG, C_NONE, C_NONE, C_TLS_LE, C_NONE, 53, 16, 0, 0},
213213
{AMOVB, C_REG, C_NONE, C_NONE, C_TLS_LE, C_NONE, 53, 16, 0, 0},
214214
{AMOVBU, C_REG, C_NONE, C_NONE, C_TLS_LE, C_NONE, 53, 16, 0, 0},
215+
{AMOVWP, C_REG, C_NONE, C_NONE, C_SOREG, C_NONE, 73, 4, 0, 0},
216+
{AMOVWP, C_REG, C_NONE, C_NONE, C_LOREG, C_NONE, 73, 4, 0, 0},
215217

216218
{AMOVW, C_LAUTO, C_NONE, C_NONE, C_REG, C_NONE, 36, 12, REGSP, 0},
217219
{AMOVWU, C_LAUTO, C_NONE, C_NONE, C_REG, C_NONE, 36, 12, REGSP, 0},
@@ -233,6 +235,8 @@ var optab = []Optab{
233235
{AMOVV, C_TLS_LE, C_NONE, C_NONE, C_REG, C_NONE, 54, 16, 0, 0},
234236
{AMOVB, C_TLS_LE, C_NONE, C_NONE, C_REG, C_NONE, 54, 16, 0, 0},
235237
{AMOVBU, C_TLS_LE, C_NONE, C_NONE, C_REG, C_NONE, 54, 16, 0, 0},
238+
{AMOVWP, C_SOREG, C_NONE, C_NONE, C_REG, C_NONE, 74, 4, 0, 0},
239+
{AMOVWP, C_LOREG, C_NONE, C_NONE, C_REG, C_NONE, 74, 4, 0, 0},
236240

237241
{AMOVW, C_SACON, C_NONE, C_NONE, C_REG, C_NONE, 3, 4, REGSP, 0},
238242
{AMOVV, C_SACON, C_NONE, C_NONE, C_REG, C_NONE, 3, 4, REGSP, 0},
@@ -1437,6 +1441,9 @@ func buildop(ctxt *obj.Link) {
14371441
case AMOVBU:
14381442
opset(AMOVHU, r0)
14391443

1444+
case AMOVWP:
1445+
opset(AMOVVP, r0)
1446+
14401447
case AMUL:
14411448
opset(AMULU, r0)
14421449
opset(AMULH, r0)
@@ -1964,6 +1971,10 @@ func OP_16IRR(op uint32, i uint32, r2 uint32, r3 uint32) uint32 {
19641971
return op | (i&0xFFFF)<<10 | (r2&0x1F)<<5 | (r3&0x1F)<<0
19651972
}
19661973

1974+
func OP_14IRR(op uint32, i uint32, r2 uint32, r3 uint32) uint32 {
1975+
return op | (i&0x3FFF)<<10 | (r2&0x1F)<<5 | (r3&0x1F)<<0
1976+
}
1977+
19671978
func OP_12IR_5I(op uint32, i1 uint32, r2 uint32, i2 uint32) uint32 {
19681979
return op | (i1&0xFFF)<<10 | (r2&0x1F)<<5 | (i2&0x1F)<<0
19691980
}
@@ -2893,6 +2904,20 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
28932904
o3 = OP_12IRR(c.opirr(ALU52ID), uint32(v>>52), uint32(REGTMP), uint32(REGTMP))
28942905
}
28952906
o4 = OP_RRR(c.oprrr(p.As), uint32(REGTMP), uint32(r), uint32(p.To.Reg))
2907+
2908+
case 73:
2909+
v := c.regoff(&p.To)
2910+
if v&3 != 0 {
2911+
c.ctxt.Diag("%v: offset must be a multiple of 4.\n", p)
2912+
}
2913+
o1 = OP_14IRR(c.opirr(p.As), uint32(v>>2), uint32(p.To.Reg), uint32(p.From.Reg))
2914+
2915+
case 74:
2916+
v := c.regoff(&p.From)
2917+
if v&3 != 0 {
2918+
c.ctxt.Diag("%v: offset must be a multiple of 4.\n", p)
2919+
}
2920+
o1 = OP_14IRR(c.opirr(-p.As), uint32(v>>2), uint32(p.From.Reg), uint32(p.To.Reg))
28962921
}
28972922

28982923
out[0] = o1
@@ -4026,6 +4051,10 @@ func (c *ctxt0) opirr(a obj.As) uint32 {
40264051
return 0x0ad << 22
40274052
case AMOVD:
40284053
return 0x0af << 22
4054+
case AMOVVP:
4055+
return 0x27 << 24 // stptr.d
4056+
case AMOVWP:
4057+
return 0x25 << 24 // stptr.w
40294058
case -AMOVB:
40304059
return 0x0a0 << 22
40314060
case -AMOVBU:
@@ -4044,6 +4073,10 @@ func (c *ctxt0) opirr(a obj.As) uint32 {
40444073
return 0x0ac << 22
40454074
case -AMOVD:
40464075
return 0x0ae << 22
4076+
case -AMOVVP:
4077+
return 0x26 << 24 // ldptr.d
4078+
case -AMOVWP:
4079+
return 0x24 << 24 // ldptr.w
40474080
case -AVMOVQ:
40484081
return 0x0b0 << 22 // vld
40494082
case -AXVMOVQ:

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,34 @@ Note: In the following sections 3.1 to 3.6, "ui4" (4-bit unsigned int immediate)
289289
290290
Go assembly | instruction Encoding
291291
ALSLV $4, r4, r5, R6 | 002d9486
292+
293+
5. Note of special memory access instructions
294+
Instruction format:
295+
MOVWP offset(Rj), Rd
296+
MOVVP offset(Rj), Rd
297+
MOVWP Rd, offset(Rj)
298+
MOVVP Rd, offset(Rj)
299+
300+
Mapping between Go and platform assembly:
301+
Go assembly | platform assembly
302+
MOVWP offset(Rj), Rd | ldptr.w rd, rj, si14
303+
MOVVP offset(Rj), Rd | ldptr.d rd, rj, si14
304+
MOVWP Rd, offset(Rj) | stptr.w rd, rj, si14
305+
MOVVP Rd, offset(Rj) | stptr.d rd, rj, si14
306+
307+
note: In Go assembly, for ease of understanding, offset is a 16-bit immediate number representing
308+
the actual address offset, but in platform assembly, it need a 14-bit immediate number.
309+
si14 = offset>>2
310+
311+
The addressing calculation for the above instruction involves logically left-shifting the 14-bit
312+
immediate number si14 by 2 bits, then sign-extending it, and finally adding it to the value in the
313+
general-purpose register rj to obtain the sum.
314+
315+
For example:
316+
317+
Go assembly | platform assembly
318+
MOVWP 8(R4), R5 | ldptr.w r5, r4, $2
319+
292320
*/
293321

294322
package loong64

0 commit comments

Comments
 (0)