[Python-checkins] r68296 - in python/trunk: configure configure.in pyconfig.h.in

mark.dickinson python-checkins at python.org
Sun Jan 4 13:29:37 CET 2009


Author: mark.dickinson
Date: Sun Jan  4 13:29:36 2009
New Revision: 68296

Log:
Add autoconf test to detect x87-style double rounding, as described in
issue #2937.  This information can be helpful for diagnosing platform-
specific problems in math and cmath.  The result of the test also
serves as a fairly reliable indicator of whether the x87 floating-point
instructions (as opposed to SSE2) are in use on Intel x86/x86_64 systems.


Modified:
   python/trunk/configure
   python/trunk/configure.in
   python/trunk/pyconfig.h.in

Modified: python/trunk/configure
==============================================================================
--- python/trunk/configure	(original)
+++ python/trunk/configure	Sun Jan  4 13:29:36 2009
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 67463 .
+# From configure.in Revision: 68292 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 2.7.
 #
@@ -2256,7 +2256,7 @@
 if test "${with_gcc+set}" = set; then
   withval=$with_gcc;
 	case $withval in
-	no)	CC=cc
+	no)	CC=${CC:-cc}
 		without_gcc=yes;;
 	yes)	CC=gcc
 		without_gcc=no;;
@@ -21523,6 +21523,94 @@
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
+# Detect whether system arithmetic is subject to x87-style double
+# rounding issues.  The result of this test has little meaning on non
+# IEEE 754 platforms.  On IEEE 754, test should return 1 if rounding
+# mode is round-to-nearest and double rounding issues are present, and
+# 0 otherwise.  See http://bugs.python.org/issue2937 for more info.
+{ echo "$as_me:$LINENO: checking for x87-style double rounding" >&5
+echo $ECHO_N "checking for x87-style double rounding... $ECHO_C" >&6; }
+if test "${ac_cv_x87_double_rounding+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+if test "$cross_compiling" = yes; then
+  ac_cv_x87_double_rounding=no
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+#include <stdlib.h>
+#include <math.h>
+int main() {
+    volatile double x, y, z;
+    /* 1./(1-2**-53) -> 1+2**-52 (correct), 1.0 (double rounding) */
+    x = 0.99999999999999989; /* 1-2**-53 */
+    y = 1./x;
+    if (y != 1.)
+        exit(0);
+    /* 1e16+2.99999 -> 1e16+2. (correct), 1e16+4. (double rounding) */
+    x = 1e16;
+    y = 2.99999;
+    z = x + y;
+    if (z != 1e16+4.)
+        exit(0);
+    /* both tests show evidence of double rounding */
+    exit(1);
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_x87_double_rounding=no
+else
+  echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_x87_double_rounding=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+fi
+
+{ echo "$as_me:$LINENO: result: $ac_cv_x87_double_rounding" >&5
+echo "${ECHO_T}$ac_cv_x87_double_rounding" >&6; }
+if test "$ac_cv_x87_double_rounding" = yes
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define X87_DOUBLE_ROUNDING 1
+_ACEOF
+
+fi
+
+
 # On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
 # -0. on some architectures.
 { echo "$as_me:$LINENO: checking whether tanh preserves the sign of zero" >&5

Modified: python/trunk/configure.in
==============================================================================
--- python/trunk/configure.in	(original)
+++ python/trunk/configure.in	Sun Jan  4 13:29:36 2009
@@ -3143,6 +3143,44 @@
 LIBS_SAVE=$LIBS
 LIBS="$LIBS $LIBM"
 
+# Detect whether system arithmetic is subject to x87-style double
+# rounding issues.  The result of this test has little meaning on non
+# IEEE 754 platforms.  On IEEE 754, test should return 1 if rounding
+# mode is round-to-nearest and double rounding issues are present, and
+# 0 otherwise.  See http://bugs.python.org/issue2937 for more info.
+AC_MSG_CHECKING(for x87-style double rounding)
+AC_CACHE_VAL(ac_cv_x87_double_rounding, [
+AC_TRY_RUN([
+#include <stdlib.h>
+#include <math.h>
+int main() {
+    volatile double x, y, z;
+    /* 1./(1-2**-53) -> 1+2**-52 (correct), 1.0 (double rounding) */
+    x = 0.99999999999999989; /* 1-2**-53 */
+    y = 1./x;
+    if (y != 1.)
+        exit(0);
+    /* 1e16+2.99999 -> 1e16+2. (correct), 1e16+4. (double rounding) */
+    x = 1e16;
+    y = 2.99999;
+    z = x + y;
+    if (z != 1e16+4.)
+        exit(0);
+    /* both tests show evidence of double rounding */
+    exit(1);
+}
+],
+ac_cv_x87_double_rounding=no,
+ac_cv_x87_double_rounding=yes,
+ac_cv_x87_double_rounding=no)])
+AC_MSG_RESULT($ac_cv_x87_double_rounding)
+if test "$ac_cv_x87_double_rounding" = yes
+then
+  AC_DEFINE(X87_DOUBLE_ROUNDING, 1,
+  [Define if arithmetic is subject to x87-style double rounding issue])
+fi
+
+
 # On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of
 # -0. on some architectures.
 AC_MSG_CHECKING(whether tanh preserves the sign of zero)

Modified: python/trunk/pyconfig.h.in
==============================================================================
--- python/trunk/pyconfig.h.in	(original)
+++ python/trunk/pyconfig.h.in	Sun Jan  4 13:29:36 2009
@@ -983,6 +983,9 @@
    first (like Motorola and SPARC, unlike Intel and VAX). */
 #undef WORDS_BIGENDIAN
 
+/* Define if arithmetic is subject to x87-style double rounding issue */
+#undef X87_DOUBLE_ROUNDING
+
 /* Define to 1 if on AIX 3.
    System headers sometimes define this.
    We just want to avoid a redefinition error message.  */


More information about the Python-checkins mailing list