[Python-checkins] cpython (2.7): #21167: Fix definition of NAN when ICC used without -fp-model strict.

r.david.murray python-checkins at python.org
Thu Aug 13 16:09:47 CEST 2015


https://hg.python.org/cpython/rev/d9c85b6bab3a
changeset:   97365:d9c85b6bab3a
branch:      2.7
parent:      97340:089f1a23dfac
user:        R David Murray <rdmurray at bitdance.com>
date:        Thu Aug 13 09:48:35 2015 -0400
summary:
  #21167: Fix definition of NAN when ICC used without -fp-model strict.

Patch from Chris Hogan of Intel, reviewed by Mark Dickinson.

files:
  Include/pymath.h |  24 +++++++++++++++++++++++-
  Misc/ACKS        |   1 +
  Misc/NEWS        |   3 +++
  3 files changed, 27 insertions(+), 1 deletions(-)


diff --git a/Include/pymath.h b/Include/pymath.h
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -152,7 +152,29 @@
  * doesn't support NaNs.
  */
 #if !defined(Py_NAN) && !defined(Py_NO_NAN)
-#define Py_NAN (Py_HUGE_VAL * 0.)
+#if !defined(__INTEL_COMPILER)
+    #define Py_NAN (Py_HUGE_VAL * 0.)
+#else /* __INTEL_COMPILER */
+    #if defined(ICC_NAN_STRICT)
+        #pragma float_control(push)
+        #pragma float_control(precise, on)
+        #pragma float_control(except,  on)
+        #if defined(_MSC_VER)
+            __declspec(noinline)
+        #else /* Linux */
+            __attribute__((noinline))
+        #endif /* _MSC_VER */
+        static double __icc_nan()
+        {
+            return sqrt(-1.0);
+        }
+        #pragma float_control (pop)
+        #define Py_NAN __icc_nan()
+    #else /* ICC_NAN_RELAXED as default for Intel Compiler */
+        static union { unsigned char buf[8]; double __icc_nan; } __nan_store = {0,0,0,0,0,0,0xf8,0x7f};
+        #define Py_NAN (__nan_store.__icc_nan)
+    #endif /* ICC_NAN_STRICT */
+#endif /* __INTEL_COMPILER */
 #endif
 
 /* Py_OVERFLOWED(X)
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -573,6 +573,7 @@
 Chris Hoffman
 Stefan Hoffmeister
 Albert Hofkamp
+Chris Hogan
 Tomas Hoger
 Jonathan Hogg
 Kamilla Holanda
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #21167: NAN operations are now handled correctly when python is
+  compiled with ICC even if -fp-model strict is not specified.
+
 - Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
   object now always allocates place for trailing null byte and it's buffer now
   is always null-terminated.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list