From 9705d5e38bdf4ec72daf480de0830dfde6e33a70 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 18 Feb 2023 15:06:40 +0100 Subject: Preliminary work to get steamwebhelper working --- src/include/debug.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/include/debug.h') diff --git a/src/include/debug.h b/src/include/debug.h index 7251c728..0a6f722e 100755 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -45,6 +45,7 @@ extern char* box64_trace; extern uint64_t start_cnt; #endif extern int box64_nosandbox; +extern int box64_malloc_hack; extern int box64_dummy_crashhandler; extern int box64_sse_flushto0; extern int allow_missing_libs; -- cgit 1.4.1 From 5d42d9212fde49278e0ad0167edd77755a2fbcd9 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 ++++++++++ src/dynarec/arm64/dynarec_arm64_db.c | 30 +++++++++++++++++++++--------- src/emu/x87emu_private.c | 30 +++++++++++++++++++++++++++++- src/include/debug.h | 1 + src/main.c | 7 +++++++ src/tools/rcfile.c | 1 + 6 files changed, 69 insertions(+), 10 deletions(-) (limited to 'src/include/debug.h') diff --git a/docs/USAGE.md b/docs/USAGE.md index e961ebb2..fa908e46 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 diff --git a/src/dynarec/arm64/dynarec_arm64_db.c b/src/dynarec/arm64/dynarec_arm64_db.c index b9d71080..e40cc71d 100644 --- a/src/dynarec/arm64/dynarec_arm64_db.c +++ b/src/dynarec/arm64/dynarec_arm64_db.c @@ -295,21 +295,33 @@ uintptr_t dynarec64_DB(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin STRx_U12(x5, ed, 0); STRH_U12(x6, ed, 8); } else { - if(ed!=x1) { - MOVx_REG(x1, ed); + if(box64_x87_no80bits) { + v1 = x87_do_push(dyn, ninst, x1, NEON_CACHE_ST_D); + addr = geted(dyn, addr, ninst, nextop, &ed, x2, &fixedaddress, 0xfff<<3, 7, rex, NULL, 0, 0); + VLDR64_U12(v1, ed, fixedaddress); + } else { + if(ed!=x1) { + MOVx_REG(x1, ed); + } + x87_do_push_empty(dyn, ninst, x3); + CALL(arm_fld, -1); } - x87_do_push_empty(dyn, ninst, x3); - CALL(arm_fld, -1); } break; case 7: INST_NAME("FSTP tbyte"); - x87_forget(dyn, ninst, x1, x3, 0); - addr = geted(dyn, addr, ninst, nextop, &ed, x1, &fixedaddress, 0, 0, rex, NULL, 0, 0); - if(ed!=x1) { - MOVx_REG(x1, ed); + if(box64_x87_no80bits) { + v1 = x87_get_st(dyn, ninst, x1, x2, 0, NEON_CACHE_ST_D); + addr = geted(dyn, addr, ninst, nextop, &wback, x2, &fixedaddress, 0xfff<<3, 7, rex, NULL, 0, 0); + VSTR64_U12(v1, wback, fixedaddress); + } else { + x87_forget(dyn, ninst, x1, x3, 0); + addr = geted(dyn, addr, ninst, nextop, &ed, x1, &fixedaddress, 0, 0, rex, NULL, 0, 0); + if(ed!=x1) { + MOVx_REG(x1, ed); + } + CALL(arm_fstp, -1); } - CALL(arm_fstp, -1); x87_do_pop(dyn, ninst, x3); break; default: diff --git a/src/emu/x87emu_private.c b/src/emu/x87emu_private.c index 2114c00d..9f4b8af6 100755 --- a/src/emu/x87emu_private.c +++ b/src/emu/x87emu_private.c @@ -83,6 +83,10 @@ void fpu_fbld(x64emu_t* emu, uint8_t* s) { // long double (80bits) -> double (64bits) void LD2D(void* ld, void* d) { + if(box64_x87_no80bits) { + *(uint64_t*)d = *(uint64_t*)ld; + return; + } FPU_t result; #pragma pack(push, 1) struct { @@ -122,7 +126,7 @@ void LD2D(void* ld, void* d) *(uint64_t*)d = result.q; return; } - if(((uint32_t)(val.b&0x7fff)==0) || (exp64<=0)) { + if(((uint32_t)(val.b&0x7fff)==0) || (exp64<-1074)) { //if(val.f.q==0) // zero //if(val.f.q!=0) @@ -134,6 +138,18 @@ void LD2D(void* ld, void* d) return; } + if(exp64<=0 && val.f.q) { + // try to see if it can be a denormal + int one = -exp64-1022; + uint64_t r = 0; + if(val.b&0x8000) + r |= 0x8000000000000000L; + r |= val.f.q>>one; + *(uint64_t*)d = r; + return; + + } + if(exp64>=0x7ff) { // to big value... result.d = HUGE_VAL; @@ -154,6 +170,10 @@ void LD2D(void* ld, void* d) // double (64bits) -> long double (80bits) void D2LD(void* d, void* ld) { + if(box64_x87_no80bits) { + *(uint64_t*)ld = *(uint64_t*)d; + return; + } #pragma pack(push, 1) struct { FPU_t f; @@ -190,6 +210,12 @@ void D2LD(void* d, void* ld) if(exp80!=0){ mant80final |= 0x8000000000000000L; exp80final += (BIAS80 - BIAS64); + } else if(mant80final!=0) { + // denormals -> normal + exp80final = BIAS80-1023; + int one = __builtin_clz(mant80final) + 1; + exp80final -= one; + mant80final<<=one; } } val.b = ((int16_t)(sign80)<<15)| (int16_t)(exp80final); @@ -201,6 +227,8 @@ void D2LD(void* d, void* ld) double FromLD(void* ld) { + if(box64_x87_no80bits) + return *(double*)ld; double ret; // cannot add = 0; it break factorio (issue when calling fmodl) LD2D(ld, &ret); return ret; diff --git a/src/include/debug.h b/src/include/debug.h index 0a6f722e..024805a1 100755 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -48,6 +48,7 @@ extern int box64_nosandbox; extern int box64_malloc_hack; extern int box64_dummy_crashhandler; extern int box64_sse_flushto0; +extern int box64_x87_no80bits; extern int allow_missing_libs; extern int box64_mapclean; extern int box64_prefer_wrapped; diff --git a/src/main.c b/src/main.c index 4c0af6cd..ea809e54 100755 --- a/src/main.c +++ b/src/main.c @@ -93,6 +93,7 @@ int allow_missing_libs = 0; int box64_prefer_emulated = 0; int box64_prefer_wrapped = 0; int box64_sse_flushto0 = 0; +int box64_x87_no80bits = 0; int fix_64bit_inodes = 0; int box64_dummy_crashhandler = 1; int box64_mapclean = 0; @@ -965,6 +966,12 @@ void LoadEnvVars(box64context_t *context) printf_log(LOG_INFO, "BOX64: Direct apply of SSE Flush to 0 flag\n"); } } + if(getenv("BOX64_X87_NO80BITS")) { + if (strcmp(getenv("BOX64_X87_NO80BITS"), "1")==0) { + box64_x87_no80bits = 1; + printf_log(LOG_INFO, "BOX64: all 80bits x87 long double will be handle as double\n"); + } + } if(getenv("BOX64_PREFER_WRAPPED")) { if (strcmp(getenv("BOX64_PREFER_WRAPPED"), "1")==0) { box64_prefer_wrapped = 1; diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c index 8a2ac920..75df7137 100644 --- a/src/tools/rcfile.c +++ b/src/tools/rcfile.c @@ -64,6 +64,7 @@ ENTRYBOOL(BOX64_X11THREADS, box64_x11threads) \ ENTRYBOOL(BOX64_X11GLX, box64_x11glx) \ ENTRYDSTRING(BOX64_LIBGL, box64_libGL) \ ENTRYBOOL(BOX64_SSE_FLUSHTO0, box64_sse_flushto0) \ +ENTRYBOOL(BOX64_X87_NO80BITS, box64_x87_no80bits) \ ENTRYSTRING_(BOX64_EMULATED_LIBS, emulated_libs) \ ENTRYBOOL(BOX64_ALLOWMISSINGLIBS, allow_missing_libs) \ ENTRYBOOL(BOX64_PREFER_WRAPPED, box64_prefer_wrapped) \ -- cgit 1.4.1 From 72119ddfa449bdfc98c7152653047f34feca332c Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sun, 5 Mar 2023 11:48:48 +0100 Subject: Added automatic detection of libcef (will help zoon #510, #451, #302 and probably other too) --- docs/USAGE.md | 5 +++++ src/include/debug.h | 1 + src/librarian/library.c | 4 ++++ src/main.c | 10 ++++++++++ src/tools/rcfile.c | 1 + 5 files changed, 21 insertions(+) (limited to 'src/include/debug.h') diff --git a/docs/USAGE.md b/docs/USAGE.md index 9000da1a..cc95735d 100755 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -202,6 +202,11 @@ Handling of x87 80bits long double * 0 : Try to handle 80bits long double as precise as possible (Default) * 1 : Handle them as double +#### BOX64_LIBCEF * +Detect libcef and apply malloc_hack settings +* 0 : Don't detect libcef +* 1 : Detect libcef, and apply MALLOC_HACK=2 if detected (Default) + #### BOX64_LIBGL * * libXXXX set the name for libGL (defaults to libGL.so.1). * /PATH/TO/libGLXXX : Sets the name and path for libGL diff --git a/src/include/debug.h b/src/include/debug.h index f4461243..e2e75ee1 100755 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -33,6 +33,7 @@ extern int arm64_crc32; extern int arm64_atomics; #endif #endif +extern int box64_libcef; extern int dlsym_error; // log dlsym error extern int cycle_log; // if using rolling logs #ifdef HAVE_TRACE diff --git a/src/librarian/library.c b/src/librarian/library.c index 3cfb2bee..48919220 100755 --- a/src/librarian/library.c +++ b/src/librarian/library.c @@ -306,6 +306,10 @@ static int loadEmulatedLib(const char* libname, library_t *lib, box64context_t* box64_dynarec_strongmem = 1; } #endif + if(libname && box64_libcef && strstr(libname, "libcef.so")) { + printf_log(LOG_INFO, "libcef detected, using malloc_hack_2\n"); + box64_malloc_hack = 2; + } return 1; } return 0; diff --git a/src/main.c b/src/main.c index e6c29568..20e5bd35 100755 --- a/src/main.c +++ b/src/main.c @@ -73,6 +73,7 @@ int arm64_atomics = 0; #else //DYNAREC int box64_dynarec = 0; #endif +int box64_libcef = 1; int dlsym_error = 0; int cycle_log = 0; #ifdef HAVE_TRACE @@ -627,6 +628,15 @@ void LoadLogEnv() #endif #endif // Other BOX64 env. var. + p = getenv("BOX64_LIBCEF"); + if(p) { + if(strlen(p)==1) { + if(p[0]>='0' && p[0]<='1') + box64_libcef = p[0]-'0'; + } + if(!box64_libcef) + printf_log(LOG_INFO, "Dynarec will not detect libcef\n"); + } p = getenv("BOX64_LOAD_ADDR"); if(p) { if(sscanf(p, "0x%zx", &box64_load_addr)!=1) diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c index b21b6e9d..ff4eb754 100644 --- a/src/tools/rcfile.c +++ b/src/tools/rcfile.c @@ -79,6 +79,7 @@ ENTRYSTRING_(BOX64_BASH, bash) \ ENTRYINT(BOX64_JITGDB, jit_gdb, 0, 2, 2) \ ENTRYBOOL(BOX64_NOSANDBOX, box64_nosandbox) \ ENTRYBOOL(BOX64_EXIT, want_exit) \ +ENTRYBOOL(BOX64_LIBCEF, box64_libcef) \ ENTRYINT(BOX64_MALLOC_HACK, box64_malloc_hack, 0, 2, 2) \ #ifdef HAVE_TRACE -- cgit 1.4.1