[pypy-svn] pypy default: Don't call libc for isnan, just implement it directly.

alex_gaynor commits-noreply at bitbucket.org
Sun Apr 10 01:35:08 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r43267:fbf29f3a8642
Date: 2011-04-09 19:34 -0400
http://bitbucket.org/pypy/pypy/changeset/fbf29f3a8642/

Log:	Don't call libc for isnan, just implement it directly.

diff --git a/pypy/translator/c/src/ll_math.h b/pypy/translator/c/src/ll_math.h
--- a/pypy/translator/c/src/ll_math.h
+++ b/pypy/translator/c/src/ll_math.h
@@ -2,7 +2,6 @@
    that don't implement these functions already. */
 
 int _pypy_math_isinf(double x);
-int _pypy_math_isnan(double x);
 
 double _pypy_math_acosh(double x);
 double _pypy_math_asinh(double x);

diff --git a/pypy/translator/c/src/ll_math.c b/pypy/translator/c/src/ll_math.c
--- a/pypy/translator/c/src/ll_math.c
+++ b/pypy/translator/c/src/ll_math.c
@@ -28,12 +28,6 @@
     return PyPy_IS_INFINITY(x);
 }
 
-int
-_pypy_math_isnan(double x)
-{
-    return PyPy_IS_NAN(x);
-}
-
 /* The following copyright notice applies to the original
    implementations of acosh, asinh and atanh. */
 

diff --git a/pypy/rpython/lltypesystem/module/ll_math.py b/pypy/rpython/lltypesystem/module/ll_math.py
--- a/pypy/rpython/lltypesystem/module/ll_math.py
+++ b/pypy/rpython/lltypesystem/module/ll_math.py
@@ -21,7 +21,7 @@
         export_symbols=['_pypy_math_acosh', '_pypy_math_asinh',
                         '_pypy_math_atanh',
                         '_pypy_math_expm1', '_pypy_math_log1p',
-                        '_pypy_math_isinf', '_pypy_math_isnan'],
+                        '_pypy_math_isinf'],
         )
     math_prefix = '_pypy_math_'
 else:
@@ -58,7 +58,6 @@
 math_hypot = llexternal(underscore + 'hypot',
                         [rffi.DOUBLE, rffi.DOUBLE], rffi.DOUBLE)
 math_isinf = math_llexternal('isinf', [rffi.DOUBLE], rffi.INT)
-math_isnan = math_llexternal('isnan', [rffi.DOUBLE], rffi.INT)
 
 # ____________________________________________________________
 #
@@ -91,9 +90,10 @@
 #
 # Custom implementations
 
- at jit.purefunction
 def ll_math_isnan(y):
-    return bool(math_isnan(y))
+    # By not calling into the extenal function the JIT can inline this.  Floats
+    # are awesome.
+    return y != y
 
 @jit.purefunction
 def ll_math_isinf(y):


More information about the Pypy-commit mailing list