[pypy-svn] pypy jitypes2: * Small tweaks to fix the tests.
arigo
commits-noreply at bitbucket.org
Wed Dec 22 17:18:44 CET 2010
Author: Armin Rigo <arigo at tunes.org>
Branch: jitypes2
Changeset: r40187:52a6bafed5d9
Date: 2010-12-22 17:18 +0100
http://bitbucket.org/pypy/pypy/changeset/52a6bafed5d9/
Log: * Small tweaks to fix the tests.
* The test passes on 32-bit, but not yet on 64-bit. Unsure why.
diff --git a/pypy/rlib/libffi.py b/pypy/rlib/libffi.py
--- a/pypy/rlib/libffi.py
+++ b/pypy/rlib/libffi.py
@@ -82,6 +82,8 @@
# ======================================================================
+IS_32_BIT = (r_uint.BITS == 32)
+
@specialize.memo()
def _check_type(TYPE):
if isinstance(TYPE, lltype.Ptr):
@@ -124,6 +126,7 @@
the conversions. Note that if you use long longs, the call won't
be jitted at all.
"""
+ assert IS_32_BIT # use a normal integer on 64-bit platforms
self._append(LongLongArg(val))
def arg_singlefloat(self, val):
@@ -290,6 +293,7 @@
# XXX: even if RESULT is LONGLONG, we still return a DOUBLE, else the
# jit complains. Note that the jit is disabled in this case
# (it's not a typo, we really return a DOUBLE)
+ assert IS_32_BIT
return self._do_call_longlong(self.funcsym, ll_args)
elif RESULT is lltype.Void:
return self._do_call_void(self.funcsym, ll_args)
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
@@ -4,7 +4,8 @@
from pypy.rpython.lltypesystem.ll2ctypes import ALLOCATED
from pypy.rlib.rarithmetic import r_singlefloat, r_longlong, r_ulonglong
from pypy.rlib.test.test_clibffi import BaseFfiTest, get_libm_name
-from pypy.rlib.libffi import CDLL, Func, get_libc_name, ArgChain, types, longlong2float, float2longlong
+from pypy.rlib.libffi import CDLL, Func, get_libc_name, ArgChain, types
+from pypy.rlib.libffi import longlong2float, float2longlong, IS_32_BIT
class TestLibffiMisc(BaseFfiTest):
@@ -125,9 +126,9 @@
for arg in args:
if isinstance(arg, r_singlefloat):
chain.arg_singlefloat(float(arg))
- elif isinstance(arg, r_longlong):
+ elif IS_32_BIT and isinstance(arg, r_longlong):
chain.arg_longlong(longlong2float(arg))
- elif isinstance(arg, r_ulonglong):
+ elif IS_32_BIT and isinstance(arg, r_ulonglong):
arg = rffi.cast(rffi.LONGLONG, arg)
chain.arg_longlong(longlong2float(arg))
else:
@@ -317,7 +318,7 @@
y = r_longlong(maxint32+2)
zero = longlong2float(r_longlong(0))
res = self.call(func, [x, y], rffi.LONGLONG, init_result=zero)
- if types.slonglong is not types.slong:
+ if IS_32_BIT:
# obscure, on 32bit it's really a long long, so it returns a
# DOUBLE because of the JIT hack
res = float2longlong(res)
@@ -341,7 +342,7 @@
x = r_ulonglong(maxint64+1)
y = r_ulonglong(2)
res = self.call(func, [x, y], rffi.ULONGLONG, init_result=0)
- if types.ulonglong is not types.ulong:
+ if IS_32_BIT:
# obscure, on 32bit it's really a long long, so it returns a
# DOUBLE because of the JIT hack
res = float2longlong(res)
diff --git a/pypy/jit/codewriter/assembler.py b/pypy/jit/codewriter/assembler.py
--- a/pypy/jit/codewriter/assembler.py
+++ b/pypy/jit/codewriter/assembler.py
@@ -71,7 +71,8 @@
TYPE = llmemory.Address
if TYPE == llmemory.Address:
value = heaptracker.adr2int(value)
- elif not isinstance(value, ComputedIntSymbolic):
+ if not isinstance(value, (llmemory.AddressAsInt,
+ ComputedIntSymbolic)):
value = lltype.cast_primitive(lltype.Signed, value)
if allow_short and -128 <= value <= 127:
# emit the constant as a small integer
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,9 +1,10 @@
import py
-from pypy.rlib.rarithmetic import r_singlefloat, r_longlong
+from pypy.rlib.rarithmetic import r_singlefloat, r_longlong, r_ulonglong
from pypy.rlib.jit import JitDriver, hint, dont_look_inside
from pypy.rlib.unroll import unrolling_iterable
from pypy.rlib.libffi import ArgChain, longlong2float, float2longlong
+from pypy.rlib.libffi import IS_32_BIT
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
@@ -20,17 +21,26 @@
"""
#
lib, name, argtypes, restype = funcspec
- args = unrolling_iterable(args)
+ method_and_args = []
+ for argval in args:
+ if type(argval) is r_singlefloat:
+ method_name = 'arg_singlefloat'
+ argval = float(argval)
+ elif IS_32_BIT and type(argval) in [r_longlong, r_ulonglong]:
+ method_name = 'arg_longlong'
+ argval = rffi.cast(rffi.LONGLONG, argval)
+ argval = longlong2float(argval)
+ else:
+ method_name = 'arg'
+ method_and_args.append((method_name, argval))
+ method_and_args = unrolling_iterable(method_and_args)
#
reds = ['n', 'res', 'func']
- if type(init_result) is float:
+ if (RESULT in [rffi.FLOAT, rffi.DOUBLE] or
+ IS_32_BIT and RESULT in [rffi.LONGLONG, rffi.ULONGLONG]):
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
@@ -39,17 +49,12 @@
driver.can_enter_jit(n=n, res=res, func=func)
func = hint(func, promote=True)
argchain = ArgChain()
- 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)
+ # this loop is unrolled
+ for method_name, argval in method_and_args:
+ getattr(argchain, method_name)(argval)
res = func.call(argchain, RESULT)
n += 1
return res
#
res = self.meta_interp(f, [0], jit_ffi=True, backendopt=True)
return res
-
More information about the Pypy-commit
mailing list