在 2024-10-21 19:11, LIU Hao 写道:
BTW, affected functions seem to be available in modern msvcrt (msvcr120 and UCRT), so another solution for the bug would be to move those function out of mingwex and use implementation provided by OS when possible.I can take a look later.
Attached is a patch for skipping the run-time check where SSE must exist, for example, on Pentium 3 or on x86-64.
The Microsoft implementation can't be used, as explained in e5d1fe451b81db3134d7ba70ff39d0a1b6c91b36. -- Best regards, LIU Hao
From 0e0c88e0843288672b50e95b2c90f1de4cb38ffc Mon Sep 17 00:00:00 2001 From: LIU Hao <[email protected]> Date: Mon, 21 Oct 2024 22:41:49 +0800 Subject: [PATCH] crt: Skip SSE detection if target support is implied Signed-off-by: LIU Hao <[email protected]> --- mingw-w64-crt/misc/feclearexcept.c | 2 ++ mingw-w64-crt/misc/fegetenv.c | 2 ++ mingw-w64-crt/misc/fegetexceptflag.c | 2 ++ mingw-w64-crt/misc/fesetenv.c | 5 ++++- mingw-w64-crt/misc/fesetexceptflag.c | 2 ++ mingw-w64-crt/misc/fesetround.c | 2 ++ mingw-w64-crt/misc/fetestexcept.c | 2 ++ 7 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mingw-w64-crt/misc/feclearexcept.c b/mingw-w64-crt/misc/feclearexcept.c index e0cd651fa..fe8df9ca8 100644 --- a/mingw-w64-crt/misc/feclearexcept.c +++ b/mingw-w64-crt/misc/feclearexcept.c @@ -69,7 +69,9 @@ int feclearexcept (int excepts) _env.__status_word &= ~(excepts & FE_ALL_EXCEPT); __asm__ volatile ("fldenv %0" : : "m" (_env)); } +# ifndef __SSE__ if (__mingw_has_sse ()) +# endif { __asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr)); _mxcsr &= ~(((excepts & FE_ALL_EXCEPT))); diff --git a/mingw-w64-crt/misc/fegetenv.c b/mingw-w64-crt/misc/fegetenv.c index 31960816e..aa01959b3 100644 --- a/mingw-w64-crt/misc/fegetenv.c +++ b/mingw-w64-crt/misc/fegetenv.c @@ -26,7 +26,9 @@ int fegetenv (fenv_t * envp) /* fnstenv sets control word to non-stop for all exceptions, so we need to reload our env to restore the original mask. */ __asm__ __volatile__ ("fldenv %0" : : "m" (*envp)); +# ifndef __SSE__ if (__mingw_has_sse ()) +# endif { int _mxcsr; __asm__ __volatile__ ("stmxcsr %0" : "=m" (_mxcsr)); diff --git a/mingw-w64-crt/misc/fegetexceptflag.c b/mingw-w64-crt/misc/fegetexceptflag.c index eaa940a2a..3380ecfe1 100644 --- a/mingw-w64-crt/misc/fegetexceptflag.c +++ b/mingw-w64-crt/misc/fegetexceptflag.c @@ -30,7 +30,9 @@ int fegetexceptflag (fexcept_t * flagp, int excepts) __asm__ volatile ("fnstsw %0" : "=am" (_status)); _mxcsr = 0; +# ifndef __SSE__ if (__mingw_has_sse ()) +# endif __asm__ volatile ("stmxcsr %0" : "=m" (_mxcsr)); *flagp = (_mxcsr | _status) & excepts & FE_ALL_EXCEPT; diff --git a/mingw-w64-crt/misc/fesetenv.c b/mingw-w64-crt/misc/fesetenv.c index a3279bddd..873d34145 100644 --- a/mingw-w64-crt/misc/fesetenv.c +++ b/mingw-w64-crt/misc/fesetenv.c @@ -65,8 +65,11 @@ int fesetenv (const fenv_t * envp) else { fenv_t env = *envp; - int has_sse = __mingw_has_sse (); + int has_sse = 1; int _mxcsr; +# ifndef __SSE__ + has_sse = __mingw_has_sse (); +# endif /*_mxcsr = ((int)envp->__unused0 << 16) | (int)envp->__unused1; *//* mxcsr low and high */ if (has_sse) __asm__ ("stmxcsr %0" : "=m" (*&_mxcsr)); diff --git a/mingw-w64-crt/misc/fesetexceptflag.c b/mingw-w64-crt/misc/fesetexceptflag.c index 7e3361c6a..a5647ac08 100644 --- a/mingw-w64-crt/misc/fesetexceptflag.c +++ b/mingw-w64-crt/misc/fesetexceptflag.c @@ -42,7 +42,9 @@ int fesetexceptflag (const fexcept_t * flagp, int excepts) _env.__status_word |= (*flagp & excepts); __asm__ volatile ("fldenv %0;" : : "m" (_env)); +# ifndef __SSE__ if (__mingw_has_sse ()) +# endif { int sse_cw; __asm__ volatile ("stmxcsr %0;" : "=m" (sse_cw)); diff --git a/mingw-w64-crt/misc/fesetround.c b/mingw-w64-crt/misc/fesetround.c index 624a9997d..d1c36796e 100644 --- a/mingw-w64-crt/misc/fesetround.c +++ b/mingw-w64-crt/misc/fesetround.c @@ -43,7 +43,9 @@ int fesetround (int mode) _cw |= mode; __asm__ volatile ("fldcw %0;" : : "m" (*&_cw)); +# ifndef __SSE__ if (__mingw_has_sse ()) +# endif { int mxcsr; diff --git a/mingw-w64-crt/misc/fetestexcept.c b/mingw-w64-crt/misc/fetestexcept.c index da073e6d0..f5850fac8 100644 --- a/mingw-w64-crt/misc/fetestexcept.c +++ b/mingw-w64-crt/misc/fetestexcept.c @@ -32,7 +32,9 @@ int fetestexcept (int excepts) unsigned short _sw; __asm__ __volatile__ ("fnstsw %%ax" : "=a" (_sw)); +# ifndef __SSE__ if (__mingw_has_sse ()) +# endif { int sse_sw; __asm__ __volatile__ ("stmxcsr %0;" : "=m" (sse_sw)); -- 2.47.0
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
