[pypy-svn] pypy jitypes2: make test_slonglong_args "mostly" passing with the jit: it fails when trying

antocuni commits-noreply at bitbucket.org
Tue Dec 21 17:22:50 CET 2010


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: jitypes2
Changeset: r40168:c4da81b326ca
Date: 2010-12-21 17:20 +0100
http://bitbucket.org/pypy/pypy/changeset/c4da81b326ca/

Log:	make test_slonglong_args "mostly" passing with the jit: it fails
	when trying to print some debug info, it will probably be fixed by
	rewriting longlong2float and float2longlong in C (which is a good
	idea anyway)

diff --git a/pypy/jit/metainterp/optimizeopt/fficall.py b/pypy/jit/metainterp/optimizeopt/fficall.py
--- a/pypy/jit/metainterp/optimizeopt/fficall.py
+++ b/pypy/jit/metainterp/optimizeopt/fficall.py
@@ -5,6 +5,8 @@
 from pypy.jit.metainterp.resoperation import rop, ResOperation
 from pypy.jit.metainterp.optimizeutil import _findall
 from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
+from pypy.jit.backend.llsupport.ffisupport import UnsupportedKind
+
 
 class FuncInfo(object):
 
@@ -18,7 +20,11 @@
         self.funcval = funcval
         self.opargs = []
         argtypes, restype = self._get_signature(funcval)
-        self.descr = cpu.calldescrof_dynamic(argtypes, restype)
+        try:
+            self.descr = cpu.calldescrof_dynamic(argtypes, restype)
+        except UnsupportedKind:
+            # e.g., I or U for long longs
+            self.descr = None
         self.prepare_op = prepare_op
 
     def _get_signature(self, funcval):

diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -60,11 +60,10 @@
         elif ffi_type is types.uint16:  return 'u'
         elif ffi_type is types.sint32:  return 'i'
         elif ffi_type is types.uint32:  return 'u'
-        ## we only support integers that fit in a lltype.Signed (==rffi.LONG)
-        ## (on 64-bit platforms, types.sint64 is types.slong and the case is
-        ## caught above)
-        ## elif ffi_type is types.sint64:  return 'i'
-        ## elif ffi_type is types.uint64:  return 'u'
+        ## (note that on 64-bit platforms, types.sint64 is types.slong and the
+        ## case is caught above)
+        elif ffi_type is types.sint64:  return 'I'
+        elif ffi_type is types.uint64:  return 'U'
         raise KeyError
 
 types._import()
@@ -192,6 +191,8 @@
 
 DOUBLE_ARRAY_PTR = lltype.Ptr(lltype.Array(rffi.DOUBLE))
 LONGLONG_ARRAY_PTR = lltype.Ptr(lltype.Array(rffi.LONGLONG))
+
+ at jit.dont_look_inside
 def longlong2float(llval):
     d_array = lltype.malloc(DOUBLE_ARRAY_PTR.TO, 1, flavor='raw')
     ll_array = rffi.cast(LONGLONG_ARRAY_PTR, d_array)
@@ -200,6 +201,7 @@
     lltype.free(d_array, flavor='raw')
     return floatval
 
+ at jit.dont_look_inside
 def float2longlong(floatval):
     d_array = lltype.malloc(DOUBLE_ARRAY_PTR.TO, 1, flavor='raw')
     ll_array = rffi.cast(LONGLONG_ARRAY_PTR, d_array)

diff --git a/pypy/rlib/test/test_libffi.py b/pypy/rlib/test/test_libffi.py
--- a/pypy/rlib/test/test_libffi.py
+++ b/pypy/rlib/test/test_libffi.py
@@ -294,7 +294,7 @@
         expected = c_float(c_float(12.34).value + c_float(56.78).value).value
         assert res == expected
 
-    def test_longlong_args(self):
+    def test_slonglong_args(self):
         """
             long long sum_xy_longlong(long long x, long long y)
             {
@@ -309,7 +309,8 @@
                 types.slonglong)
         x = r_longlong(maxint32+1)
         y = r_longlong(maxint32+2)
-        res = self.call(func, [x, y], rffi.LONGLONG, init_result=0)
+        zero = longlong2float(r_longlong(0))
+        res = self.call(func, [x, y], rffi.LONGLONG, init_result=zero)
         if types.slonglong is not types.slong:
             # obscure, on 32bit it's really a long long, so it returns a
             # DOUBLE because of the JIT hack

diff --git a/pypy/jit/backend/llsupport/ffisupport.py b/pypy/jit/backend/llsupport/ffisupport.py
--- a/pypy/jit/backend/llsupport/ffisupport.py
+++ b/pypy/jit/backend/llsupport/ffisupport.py
@@ -3,6 +3,9 @@
 from pypy.jit.backend.llsupport.descr import DynamicIntCallDescr, NonGcPtrCallDescr,\
     FloatCallDescr, VoidCallDescr
 
+class UnsupportedKind(Exception):
+    pass
+
 def get_call_descr_dynamic(ffi_args, ffi_result, extrainfo=None):
     """Get a call descr: the types of result and args are represented by
     rlib.libffi.types.*"""
@@ -33,7 +36,7 @@
         return history.FLOAT
     elif kind == 'v':
         return history.VOID
-    assert False, "Unsupported kind '%s'" % kind
+    raise UnsupportedKind("Unsupported kind '%s'" % kind)
 
 def is_ffi_type_signed(ffi_type):
     from pypy.rlib.libffi import types

diff --git a/pypy/jit/metainterp/test/test_fficall.py b/pypy/jit/metainterp/test/test_fficall.py
--- a/pypy/jit/metainterp/test/test_fficall.py
+++ b/pypy/jit/metainterp/test/test_fficall.py
@@ -1,13 +1,13 @@
 
 import py
-from pypy.rlib.rarithmetic import r_singlefloat
-from pypy.rlib.jit import JitDriver, hint
+from pypy.rlib.rarithmetic import r_singlefloat, r_longlong
+from pypy.rlib.jit import JitDriver, hint, dont_look_inside
 from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.libffi import ArgChain
+from pypy.rlib.libffi import ArgChain, longlong2float, float2longlong
 from pypy.rlib.test.test_libffi import TestLibffiCall as _TestLibffiCall
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.jit.metainterp.test.test_basic import LLJitMixin
-
+from pypy.rlib.objectmodel import specialize
 
 class TestFfiCall(LLJitMixin, _TestLibffiCall):
 
@@ -27,6 +27,10 @@
             reds = ['n', 'func', 'res'] # floats must be *after* refs
         driver = JitDriver(reds=reds, greens=[])
         #
+        @specialize.memo()
+        def memo_longlong2float(llval):
+            return longlong2float(llval)
+        
         def f(n):
             func = lib.getpointer(name, argtypes, restype)
             res = init_result
@@ -38,12 +42,14 @@
                 for argval in args: # this loop is unrolled
                     if type(argval) is r_singlefloat:
                         argchain.arg_singlefloat(float(argval))
+                    elif type(argval) is r_longlong:
+                        argchain.arg_longlong(memo_longlong2float(argval))
                     else:
                         argchain.arg(argval)
                 res = func.call(argchain, RESULT)
                 n += 1
             return res
         #
-        res = self.meta_interp(f, [0], jit_ffi=True)
+        res = self.meta_interp(f, [0], jit_ffi=True, backendopt=True)
         return res
 


More information about the Pypy-commit mailing list