@@ -557,6 +557,30 @@ extern "C" {
557557 _Py_set_387controlword(old_387controlword)
558558#endif
559559
560+ /* get and set x87 control word for VisualStudio/x86 */
561+ #if defined(_MSC_VER ) && !defined(_WIN64 ) /* x87 not supported in 64-bit */
562+ #define HAVE_PY_SET_53BIT_PRECISION 1
563+ #define _Py_SET_53BIT_PRECISION_HEADER \
564+ unsigned int old_387controlword, new_387controlword, out_387controlword
565+ /* We use the __control87_2 function to set only the x87 control word.
566+ The SSE control word is unaffected. */
567+ #define _Py_SET_53BIT_PRECISION_START \
568+ do { \
569+ __control87_2(0, 0, &old_387controlword, NULL); \
570+ new_387controlword = \
571+ (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
572+ if (new_387controlword != old_387controlword) \
573+ __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
574+ &out_387controlword, NULL); \
575+ } while (0)
576+ #define _Py_SET_53BIT_PRECISION_END \
577+ do { \
578+ if (new_387controlword != old_387controlword) \
579+ __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
580+ &out_387controlword, NULL); \
581+ } while (0)
582+ #endif
583+
560584/* default definitions are empty */
561585#ifndef HAVE_PY_SET_53BIT_PRECISION
562586#define _Py_SET_53BIT_PRECISION_HEADER
0 commit comments