def test_execute_varargs(): cpu = FakeCPU() descr = FakeCallDescr() argboxes = [ BoxInt(99999), BoxInt(321), constfloat(2.25), ConstInt(123), BoxPtr(), boxfloat(5.5) ] box = execute_varargs(cpu, FakeMetaInterp(), rop.CALL, argboxes, descr) assert box.getfloat() == 42.5 assert cpu.fakecalled == (99999, [321, 123], [ConstPtr.value], [ longlong.getfloatstorage(2.25), longlong.getfloatstorage(5.5) ], descr)
def test_gen_write_barrier(self): gc_ll_descr = self.gc_ll_descr llop1 = self.llop1 # rewriter = gc.GcRewriterAssembler(gc_ll_descr, None) newops = rewriter.newops v_base = BoxPtr() rewriter.gen_write_barrier(v_base) assert llop1.record == [] assert len(newops) == 1 assert newops[0].getopnum() == rop.COND_CALL_GC_WB assert newops[0].getarg(0) == v_base assert newops[0].result is None wbdescr = newops[0].getdescr() assert is_valid_int(wbdescr.jit_wb_if_flag) assert is_valid_int(wbdescr.jit_wb_if_flag_byteofs) assert is_valid_int(wbdescr.jit_wb_if_flag_singlebyte)
def _rewrite_changeable_constptrs(self, op, ops_with_movable_const_ptr, moving_obj_tracker): newops = [] for arg_i in ops_with_movable_const_ptr[op]: v = op.getarg(arg_i) # assert to make sure we got what we expected assert isinstance(v, ConstPtr) result_ptr = BoxPtr() array_index = moving_obj_tracker.get_array_index(v) load_op = ResOperation(rop.GETARRAYITEM_GC, [ moving_obj_tracker.const_ptr_gcref_array, ConstInt(array_index) ], result_ptr, descr=moving_obj_tracker.ptr_array_descr) newops.append(load_op) op.setarg(arg_i, result_ptr) # newops.append(op) return newops
def produce_into(self, builder, r): subset, f, exc = self.raising_func_code(builder, r) TP = lltype.FuncType([lltype.Signed] * len(subset), lltype.Void) ptr = llhelper(lltype.Ptr(TP), f) c_addr = ConstAddr(llmemory.cast_ptr_to_adr(ptr), builder.cpu) args = [c_addr] + subset descr = self.getcalldescr(builder, TP) self.put(builder, args, descr) while True: _, vtableptr = builder.get_random_structure_type_and_vtable(r) if vtableptr != exc: break other_box = ConstAddr(llmemory.cast_ptr_to_adr(vtableptr), builder.cpu) op = ResOperation(rop.GUARD_EXCEPTION, [other_box], BoxPtr(), descr=builder.getfaildescr()) op._exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc), builder.cpu) op.setfailargs(builder.subset_of_intvars(r)) builder.should_fail_by = op builder.guard_op = op builder.loop.operations.append(op)
def test_execute_nonspec(): cpu = FakeCPU() descr = FakeDescr() # cases with a descr # arity == -1 argboxes = [BoxInt(321), ConstInt(123)] box = execute_nonspec(cpu, FakeMetaInterp(), rop.CALL, argboxes, FakeCallDescr()) assert box.getfloat() == 42.5 # arity == 0 box = execute_nonspec(cpu, None, rop.NEW, [], descr) assert box.value.fakeargs == ('new', descr) # arity == 1 box1 = BoxPtr() box = execute_nonspec(cpu, None, rop.ARRAYLEN_GC, [box1], descr) assert box.value == 55 # arity == 2 box2 = boxfloat(222.2) fielddescr = FakeFieldDescr() execute_nonspec(cpu, None, rop.SETFIELD_GC, [box1, box2], fielddescr) assert cpu.fakesetfield == (box1.value, box2.value, fielddescr) # arity == 3 box3 = BoxInt(33) arraydescr = FakeArrayDescr() execute_nonspec(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2], arraydescr) assert cpu.fakesetarrayitem == (box1.value, box3.value, box2.value, arraydescr) # cases without descr # arity == 1 box = execute_nonspec(cpu, None, rop.INT_INVERT, [box3]) assert box.value == ~33 # arity == 2 box = execute_nonspec(cpu, None, rop.INT_LSHIFT, [box3, BoxInt(3)]) assert box.value == 33 << 3 # arity == 3 execute_nonspec(cpu, None, rop.STRSETITEM, [box1, BoxInt(3), box3]) assert cpu.fakestrsetitem == (box1.value, 3, box3.value)
def do(cpu, _, *argboxes): newargs = () for argtype in argtypes: if argtype == 'cpu': value = cpu elif argtype == 'd': value = argboxes[-1] assert isinstance(value, AbstractDescr) argboxes = argboxes[:-1] else: argbox = argboxes[0] argboxes = argboxes[1:] if argtype == 'i': value = argbox.getint() elif argtype == 'r': value = argbox.getref_base() elif argtype == 'f': value = argbox.getfloatstorage() newargs = newargs + (value, ) assert not argboxes # result = func(*newargs) # if resulttype == 'i': return BoxInt(result) if resulttype == 'r': return BoxPtr(result) if resulttype == 'f': return BoxFloat(result) return None
def test_wrap(): def _is(box1, box2): return (box1.__class__ == box2.__class__ and box1.value == box2.value) p = lltype.malloc(lltype.GcStruct('S')) po = lltype.cast_opaque_ptr(llmemory.GCREF, p) assert _is(wrap(None, 42), BoxInt(42)) assert _is(wrap(None, 42.5), boxfloat(42.5)) assert _is(wrap(None, p), BoxPtr(po)) assert _is(wrap(None, 42, in_const_box=True), ConstInt(42)) assert _is(wrap(None, 42.5, in_const_box=True), constfloat(42.5)) assert _is(wrap(None, p, in_const_box=True), ConstPtr(po)) if longlong.supports_longlong: import sys from rpython.rlib.rarithmetic import r_longlong, r_ulonglong value = r_longlong(-sys.maxint*17) assert _is(wrap(None, value), BoxFloat(value)) assert _is(wrap(None, value, in_const_box=True), ConstFloat(value)) value_unsigned = r_ulonglong(-sys.maxint*17) assert _is(wrap(None, value_unsigned), BoxFloat(value)) sfval = r_singlefloat(42.5) ival = longlong.singlefloat2int(sfval) assert _is(wrap(None, sfval), BoxInt(ival)) assert _is(wrap(None, sfval, in_const_box=True), ConstInt(ival))
def do_new_with_vtable(cpu, _, clsbox): return BoxPtr(exec_new_with_vtable(cpu, clsbox))
# do the call using the correct function from the cpu rettype = descr.get_result_type() if rettype == INT or rettype == 'S': # *S*ingle float try: result = cpu.bh_call_i(func, args_i, args_r, args_f, descr) except Exception, e: metainterp.execute_raised(e) result = 0 return BoxInt(result) if rettype == REF: try: result = cpu.bh_call_r(func, args_i, args_r, args_f, descr) except Exception, e: metainterp.execute_raised(e) result = NULL return BoxPtr(result) if rettype == FLOAT or rettype == 'L': # *L*ong long try: result = cpu.bh_call_f(func, args_i, args_r, args_f, descr) except Exception, e: metainterp.execute_raised(e) result = longlong.ZEROF return BoxFloat(result) if rettype == VOID: try: cpu.bh_call_v(func, args_i, args_r, args_f, descr) except Exception, e: metainterp.execute_raised(e) return None raise AssertionError("bad rettype")
def newrefboxes(count): return [BoxPtr() for _ in range(count)]
class LLtypeMixin(object): type_system = 'lltype' def get_class_of_box(self, box): return box.getref(rclass.OBJECTPTR).typeptr node_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True) node_vtable.name = rclass.alloc_array_name('node') node_vtable_adr = llmemory.cast_ptr_to_adr(node_vtable) node_vtable2 = lltype.malloc(OBJECT_VTABLE, immortal=True) node_vtable2.name = rclass.alloc_array_name('node2') node_vtable_adr2 = llmemory.cast_ptr_to_adr(node_vtable2) cpu = runner.LLGraphCPU(None) NODE = lltype.GcForwardReference() NODE.become(lltype.GcStruct('NODE', ('parent', OBJECT), ('value', lltype.Signed), ('floatval', lltype.Float), ('charval', lltype.Char), ('next', lltype.Ptr(NODE)))) NODE2 = lltype.GcStruct('NODE2', ('parent', NODE), ('other', lltype.Ptr(NODE))) node = lltype.malloc(NODE) node.parent.typeptr = node_vtable node2 = lltype.malloc(NODE2) node2.parent.parent.typeptr = node_vtable2 nodebox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, node)) myptr = nodebox.value myptr2 = lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(NODE)) nullptr = lltype.nullptr(llmemory.GCREF.TO) nodebox2 = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, node2)) nodesize = cpu.sizeof(NODE) nodesize2 = cpu.sizeof(NODE2) valuedescr = cpu.fielddescrof(NODE, 'value') floatdescr = cpu.fielddescrof(NODE, 'floatval') chardescr = cpu.fielddescrof(NODE, 'charval') nextdescr = cpu.fielddescrof(NODE, 'next') otherdescr = cpu.fielddescrof(NODE2, 'other') accessor = FieldListAccessor() accessor.initialize(None, {'inst_field': IR_QUASIIMMUTABLE}) QUASI = lltype.GcStruct('QUASIIMMUT', ('inst_field', lltype.Signed), ('mutate_field', rclass.OBJECTPTR), hints={'immutable_fields': accessor}) quasisize = cpu.sizeof(QUASI) quasi = lltype.malloc(QUASI, immortal=True) quasi.inst_field = -4247 quasifielddescr = cpu.fielddescrof(QUASI, 'inst_field') quasibox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, quasi)) quasiptr = quasibox.value quasiimmutdescr = QuasiImmutDescr(cpu, quasibox, quasifielddescr, cpu.fielddescrof(QUASI, 'mutate_field')) NODEOBJ = lltype.GcStruct('NODEOBJ', ('parent', OBJECT), ('ref', lltype.Ptr(OBJECT))) nodeobj = lltype.malloc(NODEOBJ) nodeobjvalue = lltype.cast_opaque_ptr(llmemory.GCREF, nodeobj) refdescr = cpu.fielddescrof(NODEOBJ, 'ref') INTOBJ_NOIMMUT = lltype.GcStruct('INTOBJ_NOIMMUT', ('parent', OBJECT), ('intval', lltype.Signed)) INTOBJ_IMMUT = lltype.GcStruct('INTOBJ_IMMUT', ('parent', OBJECT), ('intval', lltype.Signed), hints={'immutable': True}) intobj_noimmut_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True) intobj_immut_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True) noimmut_intval = cpu.fielddescrof(INTOBJ_NOIMMUT, 'intval') immut_intval = cpu.fielddescrof(INTOBJ_IMMUT, 'intval') PTROBJ_IMMUT = lltype.GcStruct('PTROBJ_IMMUT', ('parent', OBJECT), ('ptrval', lltype.Ptr(OBJECT)), hints={'immutable': True}) ptrobj_immut_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True) immut_ptrval = cpu.fielddescrof(PTROBJ_IMMUT, 'ptrval') arraydescr = cpu.arraydescrof(lltype.GcArray(lltype.Signed)) floatarraydescr = cpu.arraydescrof(lltype.GcArray(lltype.Float)) # a GcStruct not inheriting from OBJECT S = lltype.GcStruct('TUPLE', ('a', lltype.Signed), ('b', lltype.Ptr(NODE))) ssize = cpu.sizeof(S) adescr = cpu.fielddescrof(S, 'a') bdescr = cpu.fielddescrof(S, 'b') sbox = BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S))) arraydescr2 = cpu.arraydescrof(lltype.GcArray(lltype.Ptr(S))) T = lltype.GcStruct('TUPLE', ('c', lltype.Signed), ('d', lltype.Ptr(lltype.GcArray(lltype.Ptr(NODE))))) tsize = cpu.sizeof(T) cdescr = cpu.fielddescrof(T, 'c') ddescr = cpu.fielddescrof(T, 'd') arraydescr3 = cpu.arraydescrof(lltype.GcArray(lltype.Ptr(NODE))) U = lltype.GcStruct('U', ('parent', OBJECT), ('one', lltype.Ptr(lltype.GcArray(lltype.Ptr(NODE))))) u_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True) u_vtable_adr = llmemory.cast_ptr_to_adr(u_vtable) usize = cpu.sizeof(U) onedescr = cpu.fielddescrof(U, 'one') FUNC = lltype.FuncType([lltype.Signed], lltype.Signed) plaincalldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo.MOST_GENERAL) nonwritedescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [], [], [])) writeadescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [adescr], [], [])) writearraydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [adescr], [arraydescr], [])) readadescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([adescr], [], [], [], [], [])) mayforcevirtdescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([nextdescr], [], [], [], [], [], EffectInfo.EF_FORCES_VIRTUAL_OR_VIRTUALIZABLE, can_invalidate=True)) arraycopydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [arraydescr], [], [], [arraydescr], [], EffectInfo.EF_CANNOT_RAISE, oopspecindex=EffectInfo.OS_ARRAYCOPY)) raw_malloc_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [], [], [], EffectInfo.EF_CAN_RAISE, oopspecindex=EffectInfo.OS_RAW_MALLOC_VARSIZE_CHAR)) raw_free_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [], [], [], EffectInfo.EF_CANNOT_RAISE, oopspecindex=EffectInfo.OS_RAW_FREE)) chararray = lltype.GcArray(lltype.Char) chararraydescr = cpu.arraydescrof(chararray) u2array = lltype.GcArray(rffi.USHORT) u2arraydescr = cpu.arraydescrof(u2array) # array of structs (complex data) complexarray = lltype.GcArray( lltype.Struct("complex", ("real", lltype.Float), ("imag", lltype.Float), ) ) complexarraydescr = cpu.arraydescrof(complexarray) complexrealdescr = cpu.interiorfielddescrof(complexarray, "real") compleximagdescr = cpu.interiorfielddescrof(complexarray, "imag") complexarraycopydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [complexarraydescr], [], [], [complexarraydescr], [], EffectInfo.EF_CANNOT_RAISE, oopspecindex=EffectInfo.OS_ARRAYCOPY)) rawarraydescr = cpu.arraydescrof(lltype.Array(lltype.Signed, hints={'nolength': True})) rawarraydescr_char = cpu.arraydescrof(lltype.Array(lltype.Char, hints={'nolength': True})) rawarraydescr_float = cpu.arraydescrof(lltype.Array(lltype.Float, hints={'nolength': True})) fc_array = lltype.GcArray( lltype.Struct( "floatchar", ("float", lltype.Float), ("char", lltype.Char))) fc_array_descr = cpu.arraydescrof(fc_array) fc_array_floatdescr = cpu.interiorfielddescrof(fc_array, "float") fc_array_chardescr = cpu.interiorfielddescrof(fc_array, "char") for _name, _os in [ ('strconcatdescr', 'OS_STR_CONCAT'), ('strslicedescr', 'OS_STR_SLICE'), ('strequaldescr', 'OS_STR_EQUAL'), ('streq_slice_checknull_descr', 'OS_STREQ_SLICE_CHECKNULL'), ('streq_slice_nonnull_descr', 'OS_STREQ_SLICE_NONNULL'), ('streq_slice_char_descr', 'OS_STREQ_SLICE_CHAR'), ('streq_nonnull_descr', 'OS_STREQ_NONNULL'), ('streq_nonnull_char_descr', 'OS_STREQ_NONNULL_CHAR'), ('streq_checknull_char_descr', 'OS_STREQ_CHECKNULL_CHAR'), ('streq_lengthok_descr', 'OS_STREQ_LENGTHOK'), ]: _oopspecindex = getattr(EffectInfo, _os) locals()[_name] = \ cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [], [], [], EffectInfo.EF_CANNOT_RAISE, oopspecindex=_oopspecindex)) # _oopspecindex = getattr(EffectInfo, _os.replace('STR', 'UNI')) locals()[_name.replace('str', 'unicode')] = \ cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [], [], [], EffectInfo.EF_CANNOT_RAISE, oopspecindex=_oopspecindex)) s2u_descr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo([], [], [], [], [], [], oopspecindex=EffectInfo.OS_STR2UNICODE)) # class LoopToken(AbstractDescr): pass asmdescr = LoopToken() # it can be whatever, it's not a descr though from rpython.jit.metainterp.virtualref import VirtualRefInfo class FakeWarmRunnerDesc: pass FakeWarmRunnerDesc.cpu = cpu vrefinfo = VirtualRefInfo(FakeWarmRunnerDesc) virtualtokendescr = vrefinfo.descr_virtual_token virtualforceddescr = vrefinfo.descr_forced FUNC = lltype.FuncType([], lltype.Void) ei = EffectInfo([], [], [], [], [], [], EffectInfo.EF_CANNOT_RAISE, can_invalidate=False, oopspecindex=EffectInfo.OS_JIT_FORCE_VIRTUALIZABLE) clear_vable = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, ei) jit_virtual_ref_vtable = vrefinfo.jit_virtual_ref_vtable jvr_vtable_adr = llmemory.cast_ptr_to_adr(jit_virtual_ref_vtable) register_known_gctype(cpu, node_vtable, NODE) register_known_gctype(cpu, node_vtable2, NODE2) register_known_gctype(cpu, u_vtable, U) register_known_gctype(cpu, jit_virtual_ref_vtable,vrefinfo.JIT_VIRTUAL_REF) register_known_gctype(cpu, intobj_noimmut_vtable, INTOBJ_NOIMMUT) register_known_gctype(cpu, intobj_immut_vtable, INTOBJ_IMMUT) register_known_gctype(cpu, ptrobj_immut_vtable, PTROBJ_IMMUT) namespace = locals()
def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1)) sb.add_potential(ResOperation(rop.GETFIELD_GC, [BoxPtr()], self.i1)) sb.add_potential(ResOperation(rop.INT_NEG, [self.i1], self.i2)) sb.add_potential(ResOperation(rop.INT_ADD, [ConstInt(7), self.i2], self.i3))
class TestShortBoxes: p1 = BoxPtr() p2 = BoxPtr() p3 = BoxPtr() p4 = BoxPtr() i1 = BoxInt() i2 = BoxInt() i3 = BoxInt() i4 = BoxInt() def test_short_box_duplication_direct(self): class Optimizer(FakeOptimizer): def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1)) sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p2], self.i1)) sb = ShortBoxes(Optimizer(), [self.p1, self.p2]) assert len(sb.short_boxes) == 4 assert self.i1 in sb.short_boxes assert sum([op.result is self.i1 for op in sb.short_boxes.values() if op]) == 1 def test_dont_duplicate_potential_boxes(self): class Optimizer(FakeOptimizer): def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1)) sb.add_potential(ResOperation(rop.GETFIELD_GC, [BoxPtr()], self.i1)) sb.add_potential(ResOperation(rop.INT_NEG, [self.i1], self.i2)) sb.add_potential(ResOperation(rop.INT_ADD, [ConstInt(7), self.i2], self.i3)) sb = ShortBoxes(Optimizer(), [self.p1, self.p2]) assert len(sb.short_boxes) == 5 def test_prioritize1(self): class Optimizer(FakeOptimizer): def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1)) sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p2], self.i1)) sb.add_potential(ResOperation(rop.INT_NEG, [self.i1], self.i2)) sb = ShortBoxes(Optimizer(), [self.p1, self.p2]) assert len(sb.short_boxes.values()) == 5 int_neg = [op for op in sb.short_boxes.values() if op and op.getopnum() == rop.INT_NEG] assert len(int_neg) == 1 int_neg = int_neg[0] getfield = [op for op in sb.short_boxes.values() if op and op.result == int_neg.getarg(0)] assert len(getfield) == 1 assert getfield[0].getarg(0) in [self.p1, self.p2] def test_prioritize1bis(self): class Optimizer(FakeOptimizer): def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1), synthetic=True) sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p2], self.i1), synthetic=True) sb.add_potential(ResOperation(rop.INT_NEG, [self.i1], self.i2)) sb = ShortBoxes(Optimizer(), [self.p1, self.p2]) assert len(sb.short_boxes.values()) == 5 int_neg = [op for op in sb.short_boxes.values() if op and op.getopnum() == rop.INT_NEG] assert len(int_neg) == 1 int_neg = int_neg[0] getfield = [op for op in sb.short_boxes.values() if op and op.result == int_neg.getarg(0)] assert len(getfield) == 1 assert getfield[0].getarg(0) in [self.p1, self.p2] def test_prioritize2(self): class Optimizer(FakeOptimizer): def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1), synthetic=True) sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p2], self.i1)) sb.add_potential(ResOperation(rop.INT_NEG, [self.i1], self.i2)) sb = ShortBoxes(Optimizer(), [self.p1, self.p2]) assert len(sb.short_boxes.values()) == 5 int_neg = [op for op in sb.short_boxes.values() if op and op.getopnum() == rop.INT_NEG] assert len(int_neg) == 1 int_neg = int_neg[0] getfield = [op for op in sb.short_boxes.values() if op and op.result == int_neg.getarg(0)] assert len(getfield) == 1 assert getfield[0].getarg(0) == self.p2 def test_prioritize3(self): class Optimizer(FakeOptimizer): def produce_potential_short_preamble_ops(_self, sb): sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p1], self.i1)) sb.add_potential(ResOperation(rop.GETFIELD_GC, [self.p2], self.i1), synthetic=True) sb.add_potential(ResOperation(rop.INT_NEG, [self.i1], self.i2)) sb = ShortBoxes(Optimizer(), [self.p1, self.p2]) assert len(sb.short_boxes.values()) == 5 int_neg = [op for op in sb.short_boxes.values() if op and op.getopnum() == rop.INT_NEG] assert len(int_neg) == 1 int_neg = int_neg[0] getfield = [op for op in sb.short_boxes.values() if op and op.result == int_neg.getarg(0)] assert len(getfield) == 1 assert getfield[0].getarg(0) == self.p1
def test_bug_2(): cpu = CPU(None, None) cpu.setup_once() S4 = lltype.Struct('Sx', ("f0", lltype.Char), ("f1", lltype.Signed), ("f2", lltype.Signed), ("f3", lltype.Signed)) S5 = lltype.GcArray(S4) v1 = BoxInt() v2 = BoxInt() v3 = BoxInt() v4 = BoxInt() v5 = BoxInt() v6 = BoxInt() v7 = BoxInt() v8 = BoxInt() v9 = BoxInt() v10 = BoxInt() tmp11 = BoxInt() tmp12 = BoxPtr() faildescr0 = BasicFailDescr() tmp13 = BoxPtr() faildescr1 = BasicFailDescr() finishdescr2 = BasicFinalDescr() const_ptr14 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 1))) const_ptr15 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 489))) const_ptr16 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 16))) const_ptr17 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S5, 299))) inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10] xtp, func, funcdescr = getexception(cpu, 3) xtp2, func2, func2descr = getexception(cpu, 2) operations = [ ResOperation(rop.STRGETITEM, [const_ptr14, ConstInt(0)], tmp11), ResOperation(rop.LABEL, [v1, v2, tmp11, v3, v4, v5, v6, v7, v8, v9, v10], None, TargetToken()), ResOperation(rop.UNICODESETITEM, [const_ptr15, v4, ConstInt(22)], None), ResOperation(rop.CALL, [ConstInt(func), v2, v1, v9], None, descr=funcdescr), ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp)], tmp12, descr=faildescr0), ResOperation( rop.UNICODESETITEM, [const_ptr16, ConstInt(13), ConstInt(9)], None), ResOperation(rop.SETINTERIORFIELD_GC, [const_ptr17, v3, v7], None, cpu.interiorfielddescrof(S5, 'f3')), ResOperation(rop.CALL, [ConstInt(func2), v7, v10], None, descr=func2descr), ResOperation(rop.GUARD_NO_EXCEPTION, [], tmp13, descr=faildescr1), ResOperation(rop.FINISH, [], None, descr=finishdescr2), ] operations[4].setfailargs([v4, v8, v10, v2, v9, v7, v6, v1]) operations[8].setfailargs([v3, v9, v2, v6, v4]) looptoken = JitCellToken() cpu.compile_loop(inputargs, operations, looptoken) loop_args = [1, -39, 46, 21, 16, 6, -4611686018427387905, 12, 14, 2] frame = cpu.execute_token(looptoken, *loop_args) assert cpu.get_int_value(frame, 0) == 46 assert cpu.get_int_value(frame, 1) == 14 assert cpu.get_int_value(frame, 2) == -39 assert cpu.get_int_value(frame, 3) == 6 assert cpu.get_int_value(frame, 4) == 21 S4 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT), ("f0", lltype.Signed)) S5 = lltype.GcStruct('Sx', ("f0", lltype.Signed)) S6 = lltype.GcArray(lltype.Signed) S7 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT), ("f0", lltype.Char)) S8 = lltype.Struct('Sx', ("f0", lltype.Char), ("f1", lltype.Signed), ("f2", lltype.Signed), ("f3", lltype.Signed)) S9 = lltype.GcArray(S8) v1 = BoxInt() v2 = BoxInt() v3 = BoxInt() v4 = BoxInt() v5 = BoxInt() v6 = BoxInt() v7 = BoxInt() v8 = BoxInt() v9 = BoxInt() v10 = BoxInt() v11 = BoxInt() v12 = BoxInt() v13 = BoxInt() v14 = BoxInt() v15 = BoxInt() v16 = BoxInt() v17 = BoxInt() v18 = BoxInt() v19 = BoxInt() p20 = BoxPtr() tmp21 = BoxPtr() faildescr3 = BasicFailDescr() tmp22 = BoxPtr() faildescr4 = BasicFailDescr() tmp23 = BoxInt() tmp24 = BoxInt() tmp25 = BoxInt() tmp26 = BoxInt() tmp27 = BoxInt() tmp28 = BoxInt() tmp29 = BoxInt() faildescr5 = BasicFailDescr() tmp30 = BoxPtr() faildescr6 = BasicFailDescr() finishdescr7 = BasicFinalDescr() const_ptr31 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S4))) const_ptr32 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 46))) const_ptr33 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S5))) const_ptr34 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 26))) const_ptr35 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 15))) const_ptr36 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S7))) const_ptr37 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 484))) const_ptr38 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S9, 299))) inputargs = [v1, v2, v3, v4, v5] func3, func3descr = getnoexception(cpu, 5) xtp3, func4, func4descr = getexception(cpu, 10) operations = [ ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp2)], tmp21, descr=faildescr3), ResOperation(rop.INT_IS_ZERO, [v4], v6), ResOperation(rop.INT_NE, [v6, ConstInt(13)], v7), ResOperation(rop.GETFIELD_GC, [const_ptr31], v8, cpu.fielddescrof(S4, 'f0')), ResOperation(rop.STRSETITEM, [const_ptr32, v6, ConstInt(0)], None), ResOperation(rop.NEWSTR, [ConstInt(5)], tmp22), ResOperation(rop.STRSETITEM, [tmp22, ConstInt(0), ConstInt(42)], None), ResOperation(rop.STRSETITEM, [tmp22, ConstInt(1), ConstInt(42)], None), ResOperation(rop.STRSETITEM, [tmp22, ConstInt(2), ConstInt(20)], None), ResOperation(rop.STRSETITEM, [tmp22, ConstInt(3), ConstInt(48)], None), ResOperation(rop.STRSETITEM, [tmp22, ConstInt(4), ConstInt(6)], None), ResOperation(rop.GETFIELD_GC, [const_ptr33], v9, cpu.fielddescrof(S5, 'f0')), ResOperation(rop.UNICODESETITEM, [const_ptr34, ConstInt(24), ConstInt(65533)], None), ResOperation(rop.GETFIELD_GC, [const_ptr31], v10, cpu.fielddescrof(S4, 'f0')), ResOperation(rop.INT_NE, [v10, ConstInt(25)], v11), ResOperation(rop.CALL, [ConstInt(func3), v5, v1, v8, v3, v2], v12, descr=func3descr), ResOperation(rop.GUARD_NO_EXCEPTION, [], None, descr=faildescr4), ResOperation(rop.UNICODELEN, [const_ptr35], tmp23), ResOperation(rop.NEW_ARRAY, [v2], p20, cpu.arraydescrof(S6)), ResOperation(rop.GETFIELD_GC, [const_ptr36], v13, cpu.fielddescrof(S7, 'f0')), ResOperation(rop.INT_OR, [v8, ConstInt(2)], tmp24), ResOperation(rop.INT_FLOORDIV, [ConstInt(8), tmp24], v14), ResOperation(rop.GETARRAYITEM_GC, [p20, ConstInt(3)], v15, cpu.arraydescrof(S6)), ResOperation( rop.COPYSTRCONTENT, [tmp22, const_ptr37, ConstInt(1), ConstInt(163), ConstInt(0)], None), ResOperation(rop.COPYUNICODECONTENT, [const_ptr35, const_ptr34, ConstInt(13), ConstInt(0), v6], None), ResOperation(rop.STRGETITEM, [tmp22, v6], tmp25), ResOperation(rop.STRGETITEM, [tmp22, ConstInt(0)], tmp26), ResOperation(rop.GETINTERIORFIELD_GC, [const_ptr38, v13], v16, cpu.interiorfielddescrof(S9, 'f0')), ResOperation(rop.INT_GE, [v4, v5], v17), ResOperation(rop.INT_OR, [v13, ConstInt(2)], tmp27), ResOperation(rop.INT_FLOORDIV, [ConstInt(12), tmp27], v18), ResOperation(rop.INT_AND, [v1, ConstInt(-4)], tmp28), ResOperation(rop.INT_OR, [tmp28, ConstInt(2)], tmp29), ResOperation(rop.INT_FLOORDIV, [v15, tmp29], v19), ResOperation(rop.GUARD_FALSE, [v17], None, descr=faildescr5), ResOperation(rop.UNICODESETITEM, [const_ptr34, ConstInt(20), ConstInt(65522)], None), ResOperation( rop.CALL, [ConstInt(func4), v3, v9, v10, v8, v11, v5, v13, v14, v15, v6], None, descr=func4descr), ResOperation(rop.GUARD_NO_EXCEPTION, [], tmp30, descr=faildescr6), ResOperation(rop.FINISH, [], None, descr=finishdescr7), ] operations[0].setfailargs([]) operations[16].setfailargs([v5, v9]) operations[34].setfailargs([]) operations[37].setfailargs([v12, v19, v10, v7, v4, v8, v18, v15, v9]) cpu.compile_bridge(faildescr1, inputargs, operations, looptoken) frame = cpu.execute_token(looptoken, *loop_args) #assert cpu.get_int_value(frame, 0) == -9223372036854775766 assert cpu.get_int_value(frame, 1) == 0 #assert cpu.get_int_value(frame, 2) == -9223372036854775808 assert cpu.get_int_value(frame, 3) == 1 assert cpu.get_int_value(frame, 4) == 6 #assert cpu.get_int_value(frame, 5) == -9223372036854775808 assert cpu.get_int_value(frame, 6) == 0 assert cpu.get_int_value(frame, 7) == 0 #assert cpu.get_int_value(frame, 8) == 26 S4 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT), ("f0", lltype.Signed), ("f1", lltype.Signed)) S5 = lltype.GcStruct('Sx', ("parent", rclass.OBJECT), ("f0", lltype.Signed)) S6 = lltype.GcStruct('Sx', ("f0", lltype.Signed), ("f1", rffi.UCHAR)) v1 = BoxInt() v2 = BoxInt() v3 = BoxInt() v4 = BoxInt() v5 = BoxInt() v6 = BoxInt() v7 = BoxInt() v8 = BoxInt() v9 = BoxInt() v10 = BoxInt() v11 = BoxInt() v12 = BoxInt() v13 = BoxInt() v14 = BoxInt() v15 = BoxInt() v16 = BoxInt() v17 = BoxInt() v18 = BoxInt() tmp19 = BoxPtr() faildescr8 = BasicFailDescr() tmp20 = BoxInt() tmp21 = BoxInt() tmp22 = BoxInt() tmp23 = BoxInt() faildescr9 = BasicFailDescr() tmp24 = BoxInt() tmp25 = BoxInt() tmp26 = BoxInt() tmp27 = BoxPtr() tmp28 = BoxPtr() faildescr10 = BasicFailDescr() finishdescr11 = BasicFinalDescr() const_ptr29 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S4))) const_ptr30 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 26))) const_ptr31 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.UNICODE, 1))) const_ptr32 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S5))) const_ptr33 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(S6))) const_ptr34 = ConstPtr( lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(rstr.STR, 26))) inputargs = [v1, v2, v3, v4, v5, v6, v7, v8, v9] operations = [ ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp3)], tmp19, descr=faildescr8), ResOperation(rop.SETFIELD_GC, [const_ptr29, v7], None, cpu.fielddescrof(S4, 'f0')), ResOperation(rop.UNICODEGETITEM, [const_ptr30, ConstInt(21)], tmp20), ResOperation(rop.UNICODEGETITEM, [const_ptr30, ConstInt(10)], tmp21), ResOperation(rop.UINT_RSHIFT, [v9, ConstInt(40)], v10), ResOperation(rop.UNICODEGETITEM, [const_ptr30, ConstInt(25)], tmp22), ResOperation(rop.INT_NE, [ConstInt(-8), v9], v11), ResOperation(rop.INT_MUL_OVF, [v3, ConstInt(-4)], tmp23), ResOperation(rop.GUARD_OVERFLOW, [], None, descr=faildescr9), ResOperation(rop.UNICODESETITEM, [const_ptr31, ConstInt(0), ConstInt(50175)], None), ResOperation(rop.UINT_GT, [v8, ConstInt(-6)], v12), ResOperation(rop.GETFIELD_GC, [const_ptr32], v13, cpu.fielddescrof(S5, 'f0')), ResOperation(rop.INT_AND, [ConstInt(8), v8], v14), ResOperation(rop.INT_INVERT, [v1], v15), ResOperation(rop.SETFIELD_GC, [const_ptr33, ConstInt(3)], None, cpu.fielddescrof(S6, 'f1')), ResOperation(rop.INT_GE, [v14, v6], v16), ResOperation(rop.INT_AND, [v5, ConstInt(-4)], tmp24), ResOperation(rop.INT_OR, [tmp24, ConstInt(2)], tmp25), ResOperation(rop.INT_FLOORDIV, [v9, tmp25], v17), ResOperation(rop.STRLEN, [const_ptr34], tmp26), ResOperation(rop.NEWSTR, [ConstInt(7)], tmp27), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(0), ConstInt(21)], None), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(1), ConstInt(79)], None), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(2), ConstInt(7)], None), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(3), ConstInt(2)], None), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(4), ConstInt(229)], None), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(5), ConstInt(233)], None), ResOperation(rop.STRSETITEM, [tmp27, ConstInt(6), ConstInt(208)], None), ResOperation(rop.INT_LT, [ConstInt(-31), v10], v18), ResOperation(rop.SAME_AS, [ConstPtr(lltype.nullptr(llmemory.GCREF.TO))], tmp28), ResOperation(rop.GUARD_NONNULL_CLASS, [tmp28, ConstInt(xtp2)], None, descr=faildescr10), ResOperation(rop.FINISH, [v4], None, descr=finishdescr11), ] operations[0].setfailargs([]) operations[8].setfailargs([tmp23, v5, v3, v11, v6]) operations[30].setfailargs([v6]) cpu.compile_bridge(faildescr6, inputargs, operations, looptoken) frame = cpu.execute_token(looptoken, *loop_args) #assert cpu.get_int_value(frame, 0) == -9223372036854775808 v1 = BoxInt() v2 = BoxInt() p3 = BoxPtr() tmp4 = BoxInt() tmp5 = BoxPtr() faildescr12 = BasicFailDescr() finishdescr13 = BasicFinalDescr() inputargs = [v1] _, func5, func5descr = getexception(cpu, 0) vt = getvtable(cpu, S4) operations = [ ResOperation(rop.INT_AND, [v1, ConstInt(63)], tmp4), ResOperation(rop.INT_LSHIFT, [ConstInt(10), tmp4], v2), ResOperation(rop.NEW_WITH_VTABLE, [ConstInt(vt)], p3), ResOperation(rop.CALL, [ConstInt(func5)], None, descr=func5descr), ResOperation(rop.GUARD_EXCEPTION, [ConstInt(xtp2)], tmp5, descr=faildescr12), ResOperation(rop.FINISH, [], None, descr=finishdescr13), ] operations[4].setfailargs([v2]) cpu.compile_bridge(faildescr10, inputargs, operations, looptoken) frame = cpu.execute_token(looptoken, *loop_args)