[pypy-commit] pypy reflex-support: (cfbolz, wlav) fast path implementations and removal of jit.dont_look_inside

wlav noreply at buildbot.pypy.org
Wed Jul 13 14:22:18 CEST 2011


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: reflex-support
Changeset: r45544:9a2e5320fd1e
Date: 2011-07-13 05:15 -0700
http://bitbucket.org/pypy/pypy/changeset/9a2e5320fd1e/

Log:	(cfbolz, wlav) fast path implementations and removal of
	jit.dont_look_inside

diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -118,7 +118,6 @@
         arr = getattr(cache, 'array_' + self.typecode)
         return arr.fromaddress(space, address[0], self.size)
 
-    @jit.dont_look_inside
     def to_memory(self, space, w_obj, w_value, offset):
         # copy only the pointer value
         rawobject = get_rawobject(space, w_obj)
@@ -146,29 +145,33 @@
 
 class BoolConverter(TypeConverter):
     _immutable = True
-    libffitype = libffi.types.sint               # TODO: probably incorrect
+    libffitype = libffi.types.schar
 
-    def convert_argument(self, space, w_obj):
+    def _unwrap_object(self, space, w_obj):
         arg = space.c_int_w(w_obj)
         if arg != False and arg != True:
             raise OperationError(space.w_TypeError,
                                  space.wrap("boolean value should be bool, or integer 1 or 0"))
+        return arg
+
+    def convert_argument(self, space, w_obj):
+        arg = self._unwrap_object(space, w_obj)
         x = lltype.malloc(rffi.LONGP.TO, 1, flavor='raw')
         x[0] = arg
         return rffi.cast(rffi.VOIDP, x)
 
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg(self._unwrap_object(space, w_obj))
+
     def from_memory(self, space, w_obj, offset):
         address = self._get_raw_address(space, w_obj, offset)
         if address[0] == '\x01':
-            return space.wrap(True)
-        return space.wrap(False)
+            return space.w_True
+        return space.w_False
 
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
-        arg = space.c_int_w(w_value)
-        if arg != False and arg != True:
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("boolean value should be bool, or integer 1 or 0"))
+        arg = self._unwrap_object(space, w_value)
         if arg:
             address[0] = '\x01'
         else:
@@ -178,7 +181,7 @@
     _immutable = True
     libffitype = libffi.types.schar
 
-    def _from_space(self, space, w_value):
+    def _unwrap_object(self, space, w_value):
         # allow int to pass to char and make sure that str is of length 1
         if space.isinstance_w(w_value, space.w_int):
             ival = space.c_int_w(w_value)
@@ -196,17 +199,20 @@
         return value[0] # turn it into a "char" to the annotator
 
     def convert_argument(self, space, w_obj):
-        arg = self._from_space(space, w_obj)
+        arg = self._unwrap_object(space, w_obj)
         x = rffi.str2charp(arg)
         return rffi.cast(rffi.VOIDP, x)
 
+    def convert_argument_libffi(self, space, w_obj, argchain): 
+        argchain.arg(self._unwrap_object(space, w_obj))
+
     def from_memory(self, space, w_obj, offset):
         address = self._get_raw_address(space, w_obj, offset)
         return space.wrap(address[0])
 
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
-        address[0] = self._from_space(space, w_value)
+        address[0] = self._unwrap_object(space, w_value)
 
 class IntConverter(TypeConverter):
     _immutable = True
@@ -247,6 +253,9 @@
         x[0] = arg
         return rffi.cast(rffi.VOIDP, x)
 
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg(self._unwrap_object(space, w_obj))
+
     def from_memory(self, space, w_obj, offset):
         address = self._get_raw_address(space, w_obj, offset)
         ulongptr = rffi.cast(rffi.UINTP, address)
@@ -296,6 +305,9 @@
         x[0] = arg
         return rffi.cast(rffi.VOIDP, x)
 
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg(self._unwrap_object(space, w_obj))
+
     def from_memory(self, space, w_obj, offset):
         address = self._get_raw_address(space, w_obj, offset)
         ulongptr = rffi.cast(rffi.ULONGP, address)
@@ -306,10 +318,22 @@
         ulongptr = rffi.cast(rffi.ULONGP, address)
         ulongptr[0] = self._unwrap_object(space, w_value)
 
-class ShortConverter(LongConverter):
+class ShortConverter(TypeConverter):
     _immutable = True
     libffitype = libffi.types.sshort
 
+    def _unwrap_object(self, space, w_obj):
+        return rffi.cast(rffi.SHORT, space.int_w(w_obj))
+
+    def convert_argument(self, space, w_obj):
+        arg = self._unwrap_object(space, w_obj)
+        x = lltype.malloc(rffi.SHORTP.TO, 1, flavor='raw')
+        x[0] = arg
+        return rffi.cast(rffi.VOIDP, x)
+
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg(self._unwrap_object(space, w_obj))
+
     def from_memory(self, space, w_obj, offset):
         address = self._get_raw_address(space, w_obj, offset)
         shortptr = rffi.cast(rffi.SHORTP, address)
@@ -318,7 +342,7 @@
     def to_memory(self, space, w_obj, w_value, offset):
         address = self._get_raw_address(space, w_obj, offset)
         shortptr = rffi.cast(rffi.SHORTP, address)
-        shortptr[0] = rffi.cast(rffi.SHORT, self._unwrap_object(space, w_value))
+        shortptr[0] = self._unwrap_object(space, w_value)
 
 class FloatConverter(TypeConverter):
     _immutable = True
@@ -332,6 +356,9 @@
         x[0] = self._unwrap_object(space, w_obj)
         return rffi.cast(rffi.VOIDP, x)
 
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg_singlefloat(self._unwrap_object(space, w_obj))
+
     def from_memory(self, space, w_obj, offset):
         address = self._get_raw_address(space, w_obj, offset)
         floatptr = rffi.cast(rffi.FLOATP, address)
@@ -451,12 +478,7 @@
     def __init__(self, space, cpptype):
         self.cpptype = cpptype
 
-    # TODO: factor out the direct_ptradd into a smaller function (so that the
-    # JIT can look into the rest of the code), or better, let the JIT
-    # see it (either by teaching it direct_ptradd, or by using a
-    # different style like casts between addresses and integers)
-    @jit.dont_look_inside
-    def convert_argument(self, space, w_obj):
+    def _unwrap_object(self, space, w_obj):
         from pypy.module.cppyy.interp_cppyy import W_CPPInstance
         w_cppinstance = space.findattr(w_obj, space.wrap("_cppinstance"))
         if w_cppinstance:
@@ -473,6 +495,12 @@
                                  space.type(w_obj).getname(space, "?"),
                                  self.cpptype.name)))
 
+    def convert_argument(self, space, w_obj):
+        return self._unwrap_object(space, w_obj)
+
+    def convert_argument_libffi(self, space, w_obj, argchain):
+        argchain.arg(self._unwrap_object(space, w_obj))
+
     def free_argument(self, arg):
         pass
 
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -40,6 +40,7 @@
 
 class VoidExecutor(FunctionExecutor):
     _immutable_ = True
+    libffitype = libffi.types.void
 
     def execute(self, space, func, cppthis, num_args, args):
         capi.c_call_v(func.cpptype.handle, func.method_index, cppthis, num_args, args)
@@ -52,18 +53,28 @@
 
 class BoolExecutor(FunctionExecutor):
     _immutable_ = True
+    libffitype = libffi.types.schar
 
     def execute(self, space, func, cppthis, num_args, args):
         result = capi.c_call_b(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return space.wrap(result)
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.CHAR)
+        return space.wrap(result)
+
 class CharExecutor(FunctionExecutor):
     _immutable_ = True
+    libffitype = libffi.types.schar
 
     def execute(self, space, func, cppthis, num_args, args):
         result = capi.c_call_c(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return space.wrap(result)
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.CHAR)
+        return space.wrap(result)
+
 class ShortExecutor(FunctionExecutor):
     _immutable_ = True
     libffitype = libffi.types.sshort
@@ -72,6 +83,10 @@
         result = capi.c_call_h(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return space.wrap(result)
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.SHORT)
+        return space.wrap(result)
+
 class IntExecutor(FunctionExecutor):
     _immutable_ = True
     libffitype = libffi.types.sint
@@ -83,9 +98,9 @@
         result = capi.c_call_i(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return self._wrap_result(space, result)
 
-# TODO: check whether the following is correct (return type cast):
-#   def execute_libffi(self, space, libffifunc, argchain):
-#       return space.wrap(libffifunc.call(argchain, rffi.INT))
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.INT)
+        return space.wrap(result)
 
 class UnsignedIntExecutor(FunctionExecutor):
     _immutable_ = True
@@ -98,6 +113,10 @@
         result = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return self._wrap_result(space, result)
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.UINT)
+        return space.wrap(result)
+
 class LongExecutor(FunctionExecutor):
     _immutable_ = True
     libffitype = libffi.types.slong
@@ -110,7 +129,8 @@
         return self._wrap_result(space, result)
 
     def execute_libffi(self, space, libffifunc, argchain):
-        return space.wrap(libffifunc.call(argchain, lltype.Signed))
+        result = libffifunc.call(argchain, rffi.LONG)
+        return space.wrap(result)
 
 class UnsignedLongExecutor(LongExecutor):
     _immutable_ = True
@@ -119,27 +139,46 @@
     def _wrap_result(self, space, result):
         return space.wrap(rffi.cast(rffi.ULONG, result))
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.ULONG)
+        return space.wrap(result)
+
 class ConstIntRefExecutor(LongExecutor):
     _immutable_ = True
+    libffitype = libffi.types.pointer
 
     def _wrap_result(self, space, result):
         intptr = rffi.cast(rffi.INTP, result)
         return space.wrap(intptr[0])
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.INTP)
+        return space.wrap(result[0])
+
 class ConstLongRefExecutor(LongExecutor):
     _immutable_ = True
+    libffitype = libffi.types.pointer
 
     def _wrap_result(self, space, result):
         longptr = rffi.cast(rffi.LONGP, result)
         return space.wrap(longptr[0])
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.LONGP)
+        return space.wrap(result[0])
+
 class FloatExecutor(FunctionExecutor):
     _immutable_ = True
+    libffitype = libffi.types.float
 
     def execute(self, space, func, cppthis, num_args, args):
         result = capi.c_call_f(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         return space.wrap(result)
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.FLOAT)
+        return space.wrap(result)
+
 class DoubleExecutor(FunctionExecutor):
     _immutable_ = True
     libffitype = libffi.types.double
@@ -149,11 +188,13 @@
         return space.wrap(result)
 
     def execute_libffi(self, space, libffifunc, argchain):
-        return space.wrap(libffifunc.call(argchain, rffi.DOUBLE))
+        result = libffifunc.call(argchain, rffi.DOUBLE)
+        return space.wrap(result)
 
 
 class CStringExecutor(FunctionExecutor):
     _immutable_ = True
+
     def execute(self, space, func, cppthis, num_args, args):
         lresult = capi.c_call_l(func.cpptype.handle, func.method_index, cppthis, num_args, args)
         ccpresult = rffi.cast(rffi.CCHARP, lresult)
@@ -192,6 +233,8 @@
 
 class InstancePtrExecutor(FunctionExecutor):
     _immutable_ = True
+    libffitype = libffi.types.pointer
+
     def __init__(self, space, name, cpptype):
         FunctionExecutor.__init__(self, space, name, cpptype)
         self.cpptype = cpptype
@@ -202,6 +245,11 @@
         ptr_result = rffi.cast(rffi.VOIDP, long_result)
         return interp_cppyy.W_CPPInstance(space, self.cpptype, ptr_result, False)
 
+    def execute_libffi(self, space, libffifunc, argchain):
+        result = libffifunc.call(argchain, rffi.VOIDP)
+        return interp_cppyy.W_CPPInstance(space, self.cpptype, result, False)
+
+
 class InstanceExecutor(InstancePtrExecutor):
     _immutable_ = True
 


More information about the pypy-commit mailing list