about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2024-09-29 16:39:28 +0800
committerGitHub <noreply@github.com>2024-09-29 10:39:28 +0200
commit9a83521ad6dd1c23cf79766cfd6328bfc4c2fec7 (patch)
tree8d6e395aac02ac3cb263f886847882ab8b93e7ce /src
parent2a7eabfb1c4f883e20b3415cf8cfe87840a35e71 (diff)
downloadbox64-9a83521ad6dd1c23cf79766cfd6328bfc4c2fec7.tar.gz
box64-9a83521ad6dd1c23cf79766cfd6328bfc4c2fec7.zip
[RV64_DYNAREC] Minor optimization on vector_vsetvli (#1885)
Diffstat (limited to 'src')
-rw-r--r--src/dynarec/rv64/dynarec_rv64_helper.c11
-rw-r--r--src/dynarec/rv64/rv64_printer.c2
2 files changed, 9 insertions, 4 deletions
diff --git a/src/dynarec/rv64/dynarec_rv64_helper.c b/src/dynarec/rv64/dynarec_rv64_helper.c
index beed783a..bddb329c 100644
--- a/src/dynarec/rv64/dynarec_rv64_helper.c
+++ b/src/dynarec/rv64/dynarec_rv64_helper.c
@@ -2601,7 +2601,7 @@ void fpu_propagate_stack(dynarec_rv64_t* dyn, int ninst)
     dyn->e.swapped = 0;
 }
 
-// Simple wrapper for vsetvli
+// Simple wrapper for vsetvli, may use s1 as scratch
 int vector_vsetvli(dynarec_rv64_t* dyn, int ninst, int s1, int sew, int vlmul, float multiple)
 {
     if (sew == VECTOR_SEWNA) return VECTOR_SEW8;
@@ -2613,7 +2613,12 @@ int vector_vsetvli(dynarec_rv64_t* dyn, int ninst, int s1, int sew, int vlmul, f
      *
      *                    mu            tu          sew      lmul */
     uint32_t vtypei = (0b0 << 7) | (0b0 << 6) | (sew << 3) | vlmul;
-    ADDI(s1, xZR, (int)((float)(16 >> sew) * multiple)); // TODO: it's possible to reuse s1 sometimes
-    VSETVLI(xZR, s1, vtypei);
+    uint32_t vl = (int)((float)(16 >> sew) * multiple);
+    if (vl <= 31) {
+        VSETIVLI(xZR, vl, vtypei);
+    } else {
+        ADDI(s1, xZR, vl);
+        VSETVLI(xZR, s1, vtypei);
+    }
     return sew;
 }
diff --git a/src/dynarec/rv64/rv64_printer.c b/src/dynarec/rv64/rv64_printer.c
index a9e619b6..a5e6fc07 100644
--- a/src/dynarec/rv64/rv64_printer.c
+++ b/src/dynarec/rv64/rv64_printer.c
@@ -5018,7 +5018,7 @@ const char* rv64_print(uint32_t opcode, uintptr_t addr)
             default: sew_str = "reserved"; break;
         }
 
-        snprintf(buff, sizeof(buff), "%-15s %s, %d, %s, %s, %s, %s", "VSETVLI", gpr[a.rd], a.imm2, sew_str, lmul_str, vta_str, vma_str);
+        snprintf(buff, sizeof(buff), "%-15s %s, %d, %s, %s, %s, %s", "VSETIVLI", gpr[a.rd], a.imm2, sew_str, lmul_str, vta_str, vma_str);
         return buff;
     }