CRT function _fpreset() on x86-64 does not touch the x87 FPU unit all.
So reset x87 FPU unit manually via fninit instruction and then change
the default precision from 64-bit to 53-bit.
---
 mingw-w64-crt/crt/CRT_fp8.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/mingw-w64-crt/crt/CRT_fp8.c b/mingw-w64-crt/crt/CRT_fp8.c
index a7d3a979424b..d355694e3309 100644
--- a/mingw-w64-crt/crt/CRT_fp8.c
+++ b/mingw-w64-crt/crt/CRT_fp8.c
@@ -12,6 +12,20 @@ void _fpreset (void);
 void _fpreset (void)
 {
   (* __MINGW_IMP_SYMBOL(_fpreset))();
+#if defined(__i386__)
+  /* msvcrt _fpreset() on i386 changes the x87 precision to 53-bit,
+   * so no change is needed */
+#elif defined(__x86_64__)
+  /* msvcrt _fpreset() on x86-64 does not touch the x87 FPU unit all,
+   * so reset it now and change the default precision to 53-bit */
+  unsigned short cw_53bit = 0x027F;
+  __asm__ __volatile__ (
+    "fninit\n\t"
+    "fldcw %0"
+    :
+    : "m" (cw_53bit)
+  );
+#endif
 }
 
 #ifdef __GNUC__
-- 
2.20.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to