diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -557,6 +557,28 @@ _Py_set_387controlword(old_387controlword) #endif +/* get and set x87 control word for VisualStudio/x86 */ +#if defined(_MSC_VER) && !defined(_WIN64) /* x87 not supported in 64-bit */ +#define HAVE_PY_SET_53BIT_PRECISION 1 +#define _Py_SET_53BIT_PRECISION_HEADER \ + unsigned int old_387controlword, new_387controlword +/* We are using the __control87_2 function to set only the x87 controlword. + SSE controlword is unaffected. */ +#define _Py_SET_53BIT_PRECISION_START \ + do { \ + __control87_2(0, 0, &old_387controlword, NULL); \ + new_387controlword = \ + (old_387controlword&(_MCW_DN|_MCW_EM|_MCW_IC)) | (_PC_53|_RC_NEAR); \ + if (new_387controlword != old_387controlword) \ + __control87_2(_PC_53|_RC_NEAR, _MCW_PC|_MCW_RC, \ + &new_387controlword, NULL); \ + } while (0) +#define _Py_SET_53BIT_PRECISION_END \ + if (new_387controlword != old_387controlword) \ + __control87_2(old_387controlword, _MCW_PC|_MCW_RC, \ + &new_387controlword, NULL) +#endif + /* default definitions are empty */ #ifndef HAVE_PY_SET_53BIT_PRECISION #define _Py_SET_53BIT_PRECISION_HEADER