summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-04-15 14:10:56 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2012-04-15 14:10:56 (GMT)
commit18e3d81f96a592a0307fa41645017483eabcfc51 (patch)
tree85d50abaaa693043cf0b9399b5bee91a48979d48 /Include/pyport.h
parent473fde60dc5cfbd5f41e462c587b08c10ce51764 (diff)
downloadcpython-18e3d81f96a592a0307fa41645017483eabcfc51.zip
cpython-18e3d81f96a592a0307fa41645017483eabcfc51.tar.gz
cpython-18e3d81f96a592a0307fa41645017483eabcfc51.tar.bz2
Issue #13889: On MSVC builds, set FPU control word at runtime for all string <-> float conversions. Patch by Samuel Iseli and Stefan Krah.
Diffstat (limited to 'Include/pyport.h')
-rw-r--r--Include/pyport.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index 269ba68..4ef0db2 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -557,6 +557,30 @@ extern "C" {
_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, out_387controlword
+/* We use the __control87_2 function to set only the x87 control word.
+ The SSE control word is unaffected. */
+#define _Py_SET_53BIT_PRECISION_START \
+ do { \
+ __control87_2(0, 0, &old_387controlword, NULL); \
+ new_387controlword = \
+ (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
+ if (new_387controlword != old_387controlword) \
+ __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
+ &out_387controlword, NULL); \
+ } while (0)
+#define _Py_SET_53BIT_PRECISION_END \
+ do { \
+ if (new_387controlword != old_387controlword) \
+ __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
+ &out_387controlword, NULL); \
+ } while (0)
+#endif
+
/* default definitions are empty */
#ifndef HAVE_PY_SET_53BIT_PRECISION
#define _Py_SET_53BIT_PRECISION_HEADER