Skip to content

Commit

Permalink
loong64: add the mapping of platform instruction JIRL to plan9 instru…
Browse files Browse the repository at this point in the history
…ction RET

Change-Id: Ifec777b10bc9a5a8e5e9b4fd6bd2077205ad4151
Reviewed-on: https://go-review.googlesource.com/c/arch/+/609495
Reviewed-by: sophie zhao <zhaoxiaolin@loongson.cn>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Qiqi Huang <huangqiqi@loongson.cn>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
  • Loading branch information
limeidan authored and abner-chenc committed Sep 5, 2024
1 parent b3635f5 commit 8644b45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion loong64/loong64asm/inst.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func (i Inst) String() string {
}

case JIRL:
if i.Args[0].(Reg) == R0 && i.Args[2].(OffsetSimm).Imm == 0 {
if i.Args[0].(Reg) == R0 && i.Args[1].(Reg) == R1 && i.Args[2].(OffsetSimm).Imm == 0 {
return "ret"
} else if i.Args[0].(Reg) == R0 && i.Args[2].(OffsetSimm).Imm == 0 {
return "jr " + args[1]
}

Expand Down
7 changes: 6 additions & 1 deletion loong64/loong64asm/plan9x.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64)) strin
rd := inst.Args[0].(Reg)
rj := inst.Args[1].(Reg)
regno := uint16(rj) & 31
if rd == R0 {
off := inst.Args[2].(OffsetSimm).Imm
if rd == R0 && rj == R1 && off == 0 {
return fmt.Sprintf("RET")
} else if rd == R0 && off == 0 {
return fmt.Sprintf("JMP (R%d)", regno)
} else if rd == R0 {
return fmt.Sprintf("JMP %d(R%d)", off, regno)
}
return fmt.Sprintf("CALL (R%d)", regno)

Expand Down
2 changes: 2 additions & 0 deletions loong64/loong64asm/testdata/gnucases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ ac154806| iocsrwr.h $t0, $t1
ac194806| iocsrwr.w $t0, $t1
ac1d4806| iocsrwr.d $t0, $t1
82b54906| invtlb 0x2, $t0, $t1
2000004c| ret
2008004c| jirl $zero, $ra, 8
ac11004c| jirl $t0, $t1, 16
ac410028| ld.b $t0, $t1, 16
ac41002a| ld.bu $t0, $t1, 16
Expand Down
2 changes: 2 additions & 0 deletions loong64/loong64asm/testdata/plan9cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ a0110058| BEQ R13, 4(PC)
47d5ff6f| BGEU R10, R7, -11(PC)
802c006c| BGEU R4, 11(PC)
04d8ff67| BLEZ R4, -10(PC)
2000004c| RET
2008004c| JMP 8(R1)
00040058| JMP 1(PC)
8000004c| JMP (R4)
00340050| JMP 13(PC)
Expand Down

0 comments on commit 8644b45

Please sign in to comment.