loong64/loong64asm: add support for aliases rdcnt{vl,vh,id}.w in the GNUSyntax
Patches [1] supporting these pseudo-instructions have landed in the GNU toolchain.
Fixes golang/go#79975.
[1]: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=eff93f19cb973c58fbc9899e4e111d583e4a1dbe
Change-Id: Id010833b0f1f793a22f7a28e007a3f31bb8b7beb
Reviewed-on: https://go-review.googlesource.com/c/arch/+/790100
Reviewed-by: Meidan Li <limeidan@loongson.cn>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
diff --git a/loong64/loong64asm/ext_test.go b/loong64/loong64asm/ext_test.go
index 5e73c80..7d479dc 100644
--- a/loong64/loong64asm/ext_test.go
+++ b/loong64/loong64asm/ext_test.go
@@ -228,7 +228,7 @@
text = "error: " + err.Error()
return
}
- text = inst.String()
+
switch syntax {
case "gnu":
text = GNUSyntax(inst)
diff --git a/loong64/loong64asm/inst.go b/loong64/loong64asm/inst.go
index 362d73b..ad97323 100644
--- a/loong64/loong64asm/inst.go
+++ b/loong64/loong64asm/inst.go
@@ -63,6 +63,26 @@
op = "bgez"
args = append(args[:1], args[2:]...)
}
+
+ case RDTIMEH_W:
+ // rdtimeh.w rd, zero => rdcntvh.w rd
+ if i.Args[1].(Reg) == R0 && i.Args[0].(Reg) != R0 {
+ op = "rdcntvh.w"
+ args = args[:1]
+ }
+
+ case RDTIMEL_W:
+ // rdtimel.w zero, rj => rdcntid.w rj
+ if i.Args[0].(Reg) == R0 && i.Args[1].(Reg) != R0 {
+ op = "rdcntid.w"
+ args = args[1:]
+ }
+
+ // rdtimel.w rd, zero => rdcntvl.w rd
+ if i.Args[0].(Reg) != R0 && i.Args[1].(Reg) == R0 {
+ op = "rdcntvl.w"
+ args = args[:1]
+ }
}
if len(args) == 0 {
diff --git a/loong64/loong64asm/testdata/plan9cases.txt b/loong64/loong64asm/testdata/plan9cases.txt
index c6a5bd5..35b27c4 100644
--- a/loong64/loong64asm/testdata/plan9cases.txt
+++ b/loong64/loong64asm/testdata/plan9cases.txt
@@ -207,7 +207,9 @@
8464c817| LU32ID $-113884, R4
848c0203| LU52ID $163, R4
80600000| RDTIMELW R4, R0
+04600000| RDTIMELW R0, R4
80640000| RDTIMEHW R4, R0
+04640000| RDTIMEHW R0, R4
85680000| RDTIMED R4, R5
1e00001a| PCALAU12I $0, R30
0c02001c| PCADDU12I $16, R12