Debian Codegraph @

rpython/jit/backend/x86/test/test_assembler.py

raw symbols SCIP
1 from rpython.jit.backend.x86.regloc import *
2 from rpython.jit.metainterp.history import ConstFloat
3 from rpython.jit.metainterp.history import INT, FLOAT
4 from rpython.rtyper.lltypesystem import llmemory, rffi
5 from rpython.jit.backend.detect_cpu import getcpuclass
6 from rpython.jit.codewriter import longlong
7 import ctypes
8 import py
9
10 ACTUAL_CPU = getcpuclass()
11 if not hasattr(ACTUAL_CPU, 'NUM_REGS'):
12 py.test.skip('unsupported CPU')
13
14 class FakeCPU:
15 rtyper = None
16 supports_floats = True
17 NUM_REGS = ACTUAL_CPU.NUM_REGS
18
19 class gc_ll_descr:
20 kind = "boehm"
21
22 def fielddescrof(self, STRUCT, name):
23 return 42
24
25 def get_fail_descr_from_number(self, num):
26 assert num == 0x1C3
27 return FakeFailDescr()
28
29 class FakeMC:
30 def __init__(self):
31 self.content = []
32 def writechar(self, char):
33 self.content.append(ord(char))
34
35 class FakeFailDescr:
36 def hide(self, cpu):
37 return rffi.cast(llmemory.GCREF, 123)
38
39 # ____________________________________________________________
40
41 class TestRegallocPushPop(object):
42
43 def do_test(self, callback):
44 from rpython.jit.backend.x86.regalloc import X86FrameManager
45 from rpython.jit.backend.x86.regalloc import X86XMMRegisterManager
46 class FakeToken:
47 class compiled_loop_token:
48 asmmemmgr_blocks = None
49 cpu = ACTUAL_CPU(None, None)
50 cpu.setup()
51 if cpu.HAS_CODEMAP:
52 cpu.codemap.setup()
53 looptoken = FakeToken()
54 asm = cpu.assembler
55 asm.setup_once()
56 asm.setup(looptoken)
57 self.xrm = X86XMMRegisterManager(None, assembler=asm)
58 callback(asm)
59 asm.mc.RET()
60 rawstart = asm.materialize_loop(looptoken)
61 #
62 F = ctypes.CFUNCTYPE(ctypes.c_long)
63 fn = ctypes.cast(rawstart, F)
64 res = fn()
65 return res
66
67 def test_simple(self):
68 def callback(asm):
69 asm.mov(imm(42), edx)
70 asm.regalloc_push(edx)
71 asm.regalloc_pop(eax)
72 res = self.do_test(callback)
73 assert res == 42
74
75 def test_simple_xmm(self):
76 def callback(asm):
77 c = ConstFloat(longlong.getfloatstorage(-42.5))
78 loc = self.xrm.convert_to_imm(c)
79 asm.mov(loc, xmm5)
80 asm.regalloc_push(xmm5)
81 asm.regalloc_pop(xmm0)
82 asm.mc.CVTTSD2SI(eax, xmm0)
83 res = self.do_test(callback)
84 assert res == -42
85
86 def test_xmm_pushes_8_bytes(self):
87 def callback(asm):
88 asm.regalloc_push(xmm5)
89 asm.mc.ADD(esp, imm(8))
90 self.do_test(callback)