Skip to content

Commit ddce052

Browse files
sophie-zhaogopherbot
authored andcommitted
cmd/internal/obj/loong64: add ADDU16I.D instruction support
Go asm syntax: ADDV16 $(1<<16), R4, R5 Equivalent platform assembler syntax: addu16i.d r5, r4, $1 Change-Id: Ica4a4e779d0a107cda3eade86027abd6458779a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/699056 Reviewed-by: abner chenc <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 00b8474 commit ddce052

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ lable2:
282282
MOVVP 4(R5), R4 // a4040026
283283
MOVVP (R5), R4 // a4000026
284284

285+
// ADDU16I.D instruction
286+
ADDV16 $(-32768<<16), R4, R5 // ADDV16 $-2147483648, R4, R5 // 85000012
287+
ADDV16 $(0<<16), R4, R5 // ADDV16 $0, R4, R5 // 85000010
288+
ADDV16 $(8<<16), R4, R5 // ADDV16 $524288, R4, R5 // 85200010
289+
ADDV16 $(32767<<16), R4, R5 // ADDV16 $2147418112, R4, R5 // 85fcff11
290+
ADDV16 $(16<<16), R4 // ADDV16 $1048576, R4 // 84400010
291+
285292
// Loong64 atomic memory access instructions
286293
AMSWAPB R14, (R13), R12 // ac395c38
287294
AMSWAPH R14, (R13), R12 // acb95c38

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
TEXT errors(SB),$0
66
VSHUF4IV $16, V1, V2 // ERROR "operand out of range 0 to 15"
77
XVSHUF4IV $16, X1, X2 // ERROR "operand out of range 0 to 15"
8+
ADDV16 $1, R4, R5 // ERROR "the constant must be a multiple of 65536."
9+
ADDV16 $65535, R4, R5 // ERROR "the constant must be a multiple of 65536."

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,9 @@ const (
565565
AMOVVF
566566
AMOVVD
567567

568+
// 2.2.1.2
569+
AADDV16
570+
568571
// 2.2.1.3
569572
AALSLW
570573
AALSLWU

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

Lines changed: 1 addition & 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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ var optab = []Optab{
267267
{AADDV, C_U12CON, C_REG, C_NONE, C_REG, C_NONE, 10, 8, 0, 0},
268268
{AADDV, C_U12CON, C_NONE, C_NONE, C_REG, C_NONE, 10, 8, 0, 0},
269269

270+
{AADDV16, C_32CON, C_REG, C_NONE, C_REG, C_NONE, 4, 4, 0, 0},
271+
{AADDV16, C_32CON, C_NONE, C_NONE, C_REG, C_NONE, 4, 4, 0, 0},
272+
270273
{AAND, C_UU12CON, C_REG, C_NONE, C_REG, C_NONE, 4, 4, 0, 0},
271274
{AAND, C_UU12CON, C_NONE, C_NONE, C_REG, C_NONE, 4, 4, 0, 0},
272275
{AAND, C_S12CON, C_REG, C_NONE, C_REG, C_NONE, 10, 8, 0, 0},
@@ -1520,6 +1523,7 @@ func buildop(ctxt *obj.Link) {
15201523
APRELD,
15211524
APRELDX,
15221525
AFSEL,
1526+
AADDV16,
15231527
obj.ANOP,
15241528
obj.ATEXT,
15251529
obj.AFUNCDATA,
@@ -2087,7 +2091,14 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
20872091
if r == 0 {
20882092
r = int(p.To.Reg)
20892093
}
2090-
o1 = OP_12IRR(c.opirr(p.As), uint32(v), uint32(r), uint32(p.To.Reg))
2094+
if p.As == AADDV16 {
2095+
if v&65535 != 0 {
2096+
c.ctxt.Diag("%v: the constant must be a multiple of 65536.\n", p)
2097+
}
2098+
o1 = OP_16IRR(c.opirr(p.As), uint32(v>>16), uint32(r), uint32(p.To.Reg))
2099+
} else {
2100+
o1 = OP_12IRR(c.opirr(p.As), uint32(v), uint32(r), uint32(p.To.Reg))
2101+
}
20912102

20922103
case 5: // syscall
20932104
v := c.regoff(&p.From)
@@ -4033,6 +4044,8 @@ func (c *ctxt0) opirr(a obj.As) uint32 {
40334044
return 0x00b << 22
40344045
case AADDVU:
40354046
return 0x00b << 22
4047+
case AADDV16:
4048+
return 0x4 << 26
40364049

40374050
case AJMP:
40384051
return 0x14 << 26

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ Note: In the following sections 3.1 to 3.6, "ui4" (4-bit unsigned int immediate)
326326
Go assembly | platform assembly
327327
MOVWP 8(R4), R5 | ldptr.w r5, r4, $2
328328
329+
6. Note of special add instrction
330+
Mapping between Go and platform assembly:
331+
Go assembly | platform assembly
332+
ADDV16 si16<<16, Rj, Rd | addu16i.d rd, rj, si16
333+
334+
note: si16 is a 16-bit immediate number, and si16<<16 is the actual operand.
335+
336+
The addu16i.d instruction logically left-shifts the 16-bit immediate number si16 by 16 bits, then
337+
sign-extends it. The resulting data is added to the [63:0] bits of data in the general-purpose register
338+
rj, and the sum is written into the general-purpose register rd.
339+
The addu16i.d instruction is used in conjunction with the ldptr.w/d and stptr.w/d instructions to
340+
accelerate access based on the GOT table in position-independent code.
329341
*/
330342

331343
package loong64

0 commit comments

Comments
 (0)