[pypy-svn] r64708 - in pypy/branch/pyjitpl5/pypy/jit: backend/minimal backend/test backend/x86 backend/x86/test metainterp
arigo at codespeak.net
arigo at codespeak.net
Sun Apr 26 22:04:22 CEST 2009
Author: arigo
Date: Sun Apr 26 22:04:21 2009
New Revision: 64708
Modified:
pypy/branch/pyjitpl5/pypy/jit/backend/minimal/runner.py
pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc2.py
pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
Log:
Fix the x86 and the minimal backends.
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/minimal/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/minimal/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/minimal/runner.py Sun Apr 26 22:04:21 2009
@@ -20,6 +20,7 @@
self.is_oo = False
self.stats = stats
self.translate_support_code = translate_support_code
+ self._future_values = []
self.setup()
def setup(self):
@@ -39,11 +40,12 @@
def compile_operations(self, loop):
pass
- def execute_operations(self, loop, valueboxes):
+ def execute_operations(self, loop):
if DEBUG:
print "execute_operations: starting", loop
for box in valueboxes:
print "\t", box, "\t", box.get_()
+ valueboxes = self._future_values
self.clear_exception()
self._guard_failed = False
while True:
@@ -112,6 +114,16 @@
self.latest_fail = op, env
return op
+ def set_future_value_int(self, index, intvalue):
+ del self._future_values[index:]
+ assert len(self._future_values) == index
+ self._future_values.append(BoxInt(intvalue))
+
+ def set_future_value_ptr(self, index, ptrvalue):
+ del self._future_values[index:]
+ assert len(self._future_values) == index
+ self._future_values.append(BoxPtr(ptrvalue))
+
def get_latest_value_int(self, index):
op, env = self.latest_fail
return env[op.args[index]].getint()
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/runner.py Sun Apr 26 22:04:21 2009
@@ -1,7 +1,7 @@
import sys
from pypy.jit.metainterp.history import (BoxInt, Box, BoxPtr, TreeLoop,
- ConstInt, ConstPtr)
+ ConstInt, ConstPtr, BoxObj)
from pypy.jit.metainterp.resoperation import ResOperation, rop
from pypy.rpython.lltypesystem import lltype, llmemory, rstr, rffi, rclass
from pypy.jit.metainterp.executor import execute
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/test/test_random.py Sun Apr 26 22:04:21 2009
@@ -56,8 +56,9 @@
print >>s, ' ]'
print >>s, ' cpu = CPU(None, None)'
print >>s, ' cpu.compile_operations(loop)'
- print >>s, ' op = cpu.execute_operations(loop, [%s])' % (
- ', '.join(['BoxInt(%d)' % v.value for v in self.loop.inputargs]))
+ for i, v in enumerate(self.loop.inputargs):
+ print >>s, ' cpu.set_future_value_int(%d, %d)' % (i, v.value)
+ print >>s, ' op = cpu.execute_operations(loop)'
if self.should_fail_by is None:
for i, v in enumerate(self.loop.operations[-1].args):
print >>s, ' assert cpu.get_latest_value_int(%d) == %d' % (
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py Sun Apr 26 22:04:21 2009
@@ -264,20 +264,17 @@
self.make_sure_mc_exists()
addr = self.mc.tell()
self.mc.SUB(esp, imm(framesize * WORD))
- self.mc.MOV(eax, arg_pos(0, framesize * WORD))
for i in range(len(arglocs)):
loc = arglocs[i]
if not isinstance(loc, REG):
- self.mc.MOV(ecx, mem(eax, i * WORD))
+ self.mc.MOV(ecx,
+ addr_add(imm(self.fail_box_addr), imm(i*WORD)))
self.mc.MOV(loc, ecx)
for i in range(len(arglocs)):
loc = arglocs[i]
- if isinstance(loc, REG) and loc is not eax:
- self.mc.MOV(loc, mem(eax, i * WORD))
- for i in range(len(arglocs)):
- loc = arglocs[i]
- if loc is eax:
- self.mc.MOV(loc, mem(eax, i * WORD))
+ if isinstance(loc, REG):
+ self.mc.MOV(loc,
+ addr_add(imm(self.fail_box_addr), imm(i*WORD)))
self.mc.JMP(rel32(jumpaddr))
self.mc.done()
return addr
@@ -867,7 +864,7 @@
self.mc.PUSH(stack_pos(loc.position + extra_on_stack))
extra_on_stack += 1
if isinstance(op.args[0], Const):
- x = rel32(self.cpu.get_box_value_as_int(op.args[0]))
+ x = rel32(op.args[0].getint())
else:
x = arglocs[0]
if isinstance(x, MODRM):
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py Sun Apr 26 22:04:21 2009
@@ -69,8 +69,7 @@
debug = True
is_oo = False
- BOOTSTRAP_TP = lltype.FuncType([lltype.Ptr(rffi.CArray(lltype.Signed))],
- lltype.Signed)
+ BOOTSTRAP_TP = lltype.FuncType([], lltype.Signed)
def __init__(self, rtyper, stats, translate_support_code=False,
mixlevelann=None):
@@ -92,7 +91,6 @@
self.current_interpreter._store_exception = _store_exception
TP = lltype.GcArray(llmemory.GCREF)
self.keepalives = []
- self.keepalives_index = 0
self._bootstrap_cache = {}
self._guard_list = []
self._compiled_ops = {}
@@ -231,22 +229,6 @@
self._bootstrap_cache[key] = func
return func
- def get_box_value_as_int(self, box):
- if isinstance(box, BoxInt):
- return box.value
- elif isinstance(box, ConstInt):
- return box.value
- elif isinstance(box, BoxPtr):
- self.keepalives.append(box.value)
- return self.cast_gcref_to_int(box.value)
- elif isinstance(box, ConstPtr):
- self.keepalives.append(box.value)
- return self.cast_gcref_to_int(box.value)
- elif isinstance(box, ConstAddr):
- return self.cast_adr_to_int(box.value)
- else:
- raise ValueError('get_box_value_as_int, wrong arg')
-
def _new_box(self, ptr):
if ptr:
return BoxPtr(lltype.nullptr(llmemory.GCREF.TO))
@@ -257,7 +239,7 @@
return self.generated_mps[calldescr]
except KeyError:
pass
- args = [BoxInt(0) for i in range(argnum + 1)]
+ args = [BoxInt() for i in range(argnum + 1)]
result = self._new_box(ptr)
operations = [
ResOperation(rop.CALL, args, result, calldescr),
@@ -271,32 +253,28 @@
self.generated_mps[calldescr] = loop
return loop
- def execute_operations(self, loop, valueboxes):
+ def execute_operations(self, loop):
func = self.get_bootstrap_code(loop)
- # turn all the values into integers
- TP = rffi.CArray(lltype.Signed)
- oldindex = self.keepalives_index
- values_as_int = lltype.malloc(TP, len(valueboxes), flavor='raw')
- for i in range(len(valueboxes)):
- box = valueboxes[i]
- v = self.get_box_value_as_int(box)
- values_as_int[i] = v
# debug info
#if self.debug and not we_are_translated():
# values_repr = ", ".join([str(values_as_int[i]) for i in
# range(len(valueboxes))])
# llop.debug_print(lltype.Void, 'exec:', name, values_repr)
- self.assembler.log_call(valueboxes)
- self.keepalives_index = len(self.keepalives)
- guard_index = self.execute_call(loop, func, values_as_int)
+ #self.assembler.log_call(valueboxes) --- XXX
+ guard_index = self.execute_call(loop, func)
self._guard_index = guard_index # for tests
- keepalive_until_here(valueboxes)
- self.keepalives_index = oldindex
- del self.keepalives[oldindex:]
op = self._guard_list[guard_index]
#print "Leaving at: %d" % self.assembler.fail_boxes[len(op.args)]
return op
+ def set_future_value_int(self, index, intvalue):
+ self.assembler.fail_boxes[index] = intvalue
+
+ def set_future_value_ptr(self, index, ptrvalue):
+ self.keepalives.append(ptrvalue)
+ intvalue = self.cast_gcref_to_int(ptrvalue)
+ self.assembler.fail_boxes[index] = intvalue
+
def get_latest_value_int(self, index):
return self.assembler.fail_boxes[index]
@@ -304,7 +282,7 @@
intvalue = self.assembler.fail_boxes[index]
return self.cast_int_to_gcref(intvalue)
- def execute_call(self, loop, func, values_as_int):
+ def execute_call(self, loop, func):
# help flow objspace
prev_interpreter = None
if not self.translate_support_code:
@@ -314,12 +292,12 @@
try:
self.caught_exception = None
#print "Entering: %d" % rffi.cast(lltype.Signed, func)
- res = func(values_as_int)
+ res = func()
+ del self.keepalives[:]
self.reraise_caught_exception()
finally:
if not self.translate_support_code:
LLInterpreter.current_interpreter = prev_interpreter
- lltype.free(values_as_int, flavor='raw')
return res
def reraise_caught_exception(self):
@@ -339,21 +317,21 @@
self._guard_list.append(guard_op)
return index
- def convert_box_to_int(self, valuebox):
- if isinstance(valuebox, ConstInt):
- return valuebox.value
- elif isinstance(valuebox, BoxInt):
- return valuebox.value
- elif isinstance(valuebox, BoxPtr):
- x = self.cast_gcref_to_int(valuebox.value)
- self.keepalives.append(valuebox.value)
- return x
- elif isinstance(valuebox, ConstPtr):
- x = self.cast_gcref_to_int(valuebox.value)
- self.keepalives.append(valuebox.value)
- return x
- else:
- raise ValueError(valuebox.type)
+# def convert_box_to_int(self, valuebox):
+# if isinstance(valuebox, ConstInt):
+# return valuebox.value
+# elif isinstance(valuebox, BoxInt):
+# return valuebox.value
+# elif isinstance(valuebox, BoxPtr):
+# x = self.cast_gcref_to_int(valuebox.value)
+# self.keepalives.append(valuebox.value)
+# return x
+# elif isinstance(valuebox, ConstPtr):
+# x = self.cast_gcref_to_int(valuebox.value)
+# self.keepalives.append(valuebox.value)
+# return x
+# else:
+# raise ValueError(valuebox.type)
# def getvaluebox(self, frameadr, guard_op, argindex):
# # XXX that's plain stupid, do we care about the return value???
@@ -558,7 +536,8 @@
num_args, size, ptr = self.unpack_calldescr(calldescr)
assert isinstance(calldescr, ConstDescr3)
loop = self._get_loop_for_call(num_args, calldescr, ptr)
- self.execute_operations(loop, args)
+ history.set_future_values(self, args)
+ self.execute_operations(loop)
# Note: if an exception is set, the rest of the code does a bit of
# nonsense but nothing wrong (the return value should be ignored)
if size == 0:
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc2.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc2.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_regalloc2.py Sun Apr 26 22:04:21 2009
@@ -19,7 +19,8 @@
]
cpu = CPU(None, None)
cpu.compile_operations(loop)
- cpu.execute_operations(loop, [BoxInt(9)])
+ cpu.set_future_value_int(0, 9)
+ cpu.execute_operations(loop)
assert cpu.get_latest_value_int(0) == (9 >> 3)
assert cpu.get_latest_value_int(1) == (~18)
@@ -40,7 +41,8 @@
]
cpu = CPU(None, None)
cpu.compile_operations(loop)
- cpu.execute_operations(loop, [BoxInt(-10)])
+ cpu.set_future_value_int(0, -10)
+ cpu.execute_operations(loop)
assert cpu.get_latest_value_int(0) == 0
assert cpu.get_latest_value_int(1) == -1000
assert cpu.get_latest_value_int(2) == 1
@@ -135,7 +137,17 @@
]
cpu = CPU(None, None)
cpu.compile_operations(loop)
- cpu.execute_operations(loop, [BoxInt(-13), BoxInt(10), BoxInt(10), BoxInt(8), BoxInt(-8), BoxInt(-16), BoxInt(-18), BoxInt(46), BoxInt(-12), BoxInt(26)])
+ cpu.set_future_value_int(0, -13)
+ cpu.set_future_value_int(1, 10)
+ cpu.set_future_value_int(2, 10)
+ cpu.set_future_value_int(3, 8)
+ cpu.set_future_value_int(4, -8)
+ cpu.set_future_value_int(5, -16)
+ cpu.set_future_value_int(6, -18)
+ cpu.set_future_value_int(7, 46)
+ cpu.set_future_value_int(8, -12)
+ cpu.set_future_value_int(9, 26)
+ cpu.execute_operations(loop)
assert cpu.get_latest_value_int(0) == 0
assert cpu.get_latest_value_int(1) == 0
assert cpu.get_latest_value_int(2) == 0
@@ -239,7 +251,17 @@
]
cpu = CPU(None, None)
cpu.compile_operations(loop)
- cpu.execute_operations(loop, [BoxInt(17), BoxInt(-20), BoxInt(-6), BoxInt(6), BoxInt(1), BoxInt(13), BoxInt(13), BoxInt(9), BoxInt(49), BoxInt(8)])
+ cpu.set_future_value_int(0, 17)
+ cpu.set_future_value_int(1, -20)
+ cpu.set_future_value_int(2, -6)
+ cpu.set_future_value_int(3, 6)
+ cpu.set_future_value_int(4, 1)
+ cpu.set_future_value_int(5, 13)
+ cpu.set_future_value_int(6, 13)
+ cpu.set_future_value_int(7, 9)
+ cpu.set_future_value_int(8, 49)
+ cpu.set_future_value_int(9, 8)
+ cpu.execute_operations(loop)
assert cpu.get_latest_value_int(0) == 0
assert cpu.get_latest_value_int(1) == 8
assert cpu.get_latest_value_int(2) == 1
Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_runner.py Sun Apr 26 22:04:21 2009
@@ -88,7 +88,9 @@
operations[-1].jump_target = loop
operations[-2].suboperations = [ResOperation(rop.FAIL, [t, z], None)]
cpu.compile_operations(loop)
- res = self.cpu.execute_operations(loop, [BoxInt(0), BoxInt(10)])
+ self.cpu.set_future_value_int(0, 0)
+ self.cpu.set_future_value_int(1, 10)
+ res = self.cpu.execute_operations(loop)
assert self.cpu.get_latest_value_int(0) == 0
assert self.cpu.get_latest_value_int(1) == 55
@@ -464,7 +466,8 @@
loop.operations = ops
loop.inputargs = [b]
self.cpu.compile_operations(loop)
- r = self.cpu.execute_operations(loop, [b])
+ self.cpu.set_future_value_ptr(0, b.value)
+ r = self.cpu.execute_operations(loop)
result = self.cpu.get_latest_value_int(0)
if guard == rop.GUARD_FALSE:
assert result == execute(self.cpu, op, [b]).value
@@ -505,7 +508,9 @@
loop.operations = ops
loop.inputargs = [i for i in (a, b) if isinstance(i, Box)]
self.cpu.compile_operations(loop)
- r = self.cpu.execute_operations(loop, loop.inputargs)
+ for i, box in enumerate(loop.inputargs):
+ self.cpu.set_future_value_int(i, box.value)
+ r = self.cpu.execute_operations(loop)
result = self.cpu.get_latest_value_int(0)
if guard == rop.GUARD_FALSE:
assert result == execute(self.cpu, op, (a, b)).value
@@ -533,7 +538,8 @@
loop.operations = ops
loop.inputargs = [base_v]
self.cpu.compile_operations(loop)
- op = self.cpu.execute_operations(loop, [base_v])
+ self.cpu.set_future_value_int(0, base_v.value)
+ op = self.cpu.execute_operations(loop)
assert self.cpu.get_latest_value_int(0) == 1024
finally:
MachineCodeBlockWrapper.MC_SIZE = orig_size
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/history.py Sun Apr 26 22:04:21 2009
@@ -203,6 +203,9 @@
def get_(self):
return self.value
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_int(j, self.value)
+
def equals(self, other):
return self.value == other.getint()
@@ -242,6 +245,9 @@
def get_(self):
return llmemory.cast_adr_to_int(self.value)
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_int(j, self.getint())
+
def equals(self, other):
return self.value == other.getaddr(self.cpu)
@@ -271,6 +277,9 @@
def getaddr(self, cpu):
return llmemory.cast_ptr_to_adr(self.value)
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_ptr(j, self.value)
+
def equals(self, other):
return self.value == other.getptr_base()
@@ -296,6 +305,9 @@
def get_(self):
return ootype.ooidentityhash(self.value) # XXX: check me
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_obj(j, self.value)
+
## def getaddr(self, cpu):
## # so far this is used only when calling
## # CodeWriter.IndirectCallset.bytecode_for_address. We don't need a
@@ -377,6 +389,9 @@
def get_(self):
return self.value
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_int(j, self.value)
+
def _getrepr_(self):
return self.value
@@ -405,6 +420,9 @@
def get_(self):
return lltype.cast_ptr_to_int(self.value)
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_ptr(j, self.value)
+
_getrepr_ = repr_pointer
changevalue_ptr = __init__
@@ -431,10 +449,17 @@
def get_(self):
return ootype.ooidentityhash(self.value) # XXX: check me
+ def set_future_value(self, cpu, j):
+ cpu.set_future_value_obj(j, self.value)
+
_getrepr_ = repr_object
changevalue_obj = __init__
+def set_future_values(cpu, boxes):
+ for j in range(len(boxes)):
+ boxes[j].set_future_value(cpu, j)
+
# ____________________________________________________________
# The TreeLoop class contains a loop or a generalized loop, i.e. a tree
Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py Sun Apr 26 22:04:21 2009
@@ -1105,19 +1105,7 @@
num_green_args = self.staticdata.num_green_args
residual_args = self.get_residual_args(loop,
gmp.argboxes[num_green_args:])
- j = 0
- cpu = self.cpu
- for box in residual_args:
- if isinstance(box, BoxInt) or isinstance(box, ConstInt):
- cpu.set_future_value_int(j, box.getint())
- elif isinstance(box, BoxPtr) or isinstance(box, ConstPtr):
- cpu.set_future_value_ptr(j, box.getptr_base())
- elif cpu.is_oo and (isinstance(box, BoxObj) or
- isinstance(box, ConstObj)):
- cpu.set_future_value_obj(j, box.getobj())
- else:
- assert False
- j += 1
+ history.set_future_values(self.cpu, residual_args)
return loop
def prepare_resume_from_failure(self, opnum):
More information about the Pypy-commit
mailing list