Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RV64_DYNAREC] Removed some TABLE64 usage #2291

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/dynarec/rv64/dynarec_rv64_00_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
} else {
GETIP(ip + 1); // read the 0xCC
STORE_XEMU_CALL(x3);
ADDI(x3, xRIP, 8 + 8); // expected return address
ADDI(x1, xEmu, (uint32_t)offsetof(x64emu_t, ip)); // setup addr as &emu->ip
CALL_S(x64Int3, -1, x1);
CALL_(x64Int3, -1, x3, x1, 0);
LOAD_XEMU_CALL();
addr += 8 + 8;
TABLE64(x3, addr); // expected return address
BNE_MARK(xRIP, x3);
LW(x1, xEmu, offsetof(x64emu_t, quit));
CBZ_NEXT(x1);
Expand Down Expand Up @@ -927,7 +927,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
if (!rex.is32bits && isNativeCall(dyn, addr + i32, rex.is32bits, &dyn->insts[ninst].natcall, &dyn->insts[ninst].retn))
tmp = dyn->insts[ninst].pass2choice = 3;
else
tmp = dyn->insts[ninst].pass2choice = 0;
tmp = dyn->insts[ninst].pass2choice = i32 ? 0 : 1;
#else
tmp = dyn->insts[ninst].pass2choice;
#endif
Expand All @@ -939,7 +939,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
if (dyn->last_ip && (addr - dyn->last_ip < 0x800)) {
ADDI(x2, xRIP, addr - dyn->last_ip);
} else {
TABLE64(x2, addr);
MOV64x(x2, addr);
}
PUSH1(x2);
MESSAGE(LOG_DUMP, "Native Call to %s (retn=%d)\n", GetNativeName(GetNativeFnc(dyn->insts[ninst].natcall - 1)), dyn->insts[ninst].retn);
Expand All @@ -966,7 +966,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
ADDI(x1, xEmu, (uint32_t)offsetof(x64emu_t, ip)); // setup addr as &emu->ip
CALL_S(x64Int3, -1, x1);
LOAD_XEMU_CALL();
TABLE64(x3, dyn->insts[ninst].natcall);
MOV64x(x3, dyn->insts[ninst].natcall);
ADDI(x3, x3, 2 + 8 + 8);
BNE_MARK(xRIP, x3); // Not the expected address, exit dynarec block
POP1(xRIP); // pop the return address
Expand All @@ -978,15 +978,18 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
ADD(xRSP, xRSP, x3);
}
}
TABLE64(x3, addr);
BNE_MARK(xRIP, x3); // Not the expected address again
LW(x1, xEmu, offsetof(x64emu_t, quit));
CBZ_NEXT(x1);
MARK;
jump_to_epilog_fast(dyn, 0, xRIP, ninst);
dyn->last_ip = addr;
}
break;
case 1:
// this is call to next step, so just push the return address to the stack
MOV64x(x2, addr);
PUSH1z(x2);
break;
default:
if ((BOX64DRENV(dynarec_safeflags) > 1) || (ninst && dyn->insts[ninst - 1].x64.set_flags)) {
READFLAGS(X_PEND); // that's suspicious
Expand All @@ -1002,11 +1005,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
*ok = 0;
}*/

if (rex.is32bits) {
MOV32w(x2, addr);
} else {
TABLE64(x2, addr);
}
MOV64x(x2, addr);
fpu_purgecache(dyn, ninst, 1, x1, x3, x4);
PUSH1z(x2);
if (BOX64DRENV(dynarec_callret)) {
Expand Down Expand Up @@ -1034,7 +1033,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
if (BOX64DRENV(dynarec_callret) && addr >= (dyn->start + dyn->isize)) {
// jumps out of current dynablock...
j64 = getJumpTableAddress64(addr);
TABLE64(x4, j64);
MOV64x(x4, j64);
LD(x4, x4, 0);
BR(x4);
}
Expand Down
28 changes: 10 additions & 18 deletions src/dynarec/rv64/dynarec_rv64_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1107,33 +1107,25 @@
dyn->vector_sew = VECTOR_SEWNA;

#if STEP < 2
#define GETIP(A) TABLE64(0, 0)
#define GETIP_(A) TABLE64(0, 0)
#define GETIP(A) MOV64x(xRIP, A)
#define GETIP_(A) MOV64x(xRIP, A)
#else
// put value in the Table64 even if not using it for now to avoid difference between Step2 and Step3. Needs to be optimized later...
#define GETIP(A) \
if (dyn->last_ip && ((A) - dyn->last_ip) < 2048) { \
uint64_t _delta_ip = (A) - dyn->last_ip; \
dyn->last_ip += _delta_ip; \
if (_delta_ip) { \
ADDI(xRIP, xRIP, _delta_ip); \
} \
if (_delta_ip) ADDI(xRIP, xRIP, _delta_ip); \
} else { \
dyn->last_ip = (A); \
if (dyn->last_ip < 0xffffffff) { \
MOV64x(xRIP, dyn->last_ip); \
} else \
TABLE64(xRIP, dyn->last_ip); \
MOV64x(xRIP, (A)); \
}
#define GETIP_(A) \
if (dyn->last_ip && ((A) - dyn->last_ip) < 2048) { \
int64_t _delta_ip = (A) - dyn->last_ip; \
if (_delta_ip) { ADDI(xRIP, xRIP, _delta_ip); } \
} else { \
if ((A) < 0xffffffff) { \
MOV64x(xRIP, (A)); \
} else \
TABLE64(xRIP, (A)); \
#define GETIP_(A) \
if (dyn->last_ip && ((A) - dyn->last_ip) < 2048) { \
int64_t _delta_ip = (A) - dyn->last_ip; \
if (_delta_ip) ADDI(xRIP, xRIP, _delta_ip); \
} else { \
MOV64x(xRIP, (A)); \
}
#endif
#define CLEARIP() dyn->last_ip = 0
Expand Down
Loading