[pypy-svn] pypy default: Remove the calls to libc's isinf again, reimplement it ourselves so the JIT can inline it nicely. Algorithm taken fromboost.
alex_gaynor
commits-noreply at bitbucket.org
Thu Apr 14 20:44:37 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r43360:d8ea37b2a1ff
Date: 2011-04-14 18:44 +0000
http://bitbucket.org/pypy/pypy/changeset/d8ea37b2a1ff/
Log: Remove the calls to libc's isinf again, reimplement it ourselves so
the JIT can inline it nicely. Algorithm taken fromboost.
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
@@ -1,8 +1,6 @@
/* Definitions of some C99 math library functions, for those platforms
that don't implement these functions already. */
-int _pypy_math_isinf(double x);
-
double _pypy_math_acosh(double x);
double _pypy_math_asinh(double x);
double _pypy_math_atanh(double x);
diff --git a/pypy/rpython/lltypesystem/module/test/test_ll_math.py b/pypy/rpython/lltypesystem/module/test/test_ll_math.py
--- a/pypy/rpython/lltypesystem/module/test/test_ll_math.py
+++ b/pypy/rpython/lltypesystem/module/test/test_ll_math.py
@@ -3,6 +3,7 @@
from pypy.rpython.lltypesystem.module import ll_math
from pypy.module.math.test.test_direct import MathTests, get_tester
+from pypy.translator.c.test.test_genc import compile
class TestMath(MathTests):
@@ -21,6 +22,13 @@
assert ll_math.ll_math_isnan(nan)
assert not ll_math.ll_math_isnan(inf)
+ def test_compiled_isinf(self):
+ def f(x):
+ return ll_math.ll_math_isinf(1. / x)
+ f = compile(f, [float], backendopt=False)
+ assert f(5.5e-309)
+
+
def make_test_case((fnname, args, expected), dict):
#
def test_func(self):
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
@@ -22,12 +22,6 @@
#endif
#define PyPy_NAN (HUGE_VAL * 0.)
-int
-_pypy_math_isinf(double x)
-{
- return PyPy_IS_INFINITY(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
@@ -20,8 +20,7 @@
separate_module_files=[cdir.join('src', 'll_math.c')],
export_symbols=['_pypy_math_acosh', '_pypy_math_asinh',
'_pypy_math_atanh',
- '_pypy_math_expm1', '_pypy_math_log1p',
- '_pypy_math_isinf'],
+ '_pypy_math_expm1', '_pypy_math_log1p'],
)
math_prefix = '_pypy_math_'
else:
@@ -95,9 +94,9 @@
# are awesome.
return y != y
- at jit.purefunction
def ll_math_isinf(y):
- return bool(math_isinf(y))
+ # Use a bitwise OR so the JIT doesn't produce 2 different guards.
+ return (y == INFINITY) | (y == -INFINITY)
ll_math_copysign = math_copysign
More information about the Pypy-commit
mailing list