CRT_fp8.c _fpreset function is directly calling the msvcrt/UCRT library
_fpreset function via import symbol.
CRT_fp10.c _fpreset function is currently only calling the x87 fninit
instruction.
The msvcrt/UCRT _fpreset function for i386 builds is not only calling the
x87 fninit instruction but is doing also some other work, like setting SSE
registers or recovering from state when the function was called from the
SIGFPE signal handler (which is begin called from SEH exception filter
dispatcher). For x86-64 builds it not touching the x87 FPU unit at all.
So change the CRT_fp10.c _fpreset function function to call also the
original msvcrt/UCRT _fpreset function and then change the x87 FPU to
10 bytes (64-bit precision).
Because CRT _fpreset on x86-64 is not touching the x86 FPU unit, it is
still needed for x86-64 builds to call the x87 fninit instruction (which
also resets the x87 FPU precision to 64-bit).
For i386 builds it is enough to just call CRT function _control87() to
change FPU precision to 64-bit.
---
mingw-w64-crt/crt/CRT_fp10.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/mingw-w64-crt/crt/CRT_fp10.c b/mingw-w64-crt/crt/CRT_fp10.c
index c8a8bfbeebcc..2d4899fc1ac7 100644
--- a/mingw-w64-crt/crt/CRT_fp10.c
+++ b/mingw-w64-crt/crt/CRT_fp10.c
@@ -4,14 +4,23 @@
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
+#include <_mingw.h>
+#include <float.h>
+
+extern void (* __MINGW_IMP_SYMBOL(_fpreset))(void);
void _fpreset (void);
void _fpreset (void)
{
-#ifdef __GNUC__
+ (* __MINGW_IMP_SYMBOL(_fpreset))();
+#if defined(__i386__)
+ /* msvcrt _fpreset() on i386 changes the x87 precision to 53-bit,
+ * so change it back to 64-bit */
+ _control87(_PC_64, _MCW_PC);
+#elif defined(__x86_64__)
+ /* msvcrt _fpreset() on x86-64 does not touch the x87 FPU unit all,
+ * so reset it now (the default precision after reset is 64-bit) */
__asm__ ("fninit");
-#else /* msvc: */
- __asm fninit;
#endif
}
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public