[pypy-svn] r76464 - in pypy/branch/fast-ctypes/pypy: module/jitffi rlib
getxsick at codespeak.net
getxsick at codespeak.net
Wed Aug 4 01:49:56 CEST 2010
Author: getxsick
Date: Wed Aug 4 01:49:55 2010
New Revision: 76464
Modified:
pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
Log:
use space.fromcache for compiled loops
Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py (original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py Wed Aug 4 01:49:55 2010
@@ -61,6 +61,9 @@
W_Root, str])
)
+class Cache(object):
+ def __init__(self, space):
+ self.cache = {}
class W_Get(Wrappable):
def __init__(self, space, cpu, lib, func, args_type, res_type='v'):
@@ -68,19 +71,29 @@
if res_type == 'i':
self.rget = rjitffi._Get(cpu, lib, func, args_type,
- res_type, self.wrap_int)
+ res_type, self.wrap_int, cache=True)
elif res_type == 'f':
self.rget = rjitffi._Get(cpu, lib, func, args_type,
- res_type, self.wrap_float)
+ res_type, self.wrap_float, cache=True)
elif res_type == 'v':
self.rget = rjitffi._Get(cpu, lib, func, args_type,
- res_type, self.wrap_void)
+ res_type, self.wrap_void, cache=True)
else:
raise OperationError(
space.w_ValueError,
space.wrap('Unsupported type of result: %s'
% res_type))
+ # grab from the cache if possible
+ arg_classes = ''.join(args_type)
+ key = (res_type, arg_classes)
+ cache = space.fromcache(Cache).cache
+ try:
+ self.rget.looptoken = cache[key]
+ except KeyError:
+ self.rget.gen_looptaken()
+ cache[key] = self.rget.looptoken
+
def call_w(self, space, w_args=None):
if not space.is_w(w_args, space.w_None):
i = 0
Modified: pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py (original)
+++ pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py Wed Aug 4 01:49:55 2010
@@ -33,56 +33,51 @@
rffi.free_charp(name_ptr)
class _Get(object):
- def __init__(self, cpu, lib, func, args_type, res_type='v', push_result=None):
+ def __init__(self, cpu, lib, func, args_type, res_type='v',
+ push_result=None, cache=False):
assert isinstance(args_type, list)
self.args_type = args_type
self.res_type = res_type
self.push_result = push_result
self.cpu = cpu
+ self.bargs = []
lib = lib.handler
- bargs = []
- self._cache = {}
try:
self.funcaddr = rffi.cast(lltype.Signed, rdynload.dlsym(lib, func))
except KeyError:
raise ValueError("Cannot find symbol %s", func)
- bargs.append(BoxInt())
+ self.bargs.append(BoxInt())
+ if not cache:
+ self.gen_looptaken()
+ self.setup_stack()
- # grab from the cache if possible
- arg_classes = ''.join(self.args_type)
- key = (self.res_type, arg_classes)
- try:
- self.looptoken = self._cache[key]
- except KeyError:
- for arg in self.args_type:
- if arg == 'i':
- bargs.append(BoxInt())
- elif arg == 'f':
- bargs.append(BoxFloat())
- else:
- raise ValueError(arg)
-
- if self.res_type == 'i':
- bres = BoxInt()
- elif self.res_type == 'f':
- bres = BoxFloat()
- elif self.res_type == 'v':
- bres = NULLBOX
+ def gen_looptaken(self):
+ for arg in self.args_type:
+ if arg == 'i':
+ self.bargs.append(BoxInt())
+ elif arg == 'f':
+ self.bargs.append(BoxFloat())
else:
- raise ValueError(self.res_type)
+ raise ValueError(arg)
- calldescr = self.get_calldescr()
- self.looptoken = LoopToken()
- bargs = list(bargs) # make sure it's not resized before ResOperation
- oplist = [ResOperation(rop.CALL, bargs, bres, descr=calldescr),
- ResOperation(rop.FINISH, [bres], None,
- descr=BasicFailDescr(0))]
- self.cpu.compile_loop(bargs, oplist, self.looptoken)
+ if self.res_type == 'i':
+ bres = BoxInt()
+ elif self.res_type == 'f':
+ bres = BoxFloat()
+ elif self.res_type == 'v':
+ bres = NULLBOX
+ else:
+ raise ValueError(self.res_type)
- # add to the cache
- self._cache[key] = self.looptoken
- self.setup_stack()
+ calldescr = self.get_calldescr()
+ self.looptoken = LoopToken()
+ # make sure it's not resized before ResOperation
+ self.bargs = list(self.bargs)
+ oplist = [ResOperation(rop.CALL, self.bargs, bres, descr=calldescr),
+ ResOperation(rop.FINISH, [bres], None,
+ descr=BasicFailDescr(0))]
+ self.cpu.compile_loop(self.bargs, oplist, self.looptoken)
def get_calldescr(self):
if self.res_type == 'i':
More information about the Pypy-commit
mailing list