Пример #1
0
 def fn(args):
     n = INFINITY
     c1 = ConstFloat(longlong.getfloatstorage(n - INFINITY))
     c2 = ConstFloat(longlong.getfloatstorage(n - INFINITY))
     c3 = ConstFloat(longlong.getfloatstorage(12.34))
     if c1.same_constant(c2):
         print "ok!"
     return 0
Пример #2
0
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)
Пример #3
0
def wrap(cpu, value, in_const_box=False):
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
            if in_const_box:
                return history.ConstPtr(value)
            else:
                return resoperation.InputArgRef(value)
        else:
            adr = llmemory.cast_ptr_to_adr(value)
            value = heaptracker.adr2int(adr)
            # fall through to the end of the function
    elif (isinstance(value, float) or
          longlong.is_longlong(lltype.typeOf(value))):
        if isinstance(value, float):
            value = longlong.getfloatstorage(value)
        else:
            value = rffi.cast(lltype.SignedLongLong, value)
        if in_const_box:
            return history.ConstFloat(value)
        else:
            return resoperation.InputArgFloat(value)
    elif isinstance(value, str) or isinstance(value, unicode):
        assert len(value) == 1     # must be a character
        value = ord(value)
    elif lltype.typeOf(value) is lltype.SingleFloat:
        value = longlong.singlefloat2int(value)
    else:
        value = intmask(value)
    if in_const_box:
        return history.ConstInt(value)
    else:
        return resoperation.InputArgInt(value)
Пример #4
0
 def test_vstm_vldm_combined(self):
     n = 14
     source_container = lltype.malloc(lltype.Array(longlong.FLOATSTORAGE,
                                                   hints={'nolength':
                                                          True}),
                                      n,
                                      flavor='raw')
     target_container = lltype.malloc(lltype.Array(longlong.FLOATSTORAGE,
                                                   hints={'nolength':
                                                          True}),
                                      n,
                                      flavor='raw')
     for x in range(n):
         source_container[x] = longlong.getfloatstorage(
             float("%d.%d" % (x, x)))
     self.a.gen_func_prolog()
     self.a.mc.gen_load_int(r.ip.value,
                            rffi.cast(lltype.Signed, source_container))
     self.a.mc.VLDM(r.ip.value, [x for x in range(n)])
     self.a.mc.gen_load_int(r.ip.value,
                            rffi.cast(lltype.Signed, target_container))
     self.a.mc.VSTM(r.ip.value, [x for x in range(n)])
     self.a.gen_func_epilog()
     run_asm(self.a)
     for d in range(n):
         res = longlong.getrealfloat(target_container[0]) == float("%d.%d" %
                                                                   (d, d))
     lltype.free(source_container, flavor='raw')
     lltype.free(target_container, flavor='raw')
Пример #5
0
def test_ResumeDataLoopMemo_other():
    memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
    const = ConstFloat(longlong.getfloatstorage(-1.0))
    tagged = memo.getconst(const)
    index, tagbits = untag(tagged)
    assert tagbits == TAGCONST
    assert memo.consts[index - TAG_CONST_OFFSET] is const
Пример #6
0
def _run_with_blackhole(testself, args):
    from rpython.jit.metainterp.blackhole import BlackholeInterpBuilder

    cw = testself.cw
    blackholeinterpbuilder = BlackholeInterpBuilder(cw)
    blackholeinterp = blackholeinterpbuilder.acquire_interp()
    count_i = count_r = count_f = 0
    for value in args:
        T = lltype.typeOf(value)
        if T == lltype.Signed:
            blackholeinterp.setarg_i(count_i, value)
            count_i += 1
        elif T == llmemory.GCREF:
            blackholeinterp.setarg_r(count_r, value)
            count_r += 1
        elif T == lltype.Float:
            value = longlong.getfloatstorage(value)
            blackholeinterp.setarg_f(count_f, value)
            count_f += 1
        else:
            raise TypeError(T)
    [jitdriver_sd] = cw.callcontrol.jitdrivers_sd
    blackholeinterp.setposition(jitdriver_sd.mainjitcode, 0)
    blackholeinterp.run()
    return blackholeinterp._final_result_anytype()
Пример #7
0
 def callback(asm):
     c = ConstFloat(longlong.getfloatstorage(-42.5))
     loc = self.xrm.convert_to_imm(c)
     asm.mov(loc, xmm5)
     asm.regalloc_push(xmm5)
     asm.regalloc_pop(xmm0)
     asm.mc.CVTTSD2SI(eax, xmm0)
Пример #8
0
    def test_shadowstack_collecting_call_float(self):
        cpu = self.cpu

        def float_return(i, f):
            # mark frame for write barrier
            frame = rffi.cast(lltype.Ptr(JITFRAME), i)
            frame.hdr |= 1
            return 1.2 + f

        FUNC = lltype.FuncType([lltype.Signed, lltype.Float], lltype.Float)
        fptr = llhelper(lltype.Ptr(FUNC), float_return)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                    EffectInfo.MOST_GENERAL)
        loop = self.parse("""
        [f0]
        i = force_token()
        f1 = call(ConstClass(fptr), i, f0, descr=calldescr)
        finish(f1, descr=finaldescr)
        """, namespace={'fptr': fptr, 'calldescr': calldescr,
                        'finaldescr': BasicFinalDescr(1)})
        token = JitCellToken()
        cpu.gc_ll_descr.init_nursery(20)
        cpu.setup_once()
        cpu.compile_loop(loop.inputargs, loop.operations, token)
        arg = longlong.getfloatstorage(2.3)
        frame = cpu.execute_token(token, arg)
        ofs = cpu.get_baseofs_of_frame_field()
        f = cpu.read_float_at_mem(frame, ofs)
        f = longlong.getrealfloat(f)
        assert f == 2.3 + 1.2
Пример #9
0
def wrap(cpu, value, in_const_box=False):
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
            if in_const_box:
                return history.ConstPtr(value)
            else:
                return history.BoxPtr(value)
        else:
            adr = llmemory.cast_ptr_to_adr(value)
            value = heaptracker.adr2int(adr)
            # fall through to the end of the function
    elif (isinstance(value, float)
          or longlong.is_longlong(lltype.typeOf(value))):
        if isinstance(value, float):
            value = longlong.getfloatstorage(value)
        else:
            value = rffi.cast(lltype.SignedLongLong, value)
        if in_const_box:
            return history.ConstFloat(value)
        else:
            return history.BoxFloat(value)
    elif isinstance(value, str) or isinstance(value, unicode):
        assert len(value) == 1  # must be a character
        value = ord(value)
    elif lltype.typeOf(value) is lltype.SingleFloat:
        value = longlong.singlefloat2int(value)
    else:
        value = intmask(value)
    if in_const_box:
        return history.ConstInt(value)
    else:
        return history.BoxInt(value)
Пример #10
0
    def test_shadowstack_collecting_call_float(self):
        cpu = self.cpu

        def float_return(i, f):
            # mark frame for write barrier
            frame = rffi.cast(lltype.Ptr(JITFRAME), i)
            frame.hdr |= 1
            return 1.2 + f

        FUNC = lltype.FuncType([lltype.Signed, lltype.Float], lltype.Float)
        fptr = llhelper(lltype.Ptr(FUNC), float_return)
        calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
                                    EffectInfo.MOST_GENERAL)
        loop = self.parse("""
        [f0]
        i = force_token()
        f1 = call_f(ConstClass(fptr), i, f0, descr=calldescr)
        finish(f1, descr=finaldescr)
        """, namespace={'fptr': fptr, 'calldescr': calldescr,
                        'finaldescr': BasicFinalDescr(1)})
        token = JitCellToken()
        cpu.gc_ll_descr.init_nursery(20)
        cpu.setup_once()
        cpu.compile_loop(loop.inputargs, loop.operations, token)
        arg = longlong.getfloatstorage(2.3)
        frame = cpu.execute_token(token, arg)
        ofs = cpu.get_baseofs_of_frame_field()
        f = cpu.read_float_at_mem(frame, ofs)
        f = longlong.getrealfloat(f)
        assert f == 2.3 + 1.2
Пример #11
0
 def emit_const(self, const, kind, allow_short=False):
     value = const.value
     value_key = value
     if kind == 'int':
         TYPE = const.concretetype
         if isinstance(TYPE, lltype.Ptr):
             assert TYPE.TO._gckind == 'raw'
             self.see_raw_object(value)
             value = llmemory.cast_ptr_to_adr(value)
             TYPE = llmemory.Address
         if TYPE == llmemory.Address:
             value = adr2int(value)
         if TYPE is lltype.SingleFloat:
             value = longlong.singlefloat2int(value)
         if not isinstance(value,
                           (llmemory.AddressAsInt, ComputedIntSymbolic)):
             value = lltype.cast_primitive(lltype.Signed, value)
             if type(value) is r_int:
                 value = int(value)
             if allow_short:
                 try:
                     short_num = -128 <= value <= 127
                 except TypeError:  # "Symbolics cannot be compared!"
                     short_num = False
                 if short_num:
                     # emit the constant as a small integer
                     self.code.append(chr(value & 0xFF))
                     return True
         constants = self.constants_i
     elif kind == 'ref':
         value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
         constants = self.constants_r
         if not value:
             # nullptr
             value_key = None
         else:
             value_key = value._obj.container
     elif kind == 'float':
         if const.concretetype == lltype.Float:
             value = longlong.getfloatstorage(value)
         else:
             assert longlong.is_longlong(const.concretetype)
             value = rffi.cast(lltype.SignedLongLong, value)
         constants = self.constants_f
     else:
         raise AssemblerError('unimplemented %r in %r' %
                              (const, self.ssareprname))
     key = (kind, Constant(value_key))
     try:
         val = self.constants_dict[key]
     except KeyError:
         constants.append(value)
         val = 256 - len(constants)
         assert val >= 0, "too many constants"
         self.constants_dict[key] = val
     # emit the constant normally, as one byte that is an index in the
     # list of constants
     self.code.append(chr(val))
     return False
Пример #12
0
def test_assemble_float_consts():
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('float_return', Register('float', 13)),
        ('float_return', Constant(18.0, lltype.Float)),
        ('float_return', Constant(-4.0, lltype.Float)),
        ('float_return', Constant(128.1, lltype.Float)),
    ]
    assembler = Assembler()
    jitcode = assembler.assemble(ssarepr)
    assert jitcode.code == ("\x00\x0D" "\x00\xFF" "\x00\xFE" "\x00\xFD")
    assert assembler.insns == {'float_return/f': 0}
    assert jitcode.constants_f == [
        longlong.getfloatstorage(18.0),
        longlong.getfloatstorage(-4.0),
        longlong.getfloatstorage(128.1)
    ]
Пример #13
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)
Пример #14
0
def test_assemble_float_consts():
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('float_return', Register('float', 13)),
        ('float_return', Constant(18.0, lltype.Float)),
        ('float_return', Constant(-4.0, lltype.Float)),
        ('float_return', Constant(128.1, lltype.Float)),
        ]
    assembler = Assembler()
    jitcode = assembler.assemble(ssarepr)
    assert jitcode.code == ("\x00\x0D"
                            "\x00\xFF"
                            "\x00\xFE"
                            "\x00\xFD")
    assert assembler.insns == {'float_return/f': 0}
    assert jitcode.constants_f == [longlong.getfloatstorage(18.0),
                                   longlong.getfloatstorage(-4.0),
                                   longlong.getfloatstorage(128.1)]
Пример #15
0
def cast_to_floatstorage(x):
    if isinstance(x, float):
        return longlong.getfloatstorage(x)  # common case
    if IS_32_BIT:
        assert longlong.supports_longlong
        if isinstance(x, r_longlong):
            return x
        if isinstance(x, r_ulonglong):
            return rffi.cast(lltype.SignedLongLong, x)
    raise TypeError(type(x))
Пример #16
0
def cast_to_floatstorage(x):
    if isinstance(x, float):
        return longlong.getfloatstorage(x)  # common case
    if IS_32_BIT:
        assert longlong.supports_longlong
        if isinstance(x, r_longlong):
            return x
        if isinstance(x, r_ulonglong):
            return rffi.cast(lltype.SignedLongLong, x)
    raise TypeError(type(x))
Пример #17
0
    def test_label_float_in_reg_and_on_stack(self):
        targettoken = TargetToken()
        ops = """
        [i0, f3]
        i2 = same_as_i(i0)    # but forced to be in a register
        force_spill(i2)
        force_spill(f3)
        f4 = float_add(f3, 5.0)
        label(f3, f4, descr=targettoken)
        force_spill(f3)
        f5 = same_as_f(f3)    # but forced to be in a register
        finish(f5)
        """
        faildescr = BasicFailDescr(2)
        loop = parse(ops, self.cpu, namespace=locals())
        looptoken = JitCellToken()
        info = self.cpu.compile_loop(loop.inputargs, loop.operations,
                                     looptoken)
        ops2 = """
        [i0, f1]
        i1 = same_as_i(i0)
        f2 = same_as_f(f1)
        f3 = float_add(f1, 10.0)
        force_spill(f3)
        force_spill(i1)
        f4 = float_add(f3, f1)
        jump(f3, f4, descr=targettoken)
        """
        loop2 = parse(ops2, self.cpu, namespace=locals())
        looptoken2 = JitCellToken()
        info = self.cpu.compile_loop(loop2.inputargs, loop2.operations,
                                     looptoken2)

        deadframe = self.cpu.execute_token(looptoken, -9,
                                           longlong.getfloatstorage(-13.5))
        res = longlong.getrealfloat(self.cpu.get_float_value(deadframe, 0))
        assert res == -13.5
        #
        deadframe = self.cpu.execute_token(looptoken2, -9,
                                           longlong.getfloatstorage(-13.5))
        res = longlong.getrealfloat(self.cpu.get_float_value(deadframe, 0))
        assert res == -3.5
Пример #18
0
def unspecialize_value(value):
    """Casts 'value' to a Signed, a GCREF or a FLOATSTORAGE."""
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            return lltype.cast_opaque_ptr(llmemory.GCREF, value)
        else:
            return ptr2int(value)
    elif isinstance(value, float):
        return longlong.getfloatstorage(value)
    else:
        return lltype.cast_primitive(lltype.Signed, value)
Пример #19
0
 def callback(asm):
     c = ConstFloat(longlong.getfloatstorage(-42.5))
     loc = self.xrm.convert_to_imm(c)
     loc2 = self.fm.frame_pos(4, FLOAT)
     asm.mc.SUB_ri(esp.value, 64)
     asm.mov(loc, xmm5)
     asm.regalloc_push(xmm5)
     asm.regalloc_pop(loc2)
     asm.mov(loc2, xmm0)
     asm.mc.ADD_ri(esp.value, 64)
     asm.mc.CVTTSD2SI(eax, xmm0)
Пример #20
0
def wrap_constant(value):
    if lltype.typeOf(value) == lltype.Signed:
        return ConstInt(value)
    elif isinstance(value, bool):
        return ConstInt(int(value))
    elif lltype.typeOf(value) == longlong.FLOATSTORAGE:
        return ConstFloat(value)
    elif isinstance(value, float):
        return ConstFloat(longlong.getfloatstorage(value))
    else:
        assert lltype.typeOf(value) == llmemory.GCREF
        return ConstPtr(value)
Пример #21
0
def unspecialize_value(value):
    """Casts 'value' to a Signed, a GCREF or a FLOATSTORAGE."""
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            return lltype.cast_opaque_ptr(llmemory.GCREF, value)
        else:
            adr = llmemory.cast_ptr_to_adr(value)
            return heaptracker.adr2int(adr)
    elif isinstance(value, float):
        return longlong.getfloatstorage(value)
    else:
        return lltype.cast_primitive(lltype.Signed, value)
Пример #22
0
def wrap_constant(value):
    if lltype.typeOf(value) == lltype.Signed:
        return ConstInt(value)
    elif isinstance(value, bool):
        return ConstInt(int(value))
    elif lltype.typeOf(value) == longlong.FLOATSTORAGE:
        return ConstFloat(value)
    elif isinstance(value, float):
        return ConstFloat(longlong.getfloatstorage(value))
    else:
        assert lltype.typeOf(value) == llmemory.GCREF
        return ConstPtr(value)
Пример #23
0
 def _new(x):
     "NOT_RPYTHON"
     kind = getkind(lltype.typeOf(x))
     if kind == "int":
         intval = lltype.cast_primitive(lltype.Signed, x)
         return BoxInt(intval)
     elif kind == "ref":
         ptrval = lltype.cast_opaque_ptr(llmemory.GCREF, x)
         return BoxPtr(ptrval)
     elif kind == "float":
         return BoxFloat(longlong.getfloatstorage(x))
     else:
         raise NotImplementedError(kind)
Пример #24
0
 def _new(x):
     "NOT_RPYTHON"
     kind = getkind(lltype.typeOf(x))
     if kind == "int":
         intval = lltype.cast_primitive(lltype.Signed, x)
         return BoxInt(intval)
     elif kind == "ref":
         ptrval = lltype.cast_opaque_ptr(llmemory.GCREF, x)
         return BoxPtr(ptrval)
     elif kind == "float":
         return BoxFloat(longlong.getfloatstorage(x))
     else:
         raise NotImplementedError(kind)
Пример #25
0
    def test_label_float_in_reg_and_on_stack(self):
        targettoken = TargetToken()
        ops = """
        [i0, f3]
        i2 = same_as_i(i0)    # but forced to be in a register
        force_spill(i2)
        force_spill(f3)
        f4 = float_add(f3, 5.0)
        label(f3, f4, descr=targettoken)
        force_spill(f3)
        f5 = same_as_f(f3)    # but forced to be in a register
        finish(f5)
        """
        faildescr = BasicFailDescr(2)
        loop = parse(ops, self.cpu, namespace=locals())
        looptoken = JitCellToken()
        info = self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
        ops2 = """
        [i0, f1]
        i1 = same_as_i(i0)
        f2 = same_as_f(f1)
        f3 = float_add(f1, 10.0)
        force_spill(f3)
        force_spill(i1)
        f4 = float_add(f3, f1)
        jump(f3, f4, descr=targettoken)
        """
        loop2 = parse(ops2, self.cpu, namespace=locals())
        looptoken2 = JitCellToken()
        info = self.cpu.compile_loop(loop2.inputargs, loop2.operations, looptoken2)

        deadframe = self.cpu.execute_token(looptoken, -9, longlong.getfloatstorage(-13.5))
        res = longlong.getrealfloat(self.cpu.get_float_value(deadframe, 0))
        assert res == -13.5
        #
        deadframe = self.cpu.execute_token(looptoken2, -9, longlong.getfloatstorage(-13.5))
        res = longlong.getrealfloat(self.cpu.get_float_value(deadframe, 0))
        assert res == -3.5
Пример #26
0
 def _new(x):
     "NOT_RPYTHON"
     T = lltype.typeOf(x)
     kind = getkind(T)
     if kind == "int":
         if isinstance(T, lltype.Ptr):
             intval = ptr2int(x)
         else:
             intval = lltype.cast_primitive(lltype.Signed, x)
         return ConstInt(intval)
     elif kind == "float":
         return ConstFloat(longlong.getfloatstorage(x))
     else:
         raise NotImplementedError(kind)
Пример #27
0
 def emit_const(self, const, kind, allow_short=False):
     value = const.value
     if kind == 'int':
         TYPE = const.concretetype
         if isinstance(TYPE, lltype.Ptr):
             assert TYPE.TO._gckind == 'raw'
             self.see_raw_object(value)
             value = llmemory.cast_ptr_to_adr(value)
             TYPE = llmemory.Address
         if TYPE == llmemory.Address:
             value = heaptracker.adr2int(value)
         if TYPE is lltype.SingleFloat:
             value = longlong.singlefloat2int(value)
         if not isinstance(value, (llmemory.AddressAsInt,
                                   ComputedIntSymbolic)):
             value = lltype.cast_primitive(lltype.Signed, value)
             if allow_short:
                 try:
                     short_num = -128 <= value <= 127
                 except TypeError:    # "Symbolics cannot be compared!"
                     short_num = False
                 if short_num:
                     # emit the constant as a small integer
                     self.code.append(chr(value & 0xFF))
                     return True
         constants = self.constants_i
     elif kind == 'ref':
         value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
         constants = self.constants_r
     elif kind == 'float':
         if const.concretetype == lltype.Float:
             value = longlong.getfloatstorage(value)
         else:
             assert longlong.is_longlong(const.concretetype)
             value = rffi.cast(lltype.SignedLongLong, value)
         constants = self.constants_f
     else:
         raise AssemblerError('unimplemented %r in %r' %
                              (const, self.ssareprname))
     key = (kind, Constant(value))
     if key not in self.constants_dict:
         constants.append(value)
         val = 256 - len(constants)
         assert val >= 0, "too many constants"
         self.constants_dict[key] = val
     # emit the constant normally, as one byte that is an index in the
     # list of constants
     self.code.append(chr(self.constants_dict[key]))
     return False
Пример #28
0
 def _prepare_args(self, args, floats, ints):
     local_floats = list(floats)
     local_ints = list(ints)
     expected_result = 0.0
     arguments = []
     for i in range(len(args)):
         x = args[i]
         if x[0] == 'f':
             x = local_floats.pop()
             t = longlong.getfloatstorage(x)
             arguments.append(t)
         else:
             x = local_ints.pop()
             arguments.append(x)
         expected_result += x
     return arguments, expected_result
Пример #29
0
 def _prepare_args(self, args, floats, ints):
     local_floats = list(floats)
     local_ints = list(ints)
     expected_result = 0.0
     arguments = []
     for i in range(len(args)):
         x = args[i]
         if x[0] == 'f':
             x = local_floats.pop()
             t = longlong.getfloatstorage(x)
             arguments.append(t)
         else:
             x = local_ints.pop()
             arguments.append(x)
         expected_result += x
     return arguments, expected_result
Пример #30
0
 def test_vldm(self):
     n = 14
     container = lltype.malloc(lltype.Array(longlong.FLOATSTORAGE,
                             hints={'nolength': True}), n, flavor='raw')
     for x in range(n):
         container[x] = longlong.getfloatstorage(float("%d.%d" % (x,x)))
     self.a.gen_func_prolog()
     self.a.mc.gen_load_int(r.ip.value, rffi.cast(lltype.Signed, container))
     self.a.mc.VLDM(r.ip.value, [x for x in range(n)])
     for x in range(1, n):
         self.a.mc.VADD(0, 0, x)
     self.a.mc.VSTR(r.d0.value, r.ip.value)
     self.a.gen_func_epilog()
     res = run_asm(self.a)
     assert longlong.getrealfloat(container[0]) == sum([float("%d.%d" % (d,d)) for d in range(n)])
     lltype.free(container, flavor='raw')
Пример #31
0
 def _new(x):
     "NOT_RPYTHON"
     T = lltype.typeOf(x)
     kind = getkind(T)
     if kind == "int":
         if isinstance(T, lltype.Ptr):
             intval = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
         else:
             intval = lltype.cast_primitive(lltype.Signed, x)
         return ConstInt(intval)
     elif kind == "ref":
         return cpu.ts.new_ConstRef(x)
     elif kind == "float":
         return ConstFloat(longlong.getfloatstorage(x))
     else:
         raise NotImplementedError(kind)
Пример #32
0
 def _new(x):
     "NOT_RPYTHON"
     T = lltype.typeOf(x)
     kind = getkind(T)
     if kind == "int":
         if isinstance(T, lltype.Ptr):
             intval = heaptracker.adr2int(llmemory.cast_ptr_to_adr(x))
         else:
             intval = lltype.cast_primitive(lltype.Signed, x)
         return ConstInt(intval)
     elif kind == "ref":
         return cpu.ts.new_ConstRef(x)
     elif kind == "float":
         return ConstFloat(longlong.getfloatstorage(x))
     else:
         raise NotImplementedError(kind)
Пример #33
0
def test_call_stubs_2():
    c0 = GcCache(False)
    ARRAY = lltype.GcArray(lltype.Signed)
    ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
    RES = lltype.Float

    def f2(a, b):
        return float(b[0]) + a

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f2)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = lltype.malloc(ARRAY, 3)
    opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
    a[0] = 1
    res = descr2.call_stub_f(rffi.cast(lltype.Signed, fnptr),
                             [], [opaquea], [longlong.getfloatstorage(3.5)])
    assert longlong.getrealfloat(res) == 4.5
Пример #34
0
def test_call_stubs_2():
    c0 = GcCache(False)
    ARRAY = lltype.GcArray(lltype.Signed)
    ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
    RES = lltype.Float

    def f2(a, b):
        return float(b[0]) + a

    fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f2)
    descr2 = get_call_descr(c0, ARGS, RES)
    a = lltype.malloc(ARRAY, 3)
    opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
    a[0] = 1
    res = descr2.call_stub_f(rffi.cast(lltype.Signed, fnptr),
                             [], [opaquea], [longlong.getfloatstorage(3.5)])
    assert longlong.getrealfloat(res) == 4.5
Пример #35
0
    def optimize_FLOAT_TRUEDIV(self, op):
        arg1 = op.getarg(0)
        arg2 = op.getarg(1)
        v2 = self.getvalue(arg2)

        # replace "x / const" by "x * (1/const)" if possible
        if v2.is_constant():
            divisor = v2.box.getfloat()
            fraction = math.frexp(divisor)[0]
            # This optimization is valid for powers of two
            # but not for zeroes, some denormals and NaN:
            if fraction == 0.5 or fraction == -0.5:
                reciprocal = 1.0 / divisor
                rfraction = math.frexp(reciprocal)[0]
                if rfraction == 0.5 or rfraction == -0.5:
                    c = ConstFloat(longlong.getfloatstorage(reciprocal))
                    op = op.copy_and_change(rop.FLOAT_MUL, args=[arg1, c])
        self.emit_operation(op)
Пример #36
0
    def optimize_FLOAT_TRUEDIV(self, op):
        arg1 = op.getarg(0)
        arg2 = op.getarg(1)
        v2 = self.getvalue(arg2)

        # replace "x / const" by "x * (1/const)" if possible
        if v2.is_constant():
            divisor = v2.box.getfloat()
            fraction = math.frexp(divisor)[0]
            # This optimization is valid for powers of two
            # but not for zeroes, some denormals and NaN:
            if fraction == 0.5 or fraction == -0.5:
                reciprocal = 1.0 / divisor
                rfraction = math.frexp(reciprocal)[0]
                if rfraction == 0.5 or rfraction == -0.5:
                    c = ConstFloat(longlong.getfloatstorage(reciprocal))
                    op = op.copy_and_change(rop.FLOAT_MUL, args=[arg1, c])
        self.emit_operation(op)
Пример #37
0
    def optimize_FLOAT_TRUEDIV(self, op):
        arg1 = op.getarg(0)
        arg2 = op.getarg(1)
        v2 = self.get_box_replacement(arg2)

        # replace "x / const" by "x * (1/const)" if possible
        newop = op
        if v2.is_constant():
            divisor = v2.getfloat()
            fraction = math.frexp(divisor)[0]
            # This optimization is valid for powers of two
            # but not for zeroes, some denormals and NaN:
            if fraction == 0.5 or fraction == -0.5:
                reciprocal = 1.0 / divisor
                rfraction = math.frexp(reciprocal)[0]
                if rfraction == 0.5 or rfraction == -0.5:
                    c = ConstFloat(longlong.getfloatstorage(reciprocal))
                    newop = self.replace_op_with(op, rop.FLOAT_MUL, args=[arg1, c])
        return self.emit(newop)
Пример #38
0
 def test_vstm_vldm_combined(self):
     n = 14
     source_container = lltype.malloc(lltype.Array(longlong.FLOATSTORAGE,
         hints={'nolength': True}), n, flavor='raw')
     target_container = lltype.malloc(lltype.Array(longlong.FLOATSTORAGE,
         hints={'nolength': True}), n, flavor='raw')
     for x in range(n):
         source_container[x] = longlong.getfloatstorage(float("%d.%d" % (x,x)))
     self.a.gen_func_prolog()
     self.a.mc.gen_load_int(r.ip.value, rffi.cast(lltype.Signed, source_container))
     self.a.mc.VLDM(r.ip.value, [x for x in range(n)])
     self.a.mc.gen_load_int(r.ip.value, rffi.cast(lltype.Signed, target_container))
     self.a.mc.VSTM(r.ip.value, [x for x in range(n)])
     self.a.gen_func_epilog()
     run_asm(self.a)
     for d in range(n):
         res = longlong.getrealfloat(target_container[0]) == float("%d.%d" % (d,d))
     lltype.free(source_container, flavor='raw')
     lltype.free(target_container, flavor='raw')
Пример #39
0
    def optimize_FLOAT_TRUEDIV(self, op):
        arg1 = op.getarg(0)
        arg2 = op.getarg(1)
        v2 = get_box_replacement(arg2)

        # replace "x / const" by "x * (1/const)" if possible
        newop = op
        if v2.is_constant():
            divisor = v2.getfloat()
            fraction = math.frexp(divisor)[0]
            # This optimization is valid for powers of two
            # but not for zeroes, some denormals and NaN:
            if fraction == 0.5 or fraction == -0.5:
                reciprocal = 1.0 / divisor
                rfraction = math.frexp(reciprocal)[0]
                if rfraction == 0.5 or rfraction == -0.5:
                    c = ConstFloat(longlong.getfloatstorage(reciprocal))
                    newop = self.replace_op_with(op, rop.FLOAT_MUL,
                                                 args=[arg1, c])
        return self.emit(newop)
Пример #40
0
 def interpret(self, ops, args, run=True, namespace=None):
     loop = self.parse(ops, namespace=namespace)
     self.loop = loop
     looptoken = JitCellToken()
     self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
     arguments = []
     for arg in args:
         if isinstance(arg, int):
             arguments.append(arg)
         elif isinstance(arg, float):
             arg = longlong.getfloatstorage(arg)
             arguments.append(arg)
         else:
             assert isinstance(lltype.typeOf(arg), lltype.Ptr)
             llgcref = lltype.cast_opaque_ptr(llmemory.GCREF, arg)
             arguments.append(llgcref)
     loop._jitcelltoken = looptoken
     if run:
         self.deadframe = self.cpu.execute_token(looptoken, *arguments)
     return loop
 def interpret(self, ops, args, run=True, namespace=None):
     loop = self.parse(ops, namespace=namespace)
     self.loop = loop
     looptoken = JitCellToken()
     self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
     arguments = []
     for arg in args:
         if isinstance(arg, int):
             arguments.append(arg)
         elif isinstance(arg, float):
             arg = longlong.getfloatstorage(arg)
             arguments.append(arg)
         else:
             assert isinstance(lltype.typeOf(arg), lltype.Ptr)
             llgcref = lltype.cast_opaque_ptr(llmemory.GCREF, arg)
             arguments.append(llgcref)
     loop._jitcelltoken = looptoken
     if run:
         self.deadframe = self.cpu.execute_token(looptoken, *arguments)
     return loop
Пример #42
0
 def do(self, opnum, argboxes, descr=None):
     self.fakemetainterp._got_exc = None
     op = ResOperation(opnum, argboxes, descr)
     argboxes = map(constbox, argboxes)
     result = _execute_arglist(self.cpu, self.fakemetainterp, opnum,
                               argboxes, descr)
     if result is not None:
         if lltype.typeOf(result) == lltype.Signed:
             op._example_int = result
         elif isinstance(result, bool):
             op._example_int = int(result)
         elif lltype.typeOf(result) == longlong.FLOATSTORAGE:
             op._example_float = result
         elif isinstance(result, float):
             op._example_float = longlong.getfloatstorage(result)
         else:
             assert lltype.typeOf(result) == llmemory.GCREF
             op._example_ref = result
     self.loop.operations.append(op)
     return op
Пример #43
0
 def do(self, opnum, argboxes, descr=None):
     self.fakemetainterp._got_exc = None
     op = ResOperation(opnum, argboxes, descr)
     argboxes = map(constbox, argboxes)
     result = _execute_arglist(self.cpu, self.fakemetainterp,
                               opnum, argboxes, descr)
     if result is not None:
         if lltype.typeOf(result) == lltype.Signed:
             op._example_int = result
         elif isinstance(result, bool):
             op._example_int = int(result)
         elif lltype.typeOf(result) == longlong.FLOATSTORAGE:
             op._example_float = result
         elif isinstance(result, float):
             op._example_float = longlong.getfloatstorage(result)
         else:
             assert lltype.typeOf(result) == llmemory.GCREF
             op._example_ref = result
     self.loop.operations.append(op)
     return op
Пример #44
0
def wrap(cpu, value, in_const_box=False):
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
            if in_const_box:
                return history.ConstPtr(value)
            else:
                res = history.RefFrontendOp(0)
                res.setref_base(value)
                return res
        else:
            value = ptr2int(value)
            # fall through to the end of the function
    elif (isinstance(value, float) or
          longlong.is_longlong(lltype.typeOf(value))):
        if isinstance(value, float):
            value = longlong.getfloatstorage(value)
        else:
            value = rffi.cast(lltype.SignedLongLong, value)
        if in_const_box:
            return history.ConstFloat(value)
        else:
            res = history.FloatFrontendOp(0)
            res.setfloatstorage(value)
            return res
    elif isinstance(value, str) or isinstance(value, unicode):
        assert len(value) == 1     # must be a character
        value = ord(value)
    elif lltype.typeOf(value) is lltype.SingleFloat:
        value = longlong.singlefloat2int(value)
    else:
        value = intmask(value)
    if in_const_box:
        return history.ConstInt(value)
    else:
        res = history.IntFrontendOp(0)
        res.setint(value)
        return res
Пример #45
0
def _run_with_blackhole(testself, args):
    from rpython.jit.metainterp.blackhole import BlackholeInterpBuilder
    cw = testself.cw
    blackholeinterpbuilder = BlackholeInterpBuilder(cw)
    blackholeinterp = blackholeinterpbuilder.acquire_interp()
    count_i = count_r = count_f = 0
    for value in args:
        T = lltype.typeOf(value)
        if T == lltype.Signed:
            blackholeinterp.setarg_i(count_i, value)
            count_i += 1
        elif T == llmemory.GCREF:
            blackholeinterp.setarg_r(count_r, value)
            count_r += 1
        elif T == lltype.Float:
            value = longlong.getfloatstorage(value)
            blackholeinterp.setarg_f(count_f, value)
            count_f += 1
        else:
            raise TypeError(T)
    [jitdriver_sd] = cw.callcontrol.jitdrivers_sd
    blackholeinterp.setposition(jitdriver_sd.mainjitcode, 0)
    blackholeinterp.run()
    return blackholeinterp._final_result_anytype()
Пример #46
0
 def get_random_float_storage():
     x = get_random_float()
     return longlong.getfloatstorage(x)
Пример #47
0
def test_functions():
    xll = longlong.getfloatstorage(3.5)
    assert longlong.getrealfloat(xll) == 3.5
    assert is_valid_int(longlong.gethash(xll))
Пример #48
0
 def fromfloat(x):
     return ConstFloat(longlong.getfloatstorage(x))
Пример #49
0
 def get_random_float_storage():
     x = get_random_float()
     return longlong.getfloatstorage(x)
Пример #50
0
 def bh_call_f(self, func, args_i, args_r, args_f, calldescr):
     self.fakecalled = (func, args_i, args_r, args_f, calldescr)
     return longlong.getfloatstorage(42.5)
Пример #51
0
def test_functions():
    xll = longlong.getfloatstorage(3.5)
    assert longlong.getrealfloat(xll) == 3.5
    assert is_valid_int(longlong.gethash(xll))
Пример #52
0
 def convert_to_floatstorage(arg):
     from rpython.jit.codewriter import longlong
     return longlong.getfloatstorage(float(arg))
Пример #53
0
def boxfloat(x):
    return BoxFloat(longlong.getfloatstorage(x))
Пример #54
0
 def fromfloat(x):
     return ConstFloat(longlong.getfloatstorage(x))
Пример #55
0
def boxfloat(x):
    return BoxFloat(longlong.getfloatstorage(x))
Пример #56
0
def boxfloat(x):
    return InputArgFloat(longlong.getfloatstorage(x))
Пример #57
0
def boxfloat(x):
    return InputArgFloat(longlong.getfloatstorage(x))