about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-05-27 17:29:33 +0800
committerGitHub <noreply@github.com>2025-05-27 11:29:33 +0200
commita9f4e72c4b4f15289c8eef0b9be0359e2acf50dc (patch)
tree43dc29af182fe249380a6ccb81f61f009326b472 /src
parent1f46ca81af53d1e7177d52af58ec8eeae2a35e80 (diff)
downloadbox64-a9f4e72c4b4f15289c8eef0b9be0359e2acf50dc.tar.gz
box64-a9f4e72c4b4f15289c8eef0b9be0359e2acf50dc.zip
[RV64_DYNAREC] Fixed regression introduced in #2669 (#2676)
Diffstat (limited to 'src')
-rw-r--r--src/dynarec/rv64/dynarec_rv64_helper.c44
-rw-r--r--src/dynarec/rv64/dynarec_rv64_helper.h7
-rw-r--r--src/dynarec/rv64/dynarec_rv64_pass0.h5
-rw-r--r--src/dynarec/rv64/rv64_emitter.h2
4 files changed, 30 insertions, 28 deletions
diff --git a/src/dynarec/rv64/dynarec_rv64_helper.c b/src/dynarec/rv64/dynarec_rv64_helper.c
index 6299de8d..e9ba7119 100644
--- a/src/dynarec/rv64/dynarec_rv64_helper.c
+++ b/src/dynarec/rv64/dynarec_rv64_helper.c
@@ -66,7 +66,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                     } else {
                         if (sib >> 6) {
                             SLLI(ret, TO_NAT(sib_reg), (sib >> 6));
-                            SCRATCH_USAGE(!IS_GPR(ret));
+                            if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                         } else
                             ret = TO_NAT(sib_reg);
                         *fixaddress = tmp;
@@ -79,19 +79,19 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                             break;
                     }
                     MOV64x(ret, tmp);
-                    SCRATCH_USAGE(!IS_GPR(ret));
+                    if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                 }
             } else {
                 if (sib_reg != 4) {
                     if (!(sib >> 6)) {
                         ADD(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg));
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     } else if (rv64_zba) {
                         SHxADD(ret, TO_NAT(sib_reg), sib >> 6, TO_NAT(sib_reg2));
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     } else if (rv64_xtheadba) {
                         TH_ADDSL(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg), sib >> 6);
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     } else {
                         SLLI(scratch, TO_NAT(sib_reg), sib >> 6);
                         ADD(ret, TO_NAT(sib_reg2), scratch);
@@ -114,18 +114,15 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                 SCRATCH_USAGE(1);
             } else if (adj && (tmp + adj >= -2048) && (tmp + adj <= maxval)) {
                 ADDI(ret, xRIP, tmp + adj);
-                SCRATCH_USAGE(!IS_GPR(ret));
             } else if ((tmp >= -2048) && (tmp <= maxval)) {
                 GETIP(addr + delta, scratch);
                 ADDI(ret, xRIP, tmp);
                 SCRATCH_USAGE(1);
             } else if (tmp + addr + delta < 0x100000000LL) {
                 MOV64x(ret, tmp + addr + delta);
-                SCRATCH_USAGE(!IS_GPR(ret));
             } else {
                 if (adj) {
                     MOV64x(ret, tmp + adj);
-                    SCRATCH_USAGE(!IS_GPR(ret));
                 } else {
                     MOV64x(ret, tmp);
                     GETIP(addr + delta, scratch);
@@ -139,6 +136,7 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                     if (isLockAddress(addr + delta + tmp)) *l = 1;
                     break;
             }
+            SCRATCH_USAGE(1);
         } else {
             ret = TO_NAT((nextop & 7) + (rex.b << 3));
         }
@@ -161,13 +159,13 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                 if (sib_reg != 4) {
                     if (!(sib >> 6)) {
                         ADD(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg));
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     } else if (rv64_zba) {
                         SHxADD(ret, TO_NAT(sib_reg), sib >> 6, TO_NAT(sib_reg2));
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     } else if (rv64_xtheadba) {
                         TH_ADDSL(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg), sib >> 6);
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     } else {
                         SLLI(scratch, TO_NAT(sib_reg), sib >> 6);
                         ADD(ret, TO_NAT(sib_reg2), scratch);
@@ -184,13 +182,13 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                     if (sib_reg != 4) {
                         if (!(sib >> 6)) {
                             ADD(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg));
-                            SCRATCH_USAGE(!IS_GPR(ret));
+                            if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                         } else if (rv64_zba) {
                             SHxADD(ret, TO_NAT(sib_reg), sib >> 6, TO_NAT(sib_reg2));
-                            SCRATCH_USAGE(!IS_GPR(ret));
+                            if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                         } else if (rv64_xtheadba) {
                             TH_ADDSL(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg), sib >> 6);
-                            SCRATCH_USAGE(!IS_GPR(ret));
+                            if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                         } else {
                             SLLI(scratch, TO_NAT(sib_reg), sib >> 6);
                             ADD(ret, TO_NAT(sib_reg2), scratch);
@@ -199,11 +197,11 @@ uintptr_t geted(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_t nextop,
                         ADDI(ret, ret, i64);
                     } else {
                         ADDI(ret, TO_NAT(sib_reg2), i64);
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     }
                 } else {
                     ADDI(ret, TO_NAT((nextop & 0x07) + (rex.b << 3)), i64);
-                    SCRATCH_USAGE(!IS_GPR(ret));
+                    if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                 }
             } else {
                 MOV64x(scratch, i64);
@@ -264,7 +262,7 @@ static uintptr_t geted_32(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_
                     } else {
                         if (sib >> 6) {
                             SLLI(ret, TO_NAT(sib_reg), (sib >> 6));
-                            SCRATCH_USAGE(!IS_GPR(ret));
+                            if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                         } else
                             ret = TO_NAT(sib_reg);
                         *fixaddress = tmp;
@@ -277,7 +275,7 @@ static uintptr_t geted_32(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_
                             break;
                     }
                     MOV32w(ret, tmp);
-                    SCRATCH_USAGE(!IS_GPR(ret));
+                    if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                 }
             } else {
                 if (sib_reg != 4) {
@@ -287,7 +285,7 @@ static uintptr_t geted_32(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_
                         SCRATCH_USAGE(1);
                     } else {
                         ADDW(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg));
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     }
                     ZEROUP(ret);
                 } else {
@@ -297,7 +295,7 @@ static uintptr_t geted_32(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_
         } else if ((nextop & 7) == 5) {
             uint32_t tmp = F32;
             MOV32w(ret, tmp);
-            SCRATCH_USAGE(!IS_GPR(ret));
+            if (!IS_GPR(ret)) SCRATCH_USAGE(1);
             switch (lock) {
                 case 1: addLockAddress(tmp); break;
                 case 2:
@@ -333,7 +331,7 @@ static uintptr_t geted_32(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_
                         SCRATCH_USAGE(1);
                     } else {
                         ADDW(ret, TO_NAT(sib_reg2), TO_NAT(sib_reg));
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     }
                     ZEROUP(ret);
                 } else {
@@ -354,11 +352,11 @@ static uintptr_t geted_32(dynarec_rv64_t* dyn, uintptr_t addr, int ninst, uint8_
                         SCRATCH_USAGE(1);
                     } else {
                         scratch = TO_NAT(sib_reg2);
-                        SCRATCH_USAGE(!IS_GPR(ret));
+                        if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                     }
                 } else {
                     scratch = TO_NAT(nextop & 0x07);
-                    SCRATCH_USAGE(!IS_GPR(ret));
+                    if (!IS_GPR(ret)) SCRATCH_USAGE(1);
                 }
                 ADDIW(ret, scratch, i32);
                 ZEROUP(ret);
diff --git a/src/dynarec/rv64/dynarec_rv64_helper.h b/src/dynarec/rv64/dynarec_rv64_helper.h
index 0fd8cf75..4f923318 100644
--- a/src/dynarec/rv64/dynarec_rv64_helper.h
+++ b/src/dynarec/rv64/dynarec_rv64_helper.h
@@ -2006,9 +2006,8 @@ uintptr_t dynarec64_AVX_F3_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip,
 #define VECTOR_LOAD_VMASK(mask, s1, multiple) \
     vector_loadmask(dyn, ninst, VMASK, mask, s1, multiple)
 
-#define SCRATCH_USAGE(usage)                         \
-    do {                                             \
-        dyn->insts[ninst].no_scratch_usage = !usage; \
-    } while (0)
+#ifndef SCRATCH_USAGE
+#define SCRATCH_USAGE(usage)
+#endif
 
 #endif //__DYNAREC_RV64_HELPER_H__
diff --git a/src/dynarec/rv64/dynarec_rv64_pass0.h b/src/dynarec/rv64/dynarec_rv64_pass0.h
index a5cefa8c..42aa11c2 100644
--- a/src/dynarec/rv64/dynarec_rv64_pass0.h
+++ b/src/dynarec/rv64/dynarec_rv64_pass0.h
@@ -111,3 +111,8 @@
     do {                                                            \
         if (dyn->need_x87check) dyn->insts[ninst].x87precision = 1; \
     } while (0)
+
+#define SCRATCH_USAGE(usage)                         \
+    do {                                             \
+        dyn->insts[ninst].no_scratch_usage = !usage; \
+    } while (0)
diff --git a/src/dynarec/rv64/rv64_emitter.h b/src/dynarec/rv64/rv64_emitter.h
index 995e4bff..f541e0a5 100644
--- a/src/dynarec/rv64/rv64_emitter.h
+++ b/src/dynarec/rv64/rv64_emitter.h
@@ -278,7 +278,7 @@
     BLTU(rs2, rs3, 8);           \
     MV(rd, rs1);
 #define MVGT(rd, rs1, rs2, rs3) \
-    BGEU(rs3, rs2, 8);          \
+    BGE(rs3, rs2, 8);           \
     MV(rd, rs1);
 #define MVLE(rd, rs1, rs2, rs3) \
     BLT(rs3, rs2, 8);           \