示例#1
0
def test_known_classes():
    cls = FakeClass()
    box1 = InputArgRef()
    box1.set_forwarded(InstancePtrInfo(known_class=cls))
    box2 = InputArgRef()
    box3 = InputArgRef()
    optimizer = FakeOptimizer()

    numb_state = NumberingState(4)
    numb_state.append_int(1)  # size of resume block
    liveboxes = [InputArgInt(), box2, box1, box3]

    serialize_optimizer_knowledge(optimizer, numb_state, liveboxes, {}, None)

    assert unpack_numbering(
        numb_state.create_numbering()) == [1, 0b010000, 0, 0, 0]

    rbox1 = InputArgRef()
    rbox2 = InputArgRef()
    rbox3 = InputArgRef()
    after_optimizer = FakeOptimizer(cpu=FakeCPU({rbox1: cls}))
    deserialize_optimizer_knowledge(after_optimizer,
                                    FakeStorage(numb_state.create_numbering()),
                                    [InputArgInt(), rbox2, rbox1, rbox3],
                                    liveboxes)
    assert box1 in after_optimizer.constant_classes
    assert box2 not in after_optimizer.constant_classes
    assert box3 not in after_optimizer.constant_classes
示例#2
0
 def test_pure_ops_does_not_work(self):
     i0 = InputArgInt()
     i1 = InputArgInt()
     op = ResOperation(rop.INT_ADD, [i0, i1])
     sb = ShortBoxes()
     short_boxes = sb.create_short_boxes(Opt([op]), [i0], [i0])
     assert len(short_boxes) == 1 # just inparg
示例#3
0
 def test_nullity_with_guard(self):
     allops = [rop.INT_IS_TRUE]
     guards = [rop.GUARD_TRUE, rop.GUARD_FALSE]
     p = lltype.cast_opaque_ptr(llmemory.GCREF,
                                lltype.malloc(lltype.GcStruct('x')))
     nullptr = lltype.nullptr(llmemory.GCREF.TO)
     f = InputArgInt()
     for op in allops:
         for guard in guards:
             if op == rop.INT_IS_TRUE:
                 bp = InputArgInt(1)
                 n = InputArgInt(0)
             else:
                 bp = InputArgRef(p)
                 n = InputArgRef(nullptr)
             for b in (bp, n):
                 i1 = ResOperation(rop.SAME_AS_I, [ConstInt(1)])
                 f = ResOperation(op, [b])
                 ops = [
                     i1,
                     f,
                     ResOperation(guard, [f], descr=BasicFailDescr()),
                     ResOperation(rop.FINISH, [ConstInt(0)],
                                  descr=BasicFinalDescr()),
                 ]
                 ops[-2].setfailargs([i1])
                 looptoken = JitCellToken()
                 self.cpu.compile_loop([b], ops, looptoken)
                 deadframe = self.cpu.execute_token(looptoken, b.getint())
                 result = self.cpu.get_int_value(deadframe, 0)
                 if guard == rop.GUARD_FALSE:
                     assert result == execute(self.cpu, None, op, None, b)
                 else:
                     assert result != execute(self.cpu, None, op, None, b)
示例#4
0
文件: test_pool.py 项目: soIu/rpython
 def test_constants_arith(self, opnum):
     for c1 in [ConstInt(1), ConstInt(2**44), InputArgInt(1)]:
         for c2 in [InputArgInt(1), ConstInt(-2**33), ConstInt(2**55)]:
             self.ensure_can_hold(opnum, [c1, c2])
             if c1.is_constant() and not -2**31 <= c1.getint() <= 2**31 - 1:
                 assert self.const_in_pool(c1)
             if c2.is_constant() and not -2**31 <= c1.getint() <= 2**31 - 1:
                 assert self.const_in_pool(c2)
示例#5
0
 def test_frame_manager_basic(self):
     b0, b1 = newboxes(0, 1)
     fm = TFrameManager()
     loc0 = fm.loc(b0)
     assert fm.get_loc_index(loc0) == 0
     #
     assert fm.get(b1) is None
     loc1 = fm.loc(b1)
     assert fm.get_loc_index(loc1) == 1
     assert fm.get(b1) == loc1
     #
     loc0b = fm.loc(b0)
     assert loc0b == loc0
     #
     fm.loc(InputArgInt())
     assert fm.get_frame_depth() == 3
     #
     f0 = InputArgFloat()
     locf0 = fm.loc(f0)
     # can't be odd
     assert fm.get_loc_index(locf0) == 4
     assert fm.get_frame_depth() == 6
     #
     f1 = InputArgFloat()
     locf1 = fm.loc(f1)
     assert fm.get_loc_index(locf1) == 6
     assert fm.get_frame_depth() == 8
     fm.mark_as_free(b1)
     assert fm.freelist
     b2 = InputArgInt()
     fm.loc(b2) # should be in the same spot as b1 before
     assert fm.get(b1) is None
     assert fm.get(b2) == loc1
     fm.mark_as_free(b0)
     p0 = InputArgRef()
     ploc = fm.loc(p0)
     assert fm.get_loc_index(ploc) == 0
     assert fm.get_frame_depth() == 8
     assert ploc != loc1
     p1 = InputArgRef()
     p1loc = fm.loc(p1)
     assert fm.get_loc_index(p1loc) == 3
     assert fm.get_frame_depth() == 8
     fm.mark_as_free(p0)
     p2 = InputArgRef()
     p2loc = fm.loc(p2)
     assert p2loc == ploc
     assert len(fm.freelist) == 0
     fm.mark_as_free(b2)
     f3 = InputArgFloat()
     fm.mark_as_free(p2)
     floc = fm.loc(f3)
     assert fm.get_loc_index(floc) == 0
     for box in fm.bindings.keys():
         fm.mark_as_free(box)
示例#6
0
def get_int_tests():
    for opnum, args, retvalue in (list(_int_binary_operations()) +
                                  list(_int_comparison_operations()) +
                                  list(_int_unary_operations())):
        yield opnum, [InputArgInt(x) for x in args], retvalue
        if len(args) > 1:
            assert len(args) == 2
            yield opnum, [InputArgInt(args[0]), ConstInt(args[1])], retvalue
            yield opnum, [ConstInt(args[0]), InputArgInt(args[1])], retvalue
            if args[0] == args[1]:
                commonbox = InputArgInt(args[0])
                yield opnum, [commonbox, commonbox], retvalue
示例#7
0
    def test_stringitems(self):
        from rpython.rtyper.lltypesystem.rstr import STR
        ofs = symbolic.get_field_token(STR, 'chars', False)[0]
        ofs_items = symbolic.get_field_token(STR.chars, 'items', False)[0]

        res = self.execute_operation(rop.NEWSTR, [ConstInt(10)], 'ref')
        self.execute_operation(rop.STRSETITEM, [InputArgRef(res), ConstInt(2), ConstInt(ord('d'))], 'void')
        resbuf = self._resbuf(res, ctypes.c_char)
        assert resbuf[ofs + ofs_items + 2] == 'd'
        self.execute_operation(rop.STRSETITEM, [InputArgRef(res), InputArgInt(2), ConstInt(ord('z'))], 'void')
        assert resbuf[ofs + ofs_items + 2] == 'z'
        r = self.execute_operation(rop.STRGETITEM, [InputArgRef(res), InputArgInt(2)], 'int')
        assert r == ord('z')
示例#8
0
    def test_getfield_setfield(self):
        TP = lltype.GcStruct('x', ('s', lltype.Signed),
                             ('i', rffi.INT),
                             ('f', lltype.Float),
                             ('u', rffi.USHORT),
                             ('c1', lltype.Char),
                             ('c2', lltype.Char),
                             ('c3', lltype.Char))
        res = InputArgRef(self.execute_operation(rop.NEW, [],
                                     'ref', self.cpu.sizeof(TP)))
        ofs_s = self.cpu.fielddescrof(TP, 's')
        ofs_i = self.cpu.fielddescrof(TP, 'i')
        #ofs_f = self.cpu.fielddescrof(TP, 'f')
        ofs_u = self.cpu.fielddescrof(TP, 'u')
        ofsc1 = self.cpu.fielddescrof(TP, 'c1')
        ofsc2 = self.cpu.fielddescrof(TP, 'c2')
        ofsc3 = self.cpu.fielddescrof(TP, 'c3')
        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(3)], 'void',
                               ofs_s)
        # XXX ConstFloat
        #self.execute_operation(rop.SETFIELD_GC, [res, ofs_f, 1e100], 'void')
        # XXX we don't support shorts (at all)
        #self.execute_operation(rop.SETFIELD_GC, [res, ofs_u, ConstInt(5)], 'void')
        s = self.execute_operation(rop.GETFIELD_GC_I, [res], 'int', ofs_s)
        assert s == 3
        self.execute_operation(rop.SETFIELD_GC, [res, InputArgInt(3)], 'void',
                               ofs_s)
        s = self.execute_operation(rop.GETFIELD_GC_I, [res], 'int', ofs_s)
        assert s == 3

        self.execute_operation(rop.SETFIELD_GC, [res, InputArgInt(1234)], 'void', ofs_i)
        i = self.execute_operation(rop.GETFIELD_GC_I, [res], 'int', ofs_i)
        assert i == 1234

        #u = self.execute_operation(rop.GETFIELD_GC, [res, ofs_u], 'int')
        #assert u.value == 5
        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(1)], 'void',
                               ofsc1)
        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(3)], 'void',
                               ofsc3)
        self.execute_operation(rop.SETFIELD_GC, [res, ConstInt(2)], 'void',
                               ofsc2)
        c = self.execute_operation(rop.GETFIELD_GC_I, [res], 'int', ofsc1)
        assert c == 1
        c = self.execute_operation(rop.GETFIELD_GC_I, [res], 'int', ofsc2)
        assert c == 2
        c = self.execute_operation(rop.GETFIELD_GC_I, [res], 'int', ofsc3)
        assert c == 3
示例#9
0
def test_execute():
    cpu = FakeCPU()
    descr = FakeDescr()
    box = execute(cpu, None, rop.INT_ADD, None, InputArgInt(40), ConstInt(2))
    assert box == 42
    box = execute(cpu, None, rop.NEW, descr)
    assert box.fakeargs == ('new', descr)
示例#10
0
 def __init__(self, cpu, builder_factory, r, startvars=None, output=None):
     self.cpu = cpu
     self.output = output
     if startvars is None:
         startvars = []
         if cpu.supports_floats:
             # pick up a single threshold for the whole 'inputargs', so
             # that some loops have no or mostly no FLOATs while others
             # have a lot of them
             k = r.random()
             # but make sure there is at least one INT
             at_least_once = r.randrange(0, pytest.config.option.n_vars)
         else:
             k = -1
             at_least_once = 0
         for i in range(pytest.config.option.n_vars):
             if r.random() < k and i != at_least_once:
                 startvars.append(InputArgFloat(r.random_float_storage()))
             else:
                 startvars.append(InputArgInt(r.random_integer()))
         allow_delay = True
     else:
         allow_delay = False
     assert len(dict.fromkeys(startvars)) == len(startvars)
     self.startvars = startvars
     self.prebuilt_ptr_consts = []
     self.r = r
     self.subloops = []
     self.build_random_loop(cpu, builder_factory, r, startvars, allow_delay)
示例#11
0
    def test_call_many_float_args(self):
        from rpython.rtyper.annlowlevel import llhelper
        from rpython.jit.codewriter.effectinfo import EffectInfo

        seen = []

        def func(*args):
            seen.append(args)
            return -42

        F = lltype.Float
        I = lltype.Signed
        FUNC = self.FuncType([F] * 7 + [I] + [F] * 7 + [I] + [F], I)
        FPTR = self.Ptr(FUNC)
        func_ptr = llhelper(FPTR, func)
        cpu = self.cpu
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                    EffectInfo.MOST_GENERAL)
        funcbox = self.get_funcbox(cpu, func_ptr)
        argvals = [.1 * i for i in range(15)]
        argvals.insert(7, 77)
        argvals.insert(15, 1515)
        argvals = tuple(argvals)
        argboxes = []
        for x in argvals:
            if isinstance(x, float):
                argboxes.append(InputArgFloat(x))
            else:
                argboxes.append(InputArgInt(x))
        res = self.execute_operation(rop.CALL_I, [funcbox] + argboxes,
                                     'int',
                                     descr=calldescr)
        assert res == -42
        assert seen == [argvals]
示例#12
0
def get_float_tests(cpu):
    if not cpu.supports_floats:
        py.test.skip("requires float support from the backend")
    for opnum, args, rettype, retvalue in (
            list(_float_binary_operations()) +
            list(_float_comparison_operations()) +
            list(_float_unary_operations())):
        boxargs = []
        for x in args:
            if isinstance(x, float):
                boxargs.append(boxfloat(x))
            else:
                boxargs.append(InputArgInt(x))
        yield opnum, boxargs, rettype, retvalue
        if len(args) > 1:
            assert len(args) == 2
            yield opnum, [boxargs[0],
                          wrap_constant(boxargs[1].getvalue())
                          ], rettype, retvalue
            yield opnum, [wrap_constant(boxargs[0].getvalue()),
                          boxargs[1]], rettype, retvalue
            if (isinstance(args[0], float) and isinstance(args[1], float)
                    and args[0] == args[1]):
                commonbox = boxfloat(args[0])
                yield opnum, [commonbox, commonbox], rettype, retvalue
示例#13
0
 def test_result_is_spilled(self):
     cpu = self.cpu
     inp = [InputArgInt(i) for i in range(1, 15)]
     looptoken = JitCellToken()
     targettoken = TargetToken()
     operations = [
         ResOperation(rop.LABEL, inp, descr=targettoken),
         ResOperation(rop.INT_ADD, [inp[0], inp[1]]),
         ResOperation(rop.INT_ADD, [inp[2], inp[3]]),
         ResOperation(rop.INT_ADD, [inp[4], inp[5]]),
         ResOperation(rop.INT_ADD, [inp[6], inp[7]]),
         ResOperation(rop.INT_ADD, [inp[8], inp[9]]),
         ResOperation(rop.INT_ADD, [inp[10], inp[11]]),
         ResOperation(rop.INT_ADD, [inp[12], inp[13]]),
         ResOperation(rop.INT_ADD, [inp[0], inp[1]]),
         ResOperation(rop.INT_ADD, [inp[2], inp[3]]),
         ResOperation(rop.INT_ADD, [inp[4], inp[5]]),
         ResOperation(rop.INT_ADD, [inp[6], inp[7]]),
         ResOperation(rop.INT_ADD, [inp[8], inp[9]]),
         ResOperation(rop.INT_ADD, [inp[10], inp[11]]),
         ResOperation(rop.INT_ADD, [inp[12], inp[13]]),
         ResOperation(rop.GUARD_FALSE, [inp[1]], descr=BasicFailDescr(1)),
         ResOperation(rop.FINISH, [inp[1]], descr=BasicFinalDescr(1)),
     ]
     operations[-2].setfailargs(operations[1:15])
     cpu.compile_loop(inp, operations, looptoken)
     args = [i for i in range(1, 15)]
     deadframe = self.cpu.execute_token(looptoken, *args)
     output = [
         self.cpu.get_int_value(deadframe, i - 1) for i in range(1, 15)
     ]
     expected = [3, 7, 11, 15, 19, 23, 27, 3, 7, 11, 15, 19, 23, 27]
     assert output == expected
示例#14
0
    def test_allocations(self):
        py.test.skip("rewrite or kill")
        from rpython.rtyper.lltypesystem import rstr

        allocs = [None]
        all = []
        orig_new = self.cpu.gc_ll_descr.funcptr_for_new

        def f(size):
            allocs.insert(0, size)
            return orig_new(size)

        self.cpu.assembler.setup_once()
        self.cpu.gc_ll_descr.funcptr_for_new = f
        ofs = symbolic.get_field_token(rstr.STR, 'chars', False)[0]

        res = self.execute_operation(rop.NEWSTR, [ConstInt(7)], 'ref')
        assert allocs[0] == 7 + ofs + WORD
        resbuf = self._resbuf(res)
        assert resbuf[ofs / WORD] == 7

        # ------------------------------------------------------------

        res = self.execute_operation(rop.NEWSTR, [InputArgInt(7)], 'ref')
        assert allocs[0] == 7 + ofs + WORD
        resbuf = self._resbuf(res)
        assert resbuf[ofs / WORD] == 7

        # ------------------------------------------------------------

        TP = lltype.GcArray(lltype.Signed)
        ofs = symbolic.get_field_token(TP, 'length', False)[0]
        descr = self.cpu.arraydescrof(TP)

        res = self.execute_operation(rop.NEW_ARRAY, [ConstInt(10)], 'ref',
                                     descr)
        assert allocs[0] == 10 * WORD + ofs + WORD
        resbuf = self._resbuf(res)
        assert resbuf[ofs / WORD] == 10

        # ------------------------------------------------------------

        res = self.execute_operation(rop.NEW_ARRAY, [InputArgInt(10)], 'ref',
                                     descr)
        assert allocs[0] == 10 * WORD + ofs + WORD
        resbuf = self._resbuf(res)
        assert resbuf[ofs / WORD] == 10
示例#15
0
def test_execute_varargs():
    cpu = FakeCPU()
    descr = FakeCallDescr()
    argboxes = [
        InputArgInt(99999),
        InputArgInt(321),
        constfloat(2.25),
        ConstInt(123),
        InputArgRef(),
        boxfloat(5.5)
    ]
    box = execute_varargs(cpu, FakeMetaInterp(), rop.CALL_F, argboxes, descr)
    assert longlong.getrealfloat(box) == 42.5
    assert cpu.fakecalled == (99999, [321, 123], [ConstPtr.value], [
        longlong.getfloatstorage(2.25),
        longlong.getfloatstorage(5.5)
    ], descr)
示例#16
0
def boxes_and_longevity(num):
    res = []
    longevity = {}
    for i in range(num):
        box = InputArgInt(0)
        res.append(box)
        longevity[box] = Lifetime(0, 1)
    return res, longevity
示例#17
0
 def get_runtime_field(self, box, descr):
     struct = box.getref_base()
     if descr.is_pointer_field():
         return InputArgRef(self.cpu.bh_getfield_gc_r(struct, descr))
     elif descr.is_float_field():
         return InputArgFloat(self.cpu.bh_getfield_gc_f(struct, descr))
     else:
         return InputArgInt(self.cpu.bh_getfield_gc_i(struct, descr))
示例#18
0
 def get_runtime_item(self, box, descr, i):
     array = box.getref_base()
     if descr.is_array_of_pointers():
         return InputArgRef(self.cpu.bh_getarrayitem_gc_r(array, i, descr))
     elif descr.is_array_of_floats():
         return InputArgFloat(self.cpu.bh_getarrayitem_gc_f(array, i, descr))
     else:
         return InputArgInt(self.cpu.bh_getarrayitem_gc_i(array, i, descr))
示例#19
0
 def test_and_mask_common_patterns(self):
     cases = [8, 16, 24]
     if WORD == 8:
         cases.append(32)
     for i in cases:
         box = InputArgInt(0xAAAAAAAAAAAA)
         res = self.execute_operation(rop.INT_AND,
                                      [box, ConstInt(2**i - 1)], 'int')
         assert res == 0xAAAAAAAAAAAA & (2**i - 1)
示例#20
0
 def test_ll_arraycopy_differing_descrs_nonconst_index(self):
     h = HeapCache()
     box1 = RefFrontendOp(1)
     box2 = RefFrontendOp(2)
     box3 = RefFrontendOp(3)
     h.setarrayitem(box1, index1, box2, descr2)
     assert h.getarrayitem(box1, index1, descr2) is box2
     h.invalidate_caches(rop.CALL_N, arraycopydescr1,
                         [None, box3, box2, index1, index1,
                          InputArgInt()])
     assert h.getarrayitem(box1, index1, descr2) is box2
示例#21
0
 def test_execute_ptr_operation(self):
     cpu = self.cpu
     u_box, _, _ = self.alloc_instance(U)
     u = u_box.getref(lltype.Ptr(U))
     ofs = cpu.fielddescrof(S, 'value')
     assert self.execute_operation(rop.SETFIELD_GC,
                                   [u_box, InputArgInt(3)], 'void',
                                   ofs) == None
     assert u.parent.parent.value == 3
     u.parent.parent.value += 100
     assert (self.execute_operation(rop.GETFIELD_GC_I, [u_box], 'int',
                                    ofs) == 103)
示例#22
0
文件: compile.py 项目: Mu-L/pypy
def compile_tmp_callback(cpu,
                         jitdriver_sd,
                         greenboxes,
                         redargtypes,
                         memory_manager=None):
    """Make a LoopToken that corresponds to assembler code that just
    calls back the interpreter.  Used temporarily: a fully compiled
    version of the code may end up replacing it.
    """
    jitcell_token = make_jitcell_token(jitdriver_sd)
    #
    # record the target of a temporary callback to the interpreter
    jl.tmp_callback(jitcell_token)
    #
    nb_red_args = jitdriver_sd.num_red_args
    assert len(redargtypes) == nb_red_args
    inputargs = []
    for kind in redargtypes:
        if kind == history.INT:
            box = InputArgInt()
        elif kind == history.REF:
            box = InputArgRef()
        elif kind == history.FLOAT:
            box = InputArgFloat()
        else:
            raise AssertionError
        inputargs.append(box)
    k = jitdriver_sd.portal_runner_adr
    funcbox = history.ConstInt(adr2int(k))
    callargs = [funcbox] + greenboxes + inputargs
    #

    jd = jitdriver_sd
    opnum = OpHelpers.call_for_descr(jd.portal_calldescr)
    call_op = ResOperation(opnum, callargs, descr=jd.portal_calldescr)
    if call_op.type != 'v' is not None:
        finishargs = [call_op]
    else:
        finishargs = []
    #
    faildescr = jitdriver_sd.propagate_exc_descr
    operations = [
        call_op,
        ResOperation(rop.GUARD_NO_EXCEPTION, [], descr=faildescr),
        ResOperation(rop.FINISH, finishargs, descr=jd.portal_finishtoken)
    ]
    operations[1].setfailargs([])
    operations = get_deep_immutable_oplist(operations)
    cpu.compile_loop(inputargs, operations, jitcell_token, log=False)

    if memory_manager is not None:  # for tests
        memory_manager.keep_loop_alive(jitcell_token)
    return jitcell_token
示例#23
0
 def test_pure_ops(self):
     i0 = InputArgInt()
     i1 = InputArgInt()
     op = ResOperation(rop.INT_ADD, [i0, i1])
     sb = ShortBoxes()
     short_boxes = sb.create_short_boxes(Opt([op]), [i0, i1], [i0, i1])
     assert len(short_boxes) == 3
     short_boxes.sort(key=str)
     # inputarg
     for i in range(3):
         if short_boxes[i].short_op.res is i0:
             assert short_boxes[i].preamble_op is sb.short_inputargs[0]
             break
     else:
         raise Exception("did not find!")
     # pure op
     for i in range(3):
         if short_boxes[2].preamble_op.getarg(0) is sb.short_inputargs[0]:
             assert short_boxes[2].short_op.res is op
             break
     else:
         raise Exception("did not find!")
示例#24
0
def test_execute_nonspec():
    cpu = FakeCPU()
    descr = FakeDescr()
    # cases with a descr
    # arity == -1
    argboxes = [InputArgInt(321), ConstInt(123)]
    box = _execute_arglist(cpu, FakeMetaInterp(), rop.CALL_F,
                           argboxes, FakeCallDescr())
    assert longlong.getrealfloat(box) == 42.5
    # arity == 0
    box = _execute_arglist(cpu, None, rop.NEW, [], descr)
    assert box.fakeargs == ('new', descr)
    # arity == 1
    box1 = InputArgRef()
    box = _execute_arglist(cpu, None, rop.ARRAYLEN_GC, [box1], descr)
    assert box == 55
    # arity == 2
    box2 = boxfloat(222.2)
    fielddescr = FakeFieldDescr()
    _execute_arglist(cpu, None, rop.SETFIELD_GC, [box1, box2], fielddescr)
    assert cpu.fakesetfield == (box1.getref_base(), box2.getfloatstorage(),
                                fielddescr)
    # arity == 3
    box3 = InputArgInt(33)
    arraydescr = FakeArrayDescr()
    _execute_arglist(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2],
                    arraydescr)
    assert cpu.fakesetarrayitem == (box1.getref_base(), box3.getint(),
                                    box2.getfloatstorage(), arraydescr)
    # cases without descr
    # arity == 1
    box = _execute_arglist(cpu, None, rop.INT_INVERT, [box3])
    assert box == ~33
    # arity == 2
    box = _execute_arglist(cpu, None, rop.INT_LSHIFT, [box3, InputArgInt(3)])
    assert box == 33 << 3
    # arity == 3
    _execute_arglist(cpu, None, rop.STRSETITEM, [box1, InputArgInt(3), box3])
    assert cpu.fakestrsetitem == (box1.getref_base(), 3, box3.getint())
示例#25
0
def test_modulo_operations(n, m, known_nonneg):
    if n < 0:
        known_nonneg = False
    n_box = InputArgInt()
    ops = modulo_operations(n_box, m, known_nonneg)

    constants = {n_box: ConstInt(n)}
    for op in ops:
        argboxes = op.getarglist()
        constantboxes = [constants.get(box, box) for box in argboxes]
        res = execute(None, None, op.getopnum(), None, *constantboxes)
        constants[op] = ConstInt(res)

    assert constants[op].getint() == n % m
示例#26
0
    def test_different_frame_width(self):
        class XRegisterManager(RegisterManager):
            pass

        fm = TFrameManager()
        b0 = InputArgInt()
        longevity = {b0: Lifetime(0, 1)}
        asm = MockAsm()
        rm = RegisterManager(longevity, frame_manager=fm, assembler=asm)
        f0 = InputArgFloat()
        longevity = {f0: Lifetime(0, 1)}
        xrm = XRegisterManager(longevity, frame_manager=fm, assembler=asm)
        xrm.loc(f0)
        rm.loc(b0)
        assert fm.get_frame_depth() == 3
示例#27
0
 def test_getfield_64bit_offset(self):
     if WORD == 4:
         py.test.skip("only for 64 bits")
     TP = lltype.Struct('S', ('i', lltype.Signed))
     p = lltype.malloc(TP, flavor='raw')
     p.i = 0x123456789ABC
     offset = 3**33
     val = rffi.cast(lltype.Signed, rffi.cast(lltype.Signed, p) - offset)
     res = self.execute_operation(
         rop.GC_LOAD_I,
         [InputArgInt(val),
          ConstInt(offset),
          ConstInt(WORD)], 'int')
     assert res == 0x123456789ABC
     lltype.free(p, flavor='raw')
示例#28
0
 def newinputarg(self, elem):
     if elem.startswith('i'):
         v = InputArgInt(0)
     elif elem.startswith('f'):
         v = InputArgFloat.fromfloat(0.0)
     elif elem.startswith('v'):
         v = InputArgVector()
         elem = self.update_vector(v, elem)
     else:
         from rpython.rtyper.lltypesystem import lltype, llmemory
         assert elem.startswith('p')
         v = InputArgRef(lltype.nullptr(llmemory.GCREF.TO))
     # ensure that the variable gets the proper naming
     self.update_memo(v, elem)
     self.vars[elem] = v
     return v
示例#29
0
 def test_ll_arraycopy_doesnt_escape_arrays(self):
     h = HeapCache()
     box1 = RefFrontendOp(1)
     box2 = RefFrontendOp(2)
     lengthbox1 = IntFrontendOp(11)
     lengthbox2 = IntFrontendOp(12)
     h.new_array(box1, lengthbox1)
     h.new_array(box2, lengthbox2)
     h.invalidate_caches(rop.CALL_N, arraycopydescr1,
                         [None, box2, box1, index1, index1, index2])
     assert h.is_unescaped(box1)
     assert h.is_unescaped(box2)
     h.invalidate_caches(rop.CALL_N, arraycopydescr1,
                         [None, box2, box1, index1, index1,
                          InputArgInt()])
     assert not h.is_unescaped(box1)
     assert not h.is_unescaped(box2)
示例#30
0
 def test_virtual(self):
     loop = """
     [p1, p2, i3]
     p0 = new_with_vtable(descr=simpledescr)
     setfield_gc(p0, i3, descr=simplevalue)
     jump(p0, p0, i3)
     """
     es, loop, preamble = self.optimize(loop)
     vs = es.virtual_state
     assert vs.state[0] is vs.state[1]
     assert isinstance(vs.state[0], VirtualStateInfo)
     assert isinstance(vs.state[0].fieldstate[0], NotVirtualStateInfo)
     assert vs.state[0].fieldstate[0].level == LEVEL_UNKNOWN
     assert vs.numnotvirtuals == 1
     p = InputArgRef()
     i = InputArgInt()
     ptrinfo = info.StructPtrInfo(self.nodesize, is_virtual=True)
     ptrinfo._fields = [i]
     p.set_forwarded(ptrinfo)
     vs.make_inputargs([p, p, i], FakeOptimizer())
示例#31
0
 def test_arrayitems_not_int(self):
     TP = lltype.GcArray(lltype.Char)
     ofs = symbolic.get_field_token(TP, 'length', False)[0]
     itemsofs = symbolic.get_field_token(TP, 'items', False)[0]
     descr = self.cpu.arraydescrof(TP)
     res = self.execute_operation(rop.NEW_ARRAY, [ConstInt(10)], 'ref',
                                  descr)
     resbuf = self._resbuf(res, ctypes.c_char)
     res = InputArgRef(res)
     assert resbuf[ofs] == chr(10)
     for i in range(10):
         self.execute_operation(
             rop.SETARRAYITEM_GC,
             [res, ConstInt(i), InputArgInt(i)], 'void', descr)
     for i in range(10):
         assert resbuf[itemsofs + i] == chr(i)
     for i in range(10):
         r = self.execute_operation(rop.GETARRAYITEM_GC_I,
                                    [res, ConstInt(i)], 'int', descr)
         assert r == i