Debian Codegraph @

rpython/jit/metainterp/test/test_llop.py

raw symbols SCIP
1 import py
2 import sys
3 import struct
4 from rpython.rtyper.lltypesystem import lltype, rffi
5 from rpython.rtyper.test.test_llop import (BaseLLOpTest, str_gc_load,
6 newlist_and_gc_store)
7 from rpython.jit.codewriter import longlong
8 from rpython.jit.metainterp.history import getkind
9 from rpython.jit.metainterp.test.support import LLJitMixin
10
11
12 class TestLLOp(BaseLLOpTest, LLJitMixin):
13
14 # for the individual tests see
15 # ====> ../../../rtyper/test/test_llop.py
16 TEST_BLACKHOLE = True
17
18 def gc_load_from_string(self, TYPE, buf, offset):
19 def f(offset):
20 return str_gc_load(TYPE, buf, offset)
21 res = self.interp_operations(f, [offset], supports_singlefloats=True)
22 #
23 kind = getkind(TYPE)[0] # 'i' or 'f'
24 self.check_operations_history({'gc_load_indexed_%s' % kind: 1,
25 'finish': 1})
26 #
27 if TYPE == lltype.SingleFloat:
28 # interp_operations returns the int version of r_singlefloat, but
29 # our tests expects to receive an r_singlefloat: let's convert it
30 # back!
31 return longlong.int2singlefloat(res)
32 return res
33
34 def newlist_and_gc_store(self, TYPE, value, expected):
35 def f(value):
36 lst = newlist_and_gc_store(TYPE, value)
37 got = ''.join(lst)
38 if got != expected:
39 # I'm not sure why, but if I use an assert, the test doesn't fail
40 raise ValueError('got != expected')
41 return len(got)
42 #
43 if self.TEST_BLACKHOLE:
44 # we pass a big inline_threshold to ensure that
45 # newlist_and_gc_store is inlined, else the blackhole does not see
46 # (and thus we do not test!) the llop.gc_store_indexed
47 threshold = 33
48 else:
49 threshold = 0
50 return self.interp_operations(f, [value], supports_singlefloats=True,
51 backendopt_inline_threshold=threshold)
52
53
54 def test_force_virtual_str_storage(self):
55 byteorder = sys.byteorder
56 size = rffi.sizeof(lltype.Signed)
57 def f(val):
58 if byteorder == 'little':
59 x = chr(val) + '\x00'*(size-1)
60 else:
61 x = '\x00'*(size-1) + chr(val)
62 return str_gc_load(lltype.Signed, x, 0)
63 res = self.interp_operations(f, [42], supports_singlefloats=True)
64 assert res == 42
65 self.check_operations_history({
66 'newstr': 1, # str forcing
67 'strsetitem': 1, # str forcing
68 'call_pure_r': 1, # str forcing (copystrcontent)
69 'guard_no_exception': 1, # str forcing
70 'gc_load_indexed_i': 1, # str_storage_getitem
71 'finish': 1
72 })