[pypy-svn] r77566 - in pypy/branch/jitffi/pypy: jit/codewriter rlib
antocuni at codespeak.net
antocuni at codespeak.net
Mon Oct 4 13:48:30 CEST 2010
Author: antocuni
Date: Mon Oct 4 13:48:29 2010
New Revision: 77566
Modified:
pypy/branch/jitffi/pypy/jit/codewriter/support.py
pypy/branch/jitffi/pypy/rlib/libffi.py
Log:
manually specialize _do_call into _do_call_{int,float}. This is needed because oopspec does not play well with specialize()
Modified: pypy/branch/jitffi/pypy/jit/codewriter/support.py
==============================================================================
--- pypy/branch/jitffi/pypy/jit/codewriter/support.py (original)
+++ pypy/branch/jitffi/pypy/jit/codewriter/support.py Mon Oct 4 13:48:29 2010
@@ -235,9 +235,11 @@
def _ll_4_libffi_push_float(llfunc, value, ll_args, i):
return func(llfunc)._push_float(value, ll_args, i)
-def _ll_4_libffi_call(llfunc, funcsym, ll_args, RESULT):
+def _ll_3_libffi_call_int(llfunc, funcsym, ll_args):
return func(llfunc)._do_call(funcsym, ll_args, lltype.Signed)
-# XXX: should be RESULT, but it doesn't work
+
+def _ll_3_libffi_call_float(llfunc, funcsym, ll_args):
+ return func(llfunc)._do_call(funcsym, ll_args, lltype.Float)
Modified: pypy/branch/jitffi/pypy/rlib/libffi.py
==============================================================================
--- pypy/branch/jitffi/pypy/rlib/libffi.py (original)
+++ pypy/branch/jitffi/pypy/rlib/libffi.py Mon Oct 4 13:48:29 2010
@@ -74,6 +74,10 @@
self.keepalive = keepalive
self.funcsym = funcsym
+ # ========================================================================
+ # PUBLIC INTERFACE
+ # ========================================================================
+
@jit.unroll_safe
@specialize.arg(2)
def call(self, argchain, RESULT):
@@ -97,40 +101,59 @@
arg.push(self, ll_args, i)
i += 1
arg = arg.next
- result = self._do_call(self.funcsym, ll_args, RESULT)
- return result
+ if RESULT is lltype.Signed:
+ return self._do_call_int(self.funcsym, ll_args)
+ elif RESULT is lltype.Float:
+ return self._do_call_float(self.funcsym, ll_args)
+ else:
+ raise TypeError, 'Unsupported result type: %s' % RESULT
# END OF THE PUBLIC INTERFACE
- # -------------------------------------------------------------------------
- # the following methods are supposed to be seen opaquely by the JIT
- # optimizer. Don't call them
+ # ------------------------------------------------------------------------
+
+ # JIT friendly interface
+ # the following methods are supposed to be seen opaquely by the optimizer
@jit.oopspec('libffi_prepare_call(self)')
def _prepare(self):
ll_args = lltype.malloc(rffi.VOIDPP.TO, len(self.argtypes), flavor='raw')
return ll_args
- @specialize.arg(1)
- def _push_arg(self, TYPE, value, ll_args, i):
- # XXX: check the type is not translated?
- argtype = self.argtypes[i]
- c_size = intmask(argtype.c_size)
- ll_buf = lltype.malloc(rffi.CCHARP.TO, c_size, flavor='raw')
- push_arg_as_ffiptr(argtype, value, ll_buf)
- ll_args[i] = ll_buf
+ # _push_* and _do_call_* in theory could be automatically specialize()d by
+ # the annotator. However, specialization doesn't work well with oopspec,
+ # so we specialize them by hand
@jit.oopspec('libffi_push_int(self, value, ll_args, i)')
@enforceargs( None, int, None, int) # fix the annotation for tests
def _push_int(self, value, ll_args, i):
- self._push_arg(lltype.Signed, value, ll_args, i)
+ self._push_arg(value, ll_args, i)
@jit.oopspec('libffi_push_float(self, value, ll_args, i)')
@enforceargs( None, float, None, int) # fix the annotation for tests
def _push_float(self, value, ll_args, i):
- self._push_arg(lltype.Float, value, ll_args, i)
+ self._push_arg(value, ll_args, i)
+
+ @jit.oopspec('libffi_call_int(self, funcsym, ll_args)')
+ def _do_call_int(self, funcsym, ll_args):
+ return self._do_call(funcsym, ll_args, lltype.Signed)
+
+ @jit.oopspec('libffi_call_float(self, funcsym, ll_args)')
+ def _do_call_float(self, funcsym, ll_args):
+ return self._do_call(funcsym, ll_args, lltype.Float)
+
+ # ------------------------------------------------------------------------
+ # private methods
+
+ @specialize.argtype(1)
+ def _push_arg(self, value, ll_args, i):
+ # XXX: check the type is not translated?
+ argtype = self.argtypes[i]
+ c_size = intmask(argtype.c_size)
+ ll_buf = lltype.malloc(rffi.CCHARP.TO, c_size, flavor='raw')
+ push_arg_as_ffiptr(argtype, value, ll_buf)
+ ll_args[i] = ll_buf
@specialize.arg(3)
- @jit.oopspec('libffi_call(self, funcsym, ll_args, RESULT)')
def _do_call(self, funcsym, ll_args, RESULT):
# XXX: check len(args)?
ll_result = lltype.nullptr(rffi.CCHARP.TO)
More information about the Pypy-commit
mailing list