This speeds up all floating-point rounding and exception functions by only querying cpuid once and storing its result. This helps when such functions are repeatedly called. This fixes https://sourceforge.net/p/mingw-w64/bugs/995/ .
Signed-off-by: Moritz Bender <[email protected]> --- diff --git a/mingw-w64-crt/misc/feclearexcept.c b/mingw-w64-crt/misc/feclearexcept.c index 673528b20..259809d58 100644 --- a/mingw-w64-crt/misc/feclearexcept.c +++ b/mingw-w64-crt/misc/feclearexcept.c @@ -7,9 +7,13 @@ #if !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)) int __mingw_has_sse (void); +static int __has_sse = -1; int __mingw_has_sse(void) { + if (__has_sse != -1) + return __has_sse; + int cpuInfo[4],infoType = 1; #ifndef _WIN64 @@ -19,8 +23,11 @@ int __mingw_has_sse(void) n_flag = o_flag ^ 0x200000; __asm__ volatile ("pushl %0\n\tpopfl" : : "g" (n_flag)); __asm__ volatile ("pushfl\n\tpopl %0" : "=mr" (n_flag)); - if (n_flag == o_flag) - return 0; + if (n_flag == o_flag) + { + __has_sse = 0; + return __has_sse; + } #endif __asm__ __volatile__ ( @@ -28,9 +35,8 @@ int __mingw_has_sse(void) : "=a" (cpuInfo[0]), "=b" (cpuInfo[1]), "=c" (cpuInfo[2]), "=d" (cpuInfo[3]) : "a" (infoType)); - if (cpuInfo[3] & 0x2000000) - return 1; - return 0; + __has_sse = (cpuInfo[3] & 0x2000000); + return __has_sse; } #endif /* !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)) */ _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
