Skip to content

Commit bf8d142

Browse files
abner-chencwdvxdr1123
authored andcommitted
cmd/asm: add RDTIME{L,H}.W, RDTIME.D support for loong64
Instruction formats: rdtime rd, rj The RDTIME family of instructions are used to read constant frequency timer information, the stable counter value is written into the general register rd, and the counter id information is written into the general register rj. (Note: both of its register operands are outputs). Ref: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html Change-Id: Ida5bbb28316ef70b5f616dac3e6fa6f2e77875b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/421655 Reviewed-by: xiaodong liu <[email protected]> Reviewed-by: WANG Xuerui <[email protected]> Reviewed-by: Wayne Zuo <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Run-TryBot: Wayne Zuo <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Meidan Li <[email protected]>
1 parent a432d89 commit bf8d142

File tree

7 files changed

+373
-310
lines changed

7 files changed

+373
-310
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ func IsLoong64MUL(op obj.As) bool {
4444
return false
4545
}
4646

47+
// IsLoong64RDTIME reports whether the op (as defined by an loong64.A*
48+
// constant) is one of the RDTIMELW/RDTIMEHW/RDTIMED instructions that
49+
// require special handling.
50+
func IsLoong64RDTIME(op obj.As) bool {
51+
switch op {
52+
case loong64.ARDTIMELW, loong64.ARDTIMEHW, loong64.ARDTIMED:
53+
return true
54+
}
55+
return false
56+
}
57+
4758
func loong64RegisterNumber(name string, n int16) (int16, bool) {
4859
switch name {
4960
case "F":

src/cmd/asm/internal/asm/asm.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,18 @@ func (p *Parser) asmInstruction(op obj.As, cond string, a []obj.Addr) {
642642
prog.Reg = p.getRegister(prog, op, &a[1])
643643
break
644644
}
645+
646+
if arch.IsLoong64RDTIME(op) {
647+
// The Loong64 RDTIME family of instructions is a bit special,
648+
// in that both its register operands are outputs
649+
prog.To = a[0]
650+
if a[1].Type != obj.TYPE_REG {
651+
p.errorf("invalid addressing modes for 2nd operand to %s instruction, must be register", op)
652+
return
653+
}
654+
prog.RegTo2 = a[1].Reg
655+
break
656+
}
645657
}
646658
prog.From = a[0]
647659
prog.To = a[1]

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,7 @@ lable2:
218218
CMPGEF F4, R5 // a090130c
219219
CMPGED F4, R5 // a090230c
220220
CMPEQD F4, R5 // a010220c
221+
222+
RDTIMELW R4, R0 // 80600000
223+
RDTIMEHW R4, R0 // 80640000
224+
RDTIMED R4, R5 // 85680000

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ const (
391391
AMOVVF
392392
AMOVVD
393393

394+
// 2.2.10. Other Miscellaneous Instructions
395+
ARDTIMELW
396+
ARDTIMEHW
397+
ARDTIMED
398+
394399
ALAST
395400

396401
// aliases

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

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

0 commit comments

Comments
 (0)