From 4610f451e99610043461401f4c9acd3de408a02d Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 19 Feb 2023 14:50:01 +0100 Subject: Improved convertion to/from 80bits double, and added BOX64_X87_NO80BITS to not handle them --- docs/USAGE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'docs') diff --git a/docs/USAGE.md b/docs/USAGE.md index bc2bdea3..17fadb61 100755 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -187,6 +187,16 @@ Behavior with FillBlock is not availble (FillBlock build Dynarec blocks and is n * 0 : Dynarec will not wait for FillBlock to ready and use Interpreter instead (might speedup a bit massive multithread or JIT programs) * 1 : Dynarec will wait for FillBlock to be ready (Default) +#### BOX64_SSE_FLUSHTO0 * +Handling of SSE Flush to 0 flags +* 0 : Just track the flag (Default) +* 1 : Direct apply of SSE Flush to 0 flag + +#### BOX64_X87_NO80BITS * +Handling of x87 80bits long double +* 0 : Try to handle 80bits long double as precise as possible (Default) +* 1 : Handle them as double + #### BOX64_LIBGL * * libXXXX set the name for libGL (defaults to libGL.so.1). * /PATH/TO/libGLXXX : Sets the name and path for libGL -- cgit 1.4.1 From d06ff478d188eb4a077041e4b2b628f75ed9eaf8 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 19 Feb 2023 23:54:00 +0100 Subject: [DYNAREC] Introduced BOX64_DYNAREC_FASTPAGE to use an alternate way to handle HotPages (faster but crashy) --- docs/USAGE.md | 7 ++++++- src/dynarec/dynablock.c | 15 +++++++++++++-- src/include/debug.h | 1 + src/main.c | 10 ++++++++++ src/tools/rcfile.c | 8 +++++--- 5 files changed, 35 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/USAGE.md b/docs/USAGE.md index 17fadb61..92913438 100755 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -175,7 +175,12 @@ Optimisation of CALL/RET opcodes (not compatible with jit/dynarec/smc) #### BOX64_DYNAREC_HOTPAGE * Handling of HotPage (Page beeing both executed and writen) * 0 : Don't track hotpage -* 1-255 : Trak HotPage, and disable execution of a page beeing writen for N attempts (default is 16) +* 1-255 : Track HotPage, and disable execution of a page beeing writen for N attempts (default is 16) + +#### BOX64_DYNAREC_FASTPAGE * +Will use a faster handling of HotPage (Page beeing both executed and writen) +* 0 : use regular hotpage (Default) +* 1 : Use faster hotpage, taking the risk of running obsolete JIT code (might be faster, but more prone to crash) #### BOX64_DYNAREC_BLEEDING_EDGE * Detect MonoBleedingEdge and apply conservative settings diff --git a/src/dynarec/dynablock.c b/src/dynarec/dynablock.c index 6ff5e53c..9529a91c 100755 --- a/src/dynarec/dynablock.c +++ b/src/dynarec/dynablock.c @@ -205,8 +205,19 @@ dynablock_t* DBGetBlock(x64emu_t* emu, uintptr_t addr, int create) dynablock_t *db = internalDBGetBlock(emu, addr, addr, create, 1); if(db && db->done && db->block && db->need_test) { if(AreaInHotPage((uintptr_t)db->x64_addr, (uintptr_t)db->x64_addr + db->x64_size - 1)) { - dynarec_log(LOG_INFO, "Not running block %p from %p:%p with for %p because it's in a hotpage\n", db, db->x64_addr, db->x64_addr+db->x64_size-1, (void*)addr); - return NULL; + if(box64_dynarec_fastpage) { + uint32_t hash = X31_hash_code(db->x64_addr, db->x64_size); + if(hash==db->hash) // seems ok, run it without reprotecting it + return db; + db->done = 0; // invalidating the block, it's already not good + dynarec_log(LOG_DEBUG, "Invalidating block %p from %p:%p (hash:%X/%X) for %p\n", db, db->x64_addr, db->x64_addr+db->x64_size-1, hash, db->hash, (void*)addr); + // Free db, it's now invalid! + FreeDynablock(db, 1); + return NULL; // not building a new one, it's still a hotpage + } else { + dynarec_log(LOG_INFO, "Not running block %p from %p:%p with for %p because it's in a hotpage\n", db, db->x64_addr, db->x64_addr+db->x64_size-1, (void*)addr); + return NULL; + } } uint32_t hash = X31_hash_code(db->x64_addr, db->x64_size); if(mutex_trylock(&my_context->mutex_dyndump)) { diff --git a/src/include/debug.h b/src/include/debug.h index 06ec0d8c..b9729787 100755 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -23,6 +23,7 @@ extern int box64_dynarec_safeflags; extern int box64_dynarec_callret; extern int box64_dynarec_bleeding_edge; extern int box64_dynarec_hotpage; +extern int box64_dynarec_fastpage; extern int box64_dynarec_wait; #ifdef ARM64 extern int arm64_asimd; diff --git a/src/main.c b/src/main.c index b8ee9f4b..55a18473 100755 --- a/src/main.c +++ b/src/main.c @@ -57,6 +57,7 @@ int box64_dynarec_fastround = 1; int box64_dynarec_safeflags = 1; int box64_dynarec_callret = 0; int box64_dynarec_hotpage = 16; +int box64_dynarec_fastpage = 0; int box64_dynarec_bleeding_edge = 1; int box64_dynarec_wait = 1; uintptr_t box64_nodynarec_start = 0; @@ -563,6 +564,15 @@ void LoadLogEnv() else printf_log(LOG_INFO, "Dynarec will not tag HotPage\n"); } + p = getenv("BOX64_DYNAREC_FASTPAGE"); + if(p) { + if(strlen(p)==1) { + if(p[0]>='0' && p[0]<='1') + box64_dynarec_fastpage = p[0]-'0'; + } + if(box64_dynarec_fastpage) + printf_log(LOG_INFO, "Dynarec will use Fast HotPage\n"); + } p = getenv("BOX64_NODYNAREC"); if(p) { if (strchr(p,'-')) { diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c index e3789a20..60e1a1e5 100644 --- a/src/tools/rcfile.c +++ b/src/tools/rcfile.c @@ -112,7 +112,8 @@ ENTRYINT(BOX64_DYNAREC_SAFEFLAGS, box64_dynarec_safeflags, 0, 2, 2) \ ENTRYBOOL(BOX64_DYNAREC_CALLRET, box64_dynarec_callret) \ ENTRYBOOL(BOX64_DYNAREC_BLEEDING_EDGE, box64_dynarec_bleeding_edge) \ ENTRYINT(BOX64_DYNAREC_HOTPAGE, box64_dynarec_hotpage, 0, 255, 8) \ -ENTRYBOOL(box64_dynarec_wait, box64_dynarec_wait) \ +ENTRYBOOL(BOX64_DYNAREC_FASTPAGE, box64_dynarec_fastpage) \ +ENTRYBOOL(BOX64_DYNAREC_WAIT, box64_dynarec_wait) \ ENTRYSTRING_(BOX64_NODYNAREC, box64_nodynarec) \ #else @@ -129,7 +130,8 @@ IGNORE(BOX64_DYNAREC_SAFEFLAGS) \ IGNORE(BOX64_DYNAREC_CALLRET) \ IGNORE(BOX64_DYNAREC_BLEEDING_EDGE) \ IGNORE(BOX64_DYNAREC_HOTPAGE) \ -IGNORE(BOX64_DYNAREC_wait) \ +IGNORE(BOX64_DYNAREC_FASTPAGE) \ +IGNORE(BOX64_DYNAREC_WAIT) \ IGNORE(BOX64_NODYNAREC) \ #endif @@ -354,7 +356,7 @@ void LoadRCFile(const char* filename) if(0) ; SUPER() else if(len && current_name) { - printf_log(LOG_INFO, "Warning, unsupported %s=%s for [%s] in %s", key, val, current_name, filename); + printf_log(LOG_INFO, "Warning, unsupported %s=%s for [%s] in %s\n", key, val, current_name, filename); } #undef ENTRYBOOL #undef CENTRYBOOL -- cgit 1.4.1 From fb5ac9c4cddf2bf03ee62dc4addac719c0cf02ab Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Mon, 20 Feb 2023 19:50:26 +0100 Subject: Fixed a improved HotPage handling --- docs/USAGE.md | 2 +- src/custommem.c | 58 +++++++++++++++++++++++++++------------------------------ src/main.c | 2 +- 3 files changed, 29 insertions(+), 33 deletions(-) (limited to 'docs') diff --git a/docs/USAGE.md b/docs/USAGE.md index 92913438..422dc176 100755 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -175,7 +175,7 @@ Optimisation of CALL/RET opcodes (not compatible with jit/dynarec/smc) #### BOX64_DYNAREC_HOTPAGE * Handling of HotPage (Page beeing both executed and writen) * 0 : Don't track hotpage -* 1-255 : Track HotPage, and disable execution of a page beeing writen for N attempts (default is 16) +* 1-255 : Track HotPage, and disable execution of a page beeing writen for N attempts (default is 4) #### BOX64_DYNAREC_FASTPAGE * Will use a faster handling of HotPage (Page beeing both executed and writen) diff --git a/src/custommem.c b/src/custommem.c index 00e24246..6638af31 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -557,25 +557,29 @@ void FreeDynarecMap(uintptr_t addr) } } -uintptr_t getSizeJmpDefault(uintptr_t addr, size_t maxsize) +static uintptr_t getDBSize(uintptr_t addr, size_t maxsize, dynablock_t** db) { - uintptr_t idx3, idx2, idx1, idx0; - idx3 = (((uintptr_t)addr)>>48)&0xffff; + const uintptr_t idx3 = (addr>>48)&0xffff; + const uintptr_t idx2 = (addr>>32)&0xffff; + const uintptr_t idx1 = (addr>>16)&0xffff; + uintptr_t idx0 = addr&0xffff; + *db = *(dynablock_t**)(box64_jmptbl3[idx3][idx2][idx1][idx0]- sizeof(void*)); + if(*db) + return 1; if(box64_jmptbl3[idx3] == box64_jmptbldefault2) - return ((addr&~((1LL<<48)-1))|0xffffffffffffLL)-addr + 1; - idx2 = (((uintptr_t)addr)>>32)&0xffff; + return (addr|0xffffffffffffLL)+1-addr; if(box64_jmptbl3[idx3][idx2] == box64_jmptbldefault1) - return ((addr&~((1LL<<32)-1))|0xffffffffLL)-addr + 1; - idx1 = (((uintptr_t)addr)>>16)&0xffff; + return (addr|0xffffffffLL)+1-addr; uintptr_t* block = box64_jmptbl3[idx3][idx2][idx1]; if(block == box64_jmptbldefault0) - return ((addr&~((1LL<<16)-1))|0xffffLL)-addr + 1; - idx0 = addr&0xffff; + return (addr|0xffffLL)+1-addr; if (maxsize>0x10000) maxsize = 0x10000; while(idx0max_db_size)?0:(addr-my_context->max_db_size)):addr; dynarec_log(LOG_DEBUG, "cleanDBFromAddressRange %p/%p -> %p %s\n", (void*)addr, (void*)start_addr, (void*)(addr+size-1), destroy?"destroy":"mark"); - for (uintptr_t i=start_addr; i>16); i<=(end>>16); ++i) if(memprot[i].prot==memprot_default) { uint8_t* newblock = box_calloc(1<<16, sizeof(uint8_t)); - /*if (native_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) { - box_free(newblock); - }*/ memprot[i].prot = newblock; } for (uintptr_t i=idx; i<=end; ++i) { @@ -817,14 +816,11 @@ void unprotectDB(uintptr_t addr, size_t size, int mark) if(end>16); i<=(end>>16); ++i) + /*for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) if(memprot[i].prot==memprot_default) { uint8_t* newblock = box_calloc(1<<16, sizeof(uint8_t)); - /*if (native_lock_storeifref(&memprot[i], newblock, memprot_default) != newblock) { - box_free(newblock); - }*/ memprot[i].prot = newblock; - } + }*/ for (uintptr_t i=idx; i<=end; ++i) { uint32_t prot = memprot[i>>16].prot[i&0xffff]; if(prot&PROT_DYNAREC) { @@ -1028,7 +1024,7 @@ void allocProtection(uintptr_t addr, size_t size, uint32_t prot) end = (1LL<<(48-MEMPROT_SHIFT))-1; mutex_lock(&mutex_prot); addMapMem(addr, addr+size-1); - for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) + /*for (uintptr_t i=(idx>>16); i<=(end>>16); ++i) if(memprot[i].prot==memprot_default) { uint8_t* newblock = box_calloc(1<<16, sizeof(uint8_t)); memprot[i].prot = newblock; @@ -1042,23 +1038,23 @@ void allocProtection(uintptr_t addr, size_t size, uint32_t prot) block[ii] = prot; } i+=finish-start; // +1 from the "for" loop - } + }*/ mutex_unlock(&mutex_prot); } #ifdef DYNAREC int IsInHotPage(uintptr_t addr) { - if(addr<=(1LL<<48)) + if(addr>=(1LL<<48)) return 0; int idx = (addr>>MEMPROT_SHIFT)>>16; - uint8_t *block = memprot[idx].hot; - if(!block) + uint8_t *hot = memprot[idx].hot; + if(!hot) return 0; int base = (addr>>MEMPROT_SHIFT)&0xffff; - if(!block[base]) + if(!hot[base]) return 0; // decrement hot - native_lock_decifnot0b(&block[base]); + native_lock_decifnot0b(&hot[base]); return 1; } diff --git a/src/main.c b/src/main.c index 55a18473..6b5e6dc7 100755 --- a/src/main.c +++ b/src/main.c @@ -56,7 +56,7 @@ int box64_dynarec_fastnan = 1; int box64_dynarec_fastround = 1; int box64_dynarec_safeflags = 1; int box64_dynarec_callret = 0; -int box64_dynarec_hotpage = 16; +int box64_dynarec_hotpage = 4; int box64_dynarec_fastpage = 0; int box64_dynarec_bleeding_edge = 1; int box64_dynarec_wait = 1; -- cgit 1.4.1