Skip to content

Commit

Permalink
[ARM64_DYNAREC] Reworked, again, strongmem emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Feb 6, 2024
1 parent ee2580a commit 8d0cc15
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/dynarec/arm64/dynarec_arm64_00.c
Original file line number Diff line number Diff line change
Expand Up @@ -2160,10 +2160,12 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
call_n(dyn, ninst, *(void**)(addr+8), tmp);
addr+=8+8;
} else {
WILLWRITE2();
GETIP(ip+1); // read the 0xCC
STORE_XEMU_CALL(xRIP);
ADDx_U12(x1, xEmu, (uint32_t)offsetof(x64emu_t, ip)); // setup addr as &emu->ip
CALL_S(x64Int3, -1);
SMWRITE2();
LOAD_XEMU_CALL(xRIP);
addr+=8+8;
TABLE64(x3, addr); // expected return address
Expand Down Expand Up @@ -2834,6 +2836,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
} else {
TABLE64(x2, addr);
}
WILLWRITE2();
PUSH1(x2);
MESSAGE(LOG_DUMP, "Native Call to %s (retn=%d)\n", GetNativeName(GetNativeFnc(dyn->insts[ninst].natcall-1)), dyn->insts[ninst].retn);
SKIPTEST(x1); // disable test as this hack dos 2 instructions for 1
Expand All @@ -2850,13 +2853,15 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
if((box64_log<2 && !cycle_log) && dyn->insts[ninst].natcall && tmp) {
//GETIP(ip+3+8+8); // read the 0xCC
call_n(dyn, ninst, *(void**)(dyn->insts[ninst].natcall+2+8), tmp);
SMWRITE2();
POP1(xRIP); // pop the return address
dyn->last_ip = addr;
} else {
GETIP_(dyn->insts[ninst].natcall); // read the 0xCC already
STORE_XEMU_CALL(xRIP);
ADDx_U12(x1, xEmu, (uint32_t)offsetof(x64emu_t, ip)); // setup addr as &emu->ip
CALL_S(x64Int3, -1);
SMWRITE2();
LOAD_XEMU_CALL(xRIP);
TABLE64(x3, dyn->insts[ninst].natcall);
ADDx_U12(x3, x3, 2+8+8);
Expand Down
15 changes: 10 additions & 5 deletions src/dynarec/arm64/dynarec_arm64_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@
#define PKip(a) *(uint8_t*)(ip+a)

// Strong mem emulation helpers
#define SMREAD_MIN 2
#define SMREAD_MIN 3
#define SMWRITE2_MIN 1
#define SMFIRST_MIN 1
#define SMSEQ_MIN 2
#define SMSEQ_MAX 3
#if STEP == 0
// pass 0 will store is opcode write memory
#define SMWRITE() dyn->insts[ninst].will_write = 1; dyn->smwrite = 1
#define SMREAD()
#define SMREADLOCK(lock)
#define SMMIGHTREAD()
#define SMWRITE2() if(box64_dynarec_strongmem>SMREAD_MIN) {SMWRITE();}
#define WILLWRITE2() if(box64_dynarec_strongmem>SMWRITE2_MIN) {WILLWRITE();}
#define SMWRITE2() if(box64_dynarec_strongmem>SMWRITE2_MIN) {SMWRITE();}
#define SMWRITELOCK(lock) SMWRITE()
#define WILLWRITELOCK(lock)
#define WILLWRITE()
Expand All @@ -60,11 +64,12 @@
// Opcode might read (depend on nextop)
#define SMMIGHTREAD() if(!MODREG) {SMREAD();}
// Opcode has wrote
#define SMWRITE() if((box64_dynarec_strongmem>=SMFIRST_MIN) && dyn->smwrite==0) {SMDMB();} dyn->smwrite=1
#define SMWRITE() if((box64_dynarec_strongmem>=SMFIRST_MIN) && dyn->smwrite==0) {SMDMB();} if(box64_dynarec_strongmem>SMSEQ_MIN) {if(++dyn->smwrite>=SMSEQ_MAX) {SMDMB(); dyn->smwrite=1;}} else dyn->smwrite=1
// Opcode has wrote (strongmem>1 only)
#define SMWRITE2() if(box64_dynarec_strongmem>SMREAD_MIN) {SMWRITE();}
#define WILLWRITE2() if(box64_dynarec_strongmem>SMWRITE2_MIN) {WILLWRITE();}
#define SMWRITE2() if(box64_dynarec_strongmem>SMWRITE2_MIN) {SMWRITE();}
// Opcode has wrote with option forced lock
#define SMWRITELOCK(lock) if(lock) {SMDMB();} else {SMWRITE();}
#define SMWRITELOCK(lock) if(lock) {SMDMB(); dyn->smwrite=1;} else {SMWRITE();}
// Opcode has wrote with option forced lock
#define WILLWRITELOCK(lock) if(lock) {DMB_ISH();} else {WILLWRITE();}
// Opcode might have wrote (depend on nextop)
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,11 @@ void LoadLogEnv()
p = getenv("BOX64_DYNAREC_STRONGMEM");
if(p) {
if(strlen(p)==1) {
if(p[0]>='0' && p[0]<='3')
if(p[0]>='0' && p[0]<='4')
box64_dynarec_strongmem = p[0]-'0';
}
if(box64_dynarec_strongmem)
printf_log(LOG_INFO, "Dynarec will try to emulate a strong memory model%s\n", (box64_dynarec_strongmem==1)?" with limited performance loss":((box64_dynarec_strongmem==3)?" with more performance loss":""));
printf_log(LOG_INFO, "Dynarec will try to emulate a strong memory model%s\n", (box64_dynarec_strongmem==1)?" with limited performance loss":((box64_dynarec_strongmem>1)?" with more performance loss":""));
}
p = getenv("BOX64_DYNAREC_X87DOUBLE");
if(p) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rcfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ENTRYINT(BOX64_DYNAREC_DUMP, box64_dynarec_dump, 0, 2, 2) \
ENTRYINT(BOX64_DYNAREC_LOG, box64_dynarec_log, 0, 3, 2) \
ENTRYINT(BOX64_DYNAREC_BIGBLOCK, box64_dynarec_bigblock, 0, 3, 2) \
ENTRYSTRING_(BOX64_DYNAREC_FORWARD, box64_dynarec_forward) \
ENTRYINT(BOX64_DYNAREC_STRONGMEM, box64_dynarec_strongmem, 0, 3, 2) \
ENTRYINT(BOX64_DYNAREC_STRONGMEM, box64_dynarec_strongmem, 0, 4, 3) \
ENTRYBOOL(BOX64_DYNAREC_X87DOUBLE, box64_dynarec_x87double) \
ENTRYBOOL(BOX64_DYNAREC_DIV0, box64_dynarec_div0) \
ENTRYBOOL(BOX64_DYNAREC_FASTNAN, box64_dynarec_fastnan) \
Expand Down

0 comments on commit 8d0cc15

Please sign in to comment.