[pypy-svn] pypy jit-longlong: Work until the basic test_long_long passes.

arigo commits-noreply at bitbucket.org
Fri Jan 7 12:46:05 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: jit-longlong
Changeset: r40449:c22aee0cca12
Date: 2011-01-07 12:45 +0100
http://bitbucket.org/pypy/pypy/changeset/c22aee0cca12/

Log:	Work until the basic test_long_long passes.

diff --git a/pypy/jit/backend/llgraph/runner.py b/pypy/jit/backend/llgraph/runner.py
--- a/pypy/jit/backend/llgraph/runner.py
+++ b/pypy/jit/backend/llgraph/runner.py
@@ -86,6 +86,7 @@
 
 class BaseCPU(model.AbstractCPU):
     supports_floats = True
+    supports_longlong = True
 
     def __init__(self, rtyper, stats=None, opts=None,
                  translate_support_code=False,

diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -155,6 +155,7 @@
         if policy is None:
             policy = JitPolicy()
         policy.set_supports_floats(self.cpu.supports_floats)
+        policy.set_supports_longlong(self.cpu.supports_longlong)
         graphs = self.codewriter.find_all_graphs(policy)
         policy.dump_unsafe_loops()
         self.check_access_directly_sanity(graphs)

diff --git a/pypy/jit/backend/model.py b/pypy/jit/backend/model.py
--- a/pypy/jit/backend/model.py
+++ b/pypy/jit/backend/model.py
@@ -4,6 +4,11 @@
 
 class AbstractCPU(object):
     supports_floats = False
+    supports_longlong = False
+    # ^^^ This is only useful on 32-bit platforms.  If True,
+    # longlongs are supported by the JIT, but stored as doubles.
+    # Boxes and Consts are BoxFloats and ConstFloats.
+
     done_with_this_frame_void_v = -1
     done_with_this_frame_int_v = -1
     done_with_this_frame_ref_v = -1

diff --git a/pypy/jit/codewriter/test/test_longlong.py b/pypy/jit/codewriter/test/test_longlong.py
--- a/pypy/jit/codewriter/test/test_longlong.py
+++ b/pypy/jit/codewriter/test/test_longlong.py
@@ -22,8 +22,8 @@
         return False
 
 class FakeCPU:
+    supports_longlong = True
     def __init__(self):
-        self.supports_longlong = []
         self.rtyper = FakeRTyper()
 
 

diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py
--- a/pypy/jit/codewriter/jtransform.py
+++ b/pypy/jit/codewriter/jtransform.py
@@ -424,6 +424,15 @@
     rewrite_op_int_mod_zer     = _do_builtin_call
     rewrite_op_int_lshift_ovf  = _do_builtin_call
     rewrite_op_int_abs         = _do_builtin_call
+    rewrite_op_llong_abs          = _do_builtin_call
+    rewrite_op_llong_floordiv     = _do_builtin_call
+    rewrite_op_llong_floordiv_zer = _do_builtin_call
+    rewrite_op_llong_mod          = _do_builtin_call
+    rewrite_op_llong_mod_zer      = _do_builtin_call
+    rewrite_op_ullong_floordiv     = _do_builtin_call
+    rewrite_op_ullong_floordiv_zer = _do_builtin_call
+    rewrite_op_ullong_mod          = _do_builtin_call
+    rewrite_op_ullong_mod_zer      = _do_builtin_call
     rewrite_op_gc_identityhash = _do_builtin_call
     rewrite_op_gc_id           = _do_builtin_call
 

diff --git a/pypy/jit/backend/llgraph/llimpl.py b/pypy/jit/backend/llgraph/llimpl.py
--- a/pypy/jit/backend/llgraph/llimpl.py
+++ b/pypy/jit/backend/llgraph/llimpl.py
@@ -23,12 +23,16 @@
 
 from pypy.rlib.objectmodel import ComputedIntSymbolic, we_are_translated
 from pypy.rlib.rarithmetic import ovfcheck
+from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, r_uint
+from pypy.rlib.longlong2float import longlong2float, float2longlong
 
 import py
 from pypy.tool.ansi_print import ansi_log
 log = py.log.Producer('runner')
 py.log.setconsumer('runner', ansi_log)
 
+IS_32_BIT = r_ulonglong is not r_uint
+
 
 def _from_opaque(opq):
     return opq._obj.externalobj
@@ -1071,14 +1075,26 @@
 def cast_from_ptr(TYPE, x):
     return lltype.cast_opaque_ptr(TYPE, x)
 
-def cast_to_float(x):      # not really a cast, just a type check
+def cast_to_float(x):
+    if isinstance(x, float):
+        return x      # common case
+    if IS_32_BIT:
+        if isinstance(x, r_longlong):
+            return longlong2float(x)
+        if isinstance(x, r_ulonglong):
+            return longlong2float(r_longlong(x))
+    raise TypeError(type(x))
+
+def cast_from_float(TYPE, x):
     assert isinstance(x, float)
-    return x
-
-def cast_from_float(TYPE, x):   # not really a cast, just a type check
-    assert TYPE is lltype.Float
-    assert isinstance(x, float)
-    return x
+    if TYPE is lltype.Float:
+        return x
+    if IS_32_BIT:
+        if TYPE is lltype.SignedLongLong:
+            return float2longlong(x)
+        if TYPE is lltype.UnsignedLongLong:
+            return r_ulonglong(float2longlong(x))
+    raise TypeError(TYPE)
 
 
 def new_frame(is_oo, cpu):
@@ -1518,7 +1534,9 @@
                     assert n == 'r'
                 x = argsiter_r.next()
                 x = cast_from_ptr(TYPE, x)
-            elif TYPE is lltype.Float:
+            elif TYPE is lltype.Float or (
+                    IS_32_BIT and TYPE in (lltype.SignedLongLong,
+                                           lltype.UnsignedLongLong)):
                 if args_in_order is not None:
                     n = orderiter.next()
                     assert n == 'f'

diff --git a/pypy/jit/metainterp/test/test_basic.py b/pypy/jit/metainterp/test/test_basic.py
--- a/pypy/jit/metainterp/test/test_basic.py
+++ b/pypy/jit/metainterp/test/test_basic.py
@@ -57,7 +57,9 @@
     cpu = CPUClass(rtyper, stats, None, False)
     cw = codewriter.CodeWriter(cpu, [FakeJitDriverSD()])
     testself.cw = cw
-    cw.find_all_graphs(JitPolicy())
+    policy = JitPolicy()
+    policy.set_supports_longlong(True)
+    cw.find_all_graphs(policy)
     #
     testself.warmrunnerstate = FakeWarmRunnerState()
     testself.warmrunnerstate.cpu = cpu
@@ -1263,17 +1265,18 @@
 
     def test_long_long(self):
         from pypy.rlib.rarithmetic import r_longlong, intmask
-        def g(n, m, o):
-            # This function should be completely marked as residual by
-            # codewriter.py on 32-bit platforms.  On 64-bit platforms,
-            # this function should be JITted and the test should pass too.
+        def g(n, m, o, p):
+            # On 64-bit platforms, long longs == longs.  On 32-bit platforms,
+            # this function should be either completely marked as residual
+            # (backends with supports_longlong==False), or be compiled as a
+            # sequence of residual calls.
             n = r_longlong(n)
             m = r_longlong(m)
-            return intmask((n*m) // o)
-        def f(n, m, o):
-            return g(n, m, o) // 3
-        res = self.interp_operations(f, [1000000000, 90, 91])
-        assert res == (1000000000 * 90 // 91) // 3
+            return intmask((n*m + p) // o)
+        def f(n, m, o, p):
+            return g(n, m, o, p) // 3
+        res = self.interp_operations(f, [1000000000, 90, 91, -17171])
+        assert res == ((1000000000 * 90 - 17171) // 91) // 3
 
     def test_free_object(self):
         import weakref

diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -20,7 +20,6 @@
 from pypy.jit.metainterp.typesystem import deref
 from pypy.rlib import rgc
 from pypy.rlib.rarithmetic import r_longlong, r_ulonglong, intmask
-from pypy.rlib.longlong2float import longlong2float, float2longlong
 
 def getargtypes(annotator, values):
     if values is None:    # for backend tests producing stand-alone exe's
@@ -192,7 +191,7 @@
 def _ll_2_int_floordiv_zer(x, y):
     if y == 0:
         raise ZeroDivisionError
-    return llop.int_floordiv_zer(lltype.Signed, x, y)
+    return llop.int_floordiv(lltype.Signed, x, y)
 
 def _ll_2_int_mod_ovf_zer(x, y):
     if y == 0:
@@ -227,136 +226,122 @@
 # long long support
 # -----------------
 
-def _ll_1_llong_is_true(xf):
-    x = float2longlong(xf)
-    return bool(x)
+def _ll_1_llong_is_true(xll):
+    return bool(xll)
 
-def _ll_1_llong_neg(x):
-    x = float2longlong(xf)
-    y = -x
-    return longlong2float(y)
+def _ll_1_llong_neg(xll):
+    return -xll
 
-def _ll_1_llong_invert(x):
-    x = float2longlong(xf)
-    y = ~x
-    return longlong2float(y)
+def _ll_1_llong_invert(xll):
+    return ~xll
 
-def _ll_2_llong_lt(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return x < y
+def _ll_2_llong_lt(xll, yll):
+    return xll < yll
 
-def _ll_2_llong_le(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return x <= y
+def _ll_2_llong_le(xll, yll):
+    return xll <= yll
 
-def _ll_2_llong_eq(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return x == y
+def _ll_2_llong_eq(xll, yll):
+    return xll == yll
 
-def _ll_2_llong_ne(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return x != y
+def _ll_2_llong_ne(xll, yll):
+    return xll != yll
 
-def _ll_2_llong_gt(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return x > y
+def _ll_2_llong_gt(xll, yll):
+    return xll > yll
 
-def _ll_2_llong_ge(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return x >= y
+def _ll_2_llong_ge(xll, yll):
+    return xll >= yll
 
-def _ll_2_llong_ult(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return r_ulonglong(x) < r_ulonglong(y)
+def _ll_2_llong_ult(xull, yull):
+    return xull < yull
 
-def _ll_2_llong_ule(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return r_ulonglong(x) <= r_ulonglong(y)
+def _ll_2_llong_ule(xull, yull):
+    return xull <= yull
 
-def _ll_2_llong_ugt(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return r_ulonglong(x) > r_ulonglong(y)
+def _ll_2_llong_ugt(xull, yull):
+    return xull > yull
 
-def _ll_2_llong_uge(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    return r_ulonglong(x) >= r_ulonglong(y)
+def _ll_2_llong_uge(xull, yull):
+    return xull >= yull
 
-def _ll_2_llong_add(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    z = x + y
-    return longlong2float(z)
+def _ll_2_llong_add(xll, yll):
+    return xll + yll
 
-def _ll_2_llong_sub(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    z = x - y
-    return longlong2float(z)
+def _ll_2_llong_sub(xll, yll):
+    return xll - yll
 
-def _ll_2_llong_mul(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    z = x * y
-    return longlong2float(z)
+def _ll_2_llong_mul(xll, yll):
+    return xll * yll
 
-def _ll_2_llong_and(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    z = x & y
-    return longlong2float(z)
+def _ll_2_llong_and(xll, yll):
+    return xll & yll
 
-def _ll_2_llong_or(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    z = x | y
-    return longlong2float(z)
+def _ll_2_llong_or(xll, yll):
+    return xll | yll
 
-def _ll_2_llong_xor(xf, yf):
-    x = float2longlong(xf)
-    y = float2longlong(yf)
-    z = x ^ y
-    return longlong2float(z)
+def _ll_2_llong_xor(xll, yll):
+    return xll ^ yll
 
-def _ll_2_llong_lshift(xf, y):
-    x = float2longlong(xf)
-    z = x << y
-    return longlong2float(z)
+def _ll_2_llong_lshift(xll, y):
+    return xll << y
 
-def _ll_2_llong_rshift(xf, y):
-    x = float2longlong(xf)
-    z = x >> y
-    return longlong2float(z)
+def _ll_2_llong_rshift(xll, y):
+    return xll >> y
 
-def _ll_2_llong_urshift(xf, y):
-    x = float2longlong(xf)
-    z = r_ulonglong(x) >> y
-    return longlong2float(r_longlong(z))
+def _ll_2_llong_urshift(xull, y):
+    return xull >> y
 
 def _ll_1_llong_from_int(x):
-    y = r_longlong(x)
-    return longlong2float(y)
+    return r_longlong(x)
 
-def _ll_1_llong_to_int(xf):
-    x = float2longlong(xf)
-    return intmask(x)
+def _ll_1_llong_to_int(xll):
+    return intmask(xll)
 
 def _ll_1_llong_from_float(xf):
-    y = r_longlong(xf)
-    return longlong2float(y)
+    return r_longlong(xf)
 
-def _ll_1_llong_to_float(xf):
-    x = float2longlong(xf)
-    return float(x)
+def _ll_1_llong_to_float(xll):
+    return float(xll)
+
+
+def _ll_1_llong_abs(xll):
+    if xll < 0:
+        return -xll
+    else:
+        return xll
+
+def _ll_2_llong_floordiv(xll, yll):
+    return llop.llong_floordiv(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_llong_floordiv_zer(xll, yll):
+    if yll == 0:
+        raise ZeroDivisionError
+    return llop.llong_floordiv(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_llong_mod(xll, yll):
+    return llop.llong_mod(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_llong_mod_zer(xll, yll):
+    if yll == 0:
+        raise ZeroDivisionError
+    return llop.llong_mod(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_ullong_floordiv(xll, yll):
+    return llop.ullong_floordiv(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_ullong_floordiv_zer(xll, yll):
+    if yll == 0:
+        raise ZeroDivisionError
+    return llop.ullong_floordiv(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_ullong_mod(xll, yll):
+    return llop.ullong_mod(lltype.SignedLongLong, xll, yll)
+
+def _ll_2_ullong_mod_zer(xll, yll):
+    if yll == 0:
+        raise ZeroDivisionError
+    return llop.ullong_mod(lltype.SignedLongLong, xll, yll)
 
 
 # libffi support


More information about the Pypy-commit mailing list