PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/pypy/pypy/
Python | 63 lines | 55 code | 8 blank | 0 comment | 9 complexity | d4fa096bd428f945212b58d18a5f7ff1 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, Apache-2.0
  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. class FakeAsm(object):
  15. def write_i64(self, val):
  16. pass
  17. class TestPoolZARCH(object):
  18. def setup_class(self):
  19. self.calldescr = None
  20. def setup_method(self, name):
  21. self.pool = LiteralPool()
  22. self.asm = FakeAsm()
  23. self.asm.mc = FakeAsm()
  24. self.cpu = getcpuclass()(None, None)
  25. self.cpu.setup_once()
  26. def ensure_can_hold(self, opnum, args, descr=None):
  27. op = ResOperation(opnum, args, descr=descr)
  28. self.pool.ensure_can_hold_constants(self.asm, op)
  29. def const_in_pool(self, c):
  30. try:
  31. self.pool.get_offset(c)
  32. return True
  33. except KeyError:
  34. return False
  35. def test_constant_in_call_malloc(self):
  36. c = ConstPtr(rffi.cast(llmemory.GCREF, 0xdeadbeef1234))
  37. self.ensure_can_hold(rop.COND_CALL, [c], descr=self.calldescr)
  38. assert self.const_in_pool(c)
  39. assert self.const_in_pool(ConstPtr(rffi.cast(llmemory.GCREF, 0xdeadbeef1234)))
  40. @py.test.mark.parametrize('opnum',
  41. [rop.INT_ADD, rop.INT_SUB, rop.INT_MUL])
  42. def test_constants_arith(self, opnum):
  43. for c1 in [ConstInt(1), ConstInt(2**44), InputArgInt(1)]:
  44. for c2 in [InputArgInt(1), ConstInt(-2**33), ConstInt(2**55)]:
  45. self.ensure_can_hold(opnum, [c1,c2])
  46. if c1.is_constant() and not -2**31 <= c1.getint() <= 2**31-1:
  47. assert self.const_in_pool(c1)
  48. if c2.is_constant() and not -2**31 <= c1.getint() <= 2**31-1:
  49. assert self.const_in_pool(c2)
  50. def test_pool_overflow(self):
  51. self.pool.size = (2**19-1) - 8
  52. self.pool.allocate_slot(8)
  53. assert self.pool.size == 2**19-1
  54. with py.test.raises(PoolOverflow) as of:
  55. self.pool.allocate_slot(8)