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
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 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)
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')
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
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()
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)
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
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)
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
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
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) ]
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)
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)]
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))
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
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)
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)
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)
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)
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)
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)
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
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
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')
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)
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
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)
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)
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')
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)
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 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
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
def get_random_float_storage(): x = get_random_float() return longlong.getfloatstorage(x)
def test_functions(): xll = longlong.getfloatstorage(3.5) assert longlong.getrealfloat(xll) == 3.5 assert is_valid_int(longlong.gethash(xll))
def fromfloat(x): return ConstFloat(longlong.getfloatstorage(x))
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)
def convert_to_floatstorage(arg): from rpython.jit.codewriter import longlong return longlong.getfloatstorage(float(arg))
def boxfloat(x): return BoxFloat(longlong.getfloatstorage(x))
def boxfloat(x): return InputArgFloat(longlong.getfloatstorage(x))