[pypy-svn] r63767 - in pypy/branch/pyjitpl5-simplify/pypy/jit/backend: llgraph llgraph/test test x86
fijal at codespeak.net
fijal at codespeak.net
Tue Apr 7 05:50:48 CEST 2009
Author: fijal
Date: Tue Apr 7 05:50:47 2009
New Revision: 63767
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/test/test_llgraph.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py
Log:
inverse guard value for backends. A bit of shifting for test reuse, not sure
how important is that
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py Tue Apr 7 05:50:47 2009
@@ -107,6 +107,7 @@
'guard_true' : (('bool',), None),
'guard_false' : (('bool',), None),
'guard_value' : (('int', 'int'), None),
+ 'guard_value_inverse' : (('int', 'int'), None),
'guard_class' : (('ptr', 'ptr'), None),
'guard_no_exception' : ((), None),
'guard_exception' : (('ptr',), 'ptr'),
@@ -513,6 +514,10 @@
if value != expected_value:
raise GuardFailed
+ def op_guard_value_inverse(self, _, value, expected_value):
+ if value == expected_value:
+ raise GuardFailed
+
def op_guard_nonvirtualized(self, for_accessing_field,
value, expected_class):
self.op_guard_class(-1, value, expected_class)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py Tue Apr 7 05:50:47 2009
@@ -62,6 +62,8 @@
class CPU(object):
+ fake = True
+
def __init__(self, rtyper, stats=None, translate_support_code=False,
annmixlevel=None):
self.rtyper = rtyper
@@ -136,8 +138,12 @@
llimpl.compile_add_jump_target(c, op.jump_target._compiled_version)
elif op.opnum == rop.FAIL:
llimpl.compile_add_fail(c, len(self.fail_ops))
+ self._non_failing_guard = len(self.fail_ops)
self.fail_ops.append(op)
+ def guard_failed(self):
+ return self._non_failing_guard != self._fail_index
+
def execute_operations(self, loop, valueboxes):
"""Calls the assembler generated for the given loop.
Returns the ResOperation that failed, of type rop.FAIL.
@@ -158,6 +164,7 @@
raise Exception("bad box in valueboxes: %r" % (box,))
# run the loop
fail_index = llimpl.frame_execute(frame)
+ self._fail_index = fail_index
# we hit a FAIL operation. Fish for the values
# (in a real backend, this should be done by the FAIL operation
# itself, not here)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/test/test_llgraph.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/test/test_llgraph.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/test/test_llgraph.py Tue Apr 7 05:50:47 2009
@@ -64,40 +64,6 @@
assert cpu.stats.exec_counters['int_add'] == 10
assert cpu.stats.exec_jumps == 9
- def test_passing_guards(self):
- py.test.skip("rewrite me")
- assert cpu.execute_operation(rop.GUARD_TRUE, [BoxInt(1)],
- 'void') == None
- assert cpu.execute_operation(rop.GUARD_FALSE,[BoxInt(0)],
- 'void') == None
- assert cpu.execute_operation(rop.GUARD_VALUE,[BoxInt(42), BoxInt(42)],
- 'void') == None
- #subnode = lltype.malloc(SUBNODE)
- #assert cpu.execute_operation('guard_class', [subnode, SUBNODE]) == []
- #assert cpu.stats.exec_counters == {'guard_true': 1, 'guard_false': 1,
- # 'guard_value': 1, 'guard_class': 1}
- #assert cpu.stats.exec_jumps == 0
-
- def test_failing_guards(self):
- py.test.skip("rewrite me")
- cpu.set_meta_interp(FakeMetaInterp(cpu))
- #node = ootype.new(NODE)
- #subnode = ootype.new(SUBNODE)
- for opnum, args in [(rop.GUARD_TRUE, [BoxInt(0)]),
- (rop.GUARD_FALSE, [BoxInt(1)]),
- (rop.GUARD_VALUE, [BoxInt(42), BoxInt(41)]),
- #('guard_class', [node, SUBNODE]),
- #('guard_class', [subnode, NODE]),
- ]:
- operations = [
- ResOperation(rop.MERGE_POINT, args, []),
- ResOperation(opnum, args, []),
- ResOperation(rop.VOID_RETURN, [], []),
- ]
- cpu.compile_operations(operations)
- res = cpu.execute_operations_in_new_frame('foo', operations, args)
- assert res.value == 42
-
def test_cast_adr_to_int_and_back(self):
cpu = self.cpu
X = lltype.Struct('X', ('foo', lltype.Signed))
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/test/runner.py Tue Apr 7 05:50:47 2009
@@ -123,42 +123,49 @@
def test_passing_guards(self):
vtable_for_T = lltype.malloc(MY_VTABLE, immortal=True)
+ vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
cpu = self.cpu
cpu._cache_gcstruct2vtable = {T: vtable_for_T}
for (opname, args) in [(rop.GUARD_TRUE, [BoxInt(1)]),
(rop.GUARD_FALSE, [BoxInt(0)]),
- (rop.GUARD_VALUE, [BoxInt(42), BoxInt(42)])]:
+ (rop.GUARD_VALUE, [BoxInt(42), BoxInt(42)]),
+ (rop.GUARD_VALUE_INVERSE, [BoxInt(42), BoxInt(41)])]:
assert self.execute_operation(opname, args, 'void') == None
- assert self.cpu._guard_index == -1
+ assert not self.cpu.guard_failed()
t = lltype.malloc(T)
t.parent.typeptr = vtable_for_T
t_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, t))
- T_box = ConstInt(rffi.cast(lltype.Signed, vtable_for_T))
+ T_box = ConstInt(cpu.cast_adr_to_int(vtable_for_T_addr))
null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
- assert self.execute_operation(rop.GUARD_CLASS, [t_box, T_box], 'void') == None
+ if not getattr(self.cpu, 'fake', None):
+ assert self.execute_operation(rop.GUARD_CLASS, [t_box, T_box], 'void') == None
def test_failing_guards(self):
vtable_for_T = lltype.malloc(MY_VTABLE, immortal=True)
+ vtable_for_T_addr = llmemory.cast_ptr_to_adr(vtable_for_T)
vtable_for_U = lltype.malloc(MY_VTABLE, immortal=True)
+ vtable_for_U_addr = llmemory.cast_ptr_to_adr(vtable_for_U)
cpu = self.cpu
cpu._cache_gcstruct2vtable = {T: vtable_for_T, U: vtable_for_U}
t = lltype.malloc(T)
t.parent.typeptr = vtable_for_T
t_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, t))
- T_box = ConstInt(rffi.cast(lltype.Signed, vtable_for_T))
+ T_box = ConstInt(self.cpu.cast_adr_to_int(vtable_for_T_addr))
u = lltype.malloc(U)
u.parent.parent.typeptr = vtable_for_U
u_box = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, u))
- U_box = ConstInt(rffi.cast(lltype.Signed, vtable_for_U))
+ U_box = ConstInt(self.cpu.cast_adr_to_int(vtable_for_U_addr))
null_box = ConstPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.nullptr(T)))
for opname, args in [(rop.GUARD_TRUE, [BoxInt(0)]),
(rop.GUARD_FALSE, [BoxInt(1)]),
(rop.GUARD_VALUE, [BoxInt(42), BoxInt(41)]),
(rop.GUARD_CLASS, [t_box, U_box]),
(rop.GUARD_CLASS, [u_box, T_box]),
+ (rop.GUARD_VALUE_INVERSE, [BoxInt(10), BoxInt(10)]),
]:
- assert self.execute_operation(opname, args, 'void') == None
- assert self.cpu._guard_index != -1
+ if opname != rop.GUARD_CLASS or not getattr(self.cpu, 'fake', None):
+ assert self.execute_operation(opname, args, 'void') == None
+ assert self.cpu.guard_failed()
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/assembler.py Tue Apr 7 05:50:47 2009
@@ -647,6 +647,10 @@
self.mc.CMP(locs[0], locs[1])
self.implement_guard(addr, op, self.mc.JNE)
+ def genop_guard_guard_value_inverse(self, op, ign_1, addr, locs, ign_2):
+ self.mc.CMP(locs[0], locs[1])
+ self.implement_guard(addr, op, self.mc.JE)
+
def genop_guard_guard_class(self, op, ign_1, addr, locs, ign_2):
offset = 0 # XXX for now, the vtable ptr is at the start of the obj
self.mc.CMP(mem(locs[0], offset), locs[1])
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/regalloc.py Tue Apr 7 05:50:47 2009
@@ -667,6 +667,8 @@
self.eventually_free_vars(op.inputargs)
self.eventually_free_vars(op.args)
+ consider_guard_value_inverse = consider_guard_value
+
def consider_guard_class(self, op, ignored):
x = self.make_sure_var_in_reg(op.args[0], [], imm_fine=False)
y = self.loc(op.args[1])
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/x86/runner.py Tue Apr 7 05:50:47 2009
@@ -609,6 +609,10 @@
def cast_int_to_gcref(self, x):
return rffi.cast(llmemory.GCREF, x)
+ # ---------------------------- tests ------------------------
+ def guard_failed(self):
+ return self._guard_index != -1
+
def uhex(x):
if we_are_translated():
return hex(x)
More information about the Pypy-commit
mailing list