Debian Codegraph @

rpython/jit/backend/zarch/test/test_pool.py

raw symbols SCIP
1 import py
2 from rpython.jit.backend.zarch.pool import LiteralPool, PoolOverflow
3 from rpython.jit.metainterp.history import (AbstractFailDescr,
4 AbstractDescr, BasicFailDescr, BasicFinalDescr, JitCellToken,
5 TargetToken, ConstInt, ConstPtr, Const, ConstFloat)
6 from rpython.jit.metainterp.resoperation import (ResOperation, rop,
7 InputArgInt)
8 from rpython.jit.backend.zarch.codebuilder import InstrBuilder
9 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
10 from rpython.jit.backend.zarch.helper.regalloc import check_imm32
11 from rpython.jit.backend.zarch.assembler import AssemblerZARCH
12 from rpython.jit.backend.detect_cpu import getcpuclass
13 from rpython.jit.tool.oparser import parse
14
15 class FakeAsm(object):
16 def write_i64(self, val):
17 pass
18
19 class TestPoolZARCH(object):
20 def setup_class(self):
21 self.calldescr = None
22
23 def setup_method(self, name):
24 self.pool = LiteralPool()
25 self.asm = FakeAsm()
26 self.asm.mc = FakeAsm()
27 self.cpu = getcpuclass()(None, None)
28 self.cpu.setup_once()
29
30 def ensure_can_hold(self, opnum, args, descr=None):
31 op = ResOperation(opnum, args, descr=descr)
32 self.pool.ensure_can_hold_constants(self.asm, op)
33
34 def const_in_pool(self, c):
35 try:
36 self.pool.get_offset(c)
37 return True
38 except KeyError:
39 return False
40
41 def test_constant_in_call_malloc(self):
42 c = ConstPtr(rffi.cast(llmemory.GCREF, 0xdeadbeef1234))
43 self.ensure_can_hold(rop.COND_CALL, [c], descr=self.calldescr)
44 assert self.const_in_pool(c)
45 assert self.const_in_pool(ConstPtr(rffi.cast(llmemory.GCREF, 0xdeadbeef1234)))
46
47 @py.test.mark.parametrize('opnum',
48 [rop.INT_ADD, rop.INT_SUB, rop.INT_MUL])
49 def test_constants_arith(self, opnum):
50 for c1 in [ConstInt(1), ConstInt(2**44), InputArgInt(1)]:
51 for c2 in [InputArgInt(1), ConstInt(-2**33), ConstInt(2**55)]:
52 self.ensure_can_hold(opnum, [c1,c2])
53 if c1.is_constant() and not -2**31 <= c1.getint() <= 2**31-1:
54 assert self.const_in_pool(c1)
55 if c2.is_constant() and not -2**31 <= c1.getint() <= 2**31-1:
56 assert self.const_in_pool(c2)
57
58 def test_pool_overflow(self):
59 self.pool.size = (2**19-1) - 8
60 self.pool.allocate_slot(8)
61 assert self.pool.size == 2**19-1
62 with py.test.raises(PoolOverflow) as of:
63 self.pool.allocate_slot(8)