From 074be933ad50addc0f8fc370a0b302534cbea5a7 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 29 Sep 2023 15:15:13 +0200 Subject: [PATCH 1/5] remove asm FixedDiv and FixedMul functions DIE! --- src/m_fixed.c | 44 ---------------- src/m_fixed.h | 135 ++++++++------------------------------------------ 2 files changed, 22 insertions(+), 157 deletions(-) diff --git a/src/m_fixed.c b/src/m_fixed.c index 3724144f7..2da72fe05 100644 --- a/src/m_fixed.c +++ b/src/m_fixed.c @@ -23,50 +23,6 @@ #include "m_fixed.h" #include "tables.h" // ANGLETOFINESHIFT -#ifdef __USE_C_FIXEDMUL__ - -/** \brief The FixedMul function - - \param a fixed_t number - \param b fixed_t number - - \return a*b>>FRACBITS - -*/ -fixed_t FixedMul(fixed_t a, fixed_t b) -{ - // Need to cast to unsigned before shifting to avoid undefined behaviour - // for negative integers - return (fixed_t)(((UINT64)((INT64)a * b)) >> FRACBITS); -} - -#endif //__USE_C_FIXEDMUL__ - -#ifdef __USE_C_FIXEDDIV__ -/** \brief The FixedDiv2 function - - \param a fixed_t number - \param b fixed_t number - - \return a/b * FRACUNIT - -*/ -fixed_t FixedDiv2(fixed_t a, fixed_t b) -{ - INT64 ret; - - if (b == 0) - I_Error("FixedDiv: divide by zero"); - - ret = (((INT64)a * FRACUNIT)) / b; - - if ((ret > INT32_MAX) || (ret < INT32_MIN)) - I_Error("FixedDiv: divide by zero"); - return (fixed_t)ret; -} - -#endif // __USE_C_FIXEDDIV__ - fixed_t FixedSqrt(fixed_t x) { #ifdef HAVE_SQRT diff --git a/src/m_fixed.h b/src/m_fixed.h index 5ae029fc4..e64c9e0d4 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -62,126 +62,35 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FloatToFixed(float f) #define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT)) -#if defined (__WATCOMC__) && FRACBITS == 16 - #pragma aux FixedMul = \ - "imul ebx", \ - "shrd eax,edx,16" \ - parm [eax] [ebx] \ - value [eax] \ - modify exact [eax edx] +/** \brief The FixedMul function - #pragma aux FixedDiv2 = \ - "cdq", \ - "shld edx,eax,16", \ - "sal eax,16", \ - "idiv ebx" \ - parm [eax] [ebx] \ - value [eax] \ - modify exact [eax edx] -#elif defined (__GNUC__) && defined (__i386__) && !defined (NOASM) - // DJGPP, i386 linux, cygwin or mingw - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // asm - { - fixed_t ret; - asm - ( - "imull %2;" // a*b - "shrdl %3,%%edx,%0;" // shift logical right FRACBITS bits - :"=a" (ret) // eax is always the result and the first operand (%0,%1) - :"0" (a), "r" (b) // and %2 is what we use imull on with what in %1 - , "I" (FRACBITS) // %3 holds FRACBITS (normally 16) - :"cc", "%edx" // edx and condition codes clobbered - ); - return ret; - } + \param a fixed_t number + \param b fixed_t number - FUNCMATH FUNCINLINE static inline fixed_t FixedDiv2(fixed_t a, fixed_t b) - { - fixed_t ret; - asm - ( - "movl %1,%%edx;" // these two instructions allow the next two to pair, on the Pentium processor. - "sarl $31,%%edx;" // shift arithmetic right 31 on EDX - "shldl %3,%1,%%edx;" // DP shift logical left FRACBITS on EDX - "sall %3,%0;" // shift arithmetic left FRACBITS on EAX - "idivl %2;" // EDX/b = EAX - : "=a" (ret) - : "0" (a), "r" (b) - , "I" (FRACBITS) - : "%edx" - ); - return ret; - } -#elif defined (__GNUC__) && defined (__arm__) && !defined(__thumb__) && !defined(NOASM) //ARMv4 ASM - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // let abuse smull - { - fixed_t ret; - asm - ( - "smull %[lo], r1, %[a], %[b];" - "mov %[lo], %[lo], lsr %3;" - "orr %[lo], %[lo], r1, lsl %3;" - : [lo] "=&r" (ret) // rhi, rlo and rm must be distinct registers - : [a] "r" (a), [b] "r" (b) - , "i" (FRACBITS) - : "r1" - ); - return ret; - } + \return a*b>>FRACBITS - #define __USE_C_FIXEDDIV__ // no double or asm div in ARM land -#elif defined (__GNUC__) && defined (__ppc__) && !defined(NOASM) && 0 // WII: PPC CPU - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // asm - { - fixed_t ret, hi, lo; - asm - ( - "mullw %0, %2, %3;" - "mulhw %1, %2, %3" - : "=r" (hi), "=r" (lo) - : "r" (a), "r" (b) - , "I" (FRACBITS) - ); - ret = (INT64)((hi>>FRACBITS)+lo)<> FRACBITS); +} - #define __USE_C_FIXEDDIV__// Alam: I am lazy -#elif defined (__GNUC__) && defined (__mips__) && !defined(NOASM) && 0 // PSP: MIPS CPU - FUNCMATH FUNCINLINE static inline fixed_t FixedMul(fixed_t a, fixed_t b) // asm - { - fixed_t ret; - asm - ( - "mult %3, %4;" // a*b=h<32+l - : "=r" (ret), "=l" (a), "=h" (b) //todo: abuse shr opcode - : "0" (a), "r" (b) - , "I" (FRACBITS) - //: "+l", "+h" - ); - ret = (INT64)((a>>FRACBITS)+b)< Date: Fri, 29 Sep 2023 15:34:29 +0200 Subject: [PATCH 2/5] rip in pieces asm code this thing makes software crash so goddamn often, its useless nowadays anyways, and SRB2 removed it some time ago aswell https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2074?commit_id=7634a960314d5a576656cc4300a74caf889f8d7f --- SRB2.cbp | 18 - SRB2_common.props | 3 - Srb2.dev | 52 +- appveyor.yml | 8 - cmake/Modules/CMakeASM_YASMInformation.cmake | 46 - .../CMakeDetermineASM_YASMCompiler.cmake | 27 - cmake/Modules/CMakeTestASM_YASMCompiler.cmake | 23 - src/Android.mk | 2 +- src/CMakeLists.txt | 52 - src/Makefile | 33 - src/Makefile.cfg | 14 - src/asm_defs.inc | 43 - src/d_netcmd.c | 5 - src/p5prof.h | 278 --- src/r_draw.h | 14 - src/r_splats.c | 11 - src/screen.c | 31 - src/sdl/MakeCYG.cfg | 1 - src/sdl/MakeNIX.cfg | 1 - src/sdl/Makefile.cfg | 7 - src/sdl/i_main.c | 35 - src/tmap.s | 1587 ----------------- src/tmap_asm.s | 322 ---- src/tmap_mmx.nas | 674 ------- src/tmap_vc.nas | 48 - src/v_video.c | 11 - src/vid_copy.s | 61 - src/win32/Makefile.cfg | 4 - tools/anglechk.c | 1 - 29 files changed, 2 insertions(+), 3410 deletions(-) delete mode 100644 cmake/Modules/CMakeASM_YASMInformation.cmake delete mode 100644 cmake/Modules/CMakeDetermineASM_YASMCompiler.cmake delete mode 100644 cmake/Modules/CMakeTestASM_YASMCompiler.cmake delete mode 100644 src/asm_defs.inc delete mode 100644 src/p5prof.h delete mode 100644 src/tmap.s delete mode 100644 src/tmap_asm.s delete mode 100644 src/tmap_mmx.nas delete mode 100644 src/tmap_vc.nas delete mode 100644 src/vid_copy.s diff --git a/SRB2.cbp b/SRB2.cbp index acdc61c7f..b4cf543db 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -1996,24 +1996,6 @@ HW3SOUND for 3D hardware sound support