| 1 |
import py |
| 2 |
|
| 3 |
from rpython.rtyper.annlowlevel import llhelper |
| 4 |
from rpython.jit.metainterp.history import JitCellToken |
| 5 |
from rpython.jit.backend.test.calling_convention_test import CallingConvTests, parse |
| 6 |
from rpython.rtyper.lltypesystem import lltype |
| 7 |
from rpython.jit.codewriter.effectinfo import EffectInfo |
| 8 |
|
| 9 |
from rpython.jit.backend.arm.codebuilder import InstrBuilder |
| 10 |
from rpython.jit.backend.arm import registers as r |
| 11 |
from rpython.jit.backend.arm.test.support import skip_unless_run_slow_tests |
| 12 |
from rpython.jit.backend.arm.test.test_runner import boxfloat, constfloat |
| 13 |
from rpython.jit.metainterp.resoperation import rop, InputArgInt, InputArgFloat |
| 14 |
from rpython.jit.metainterp.history import JitCellToken |
| 15 |
|
| 16 |
skip_unless_run_slow_tests() |
| 17 |
|
| 18 |
boxint = InputArgInt |
| 19 |
boxfloat = InputArgFloat.fromfloat |
| 20 |
|
| 21 |
class TestARMCallingConvention(CallingConvTests): |
| 22 |
|
| 23 |
|
| 24 |
def make_function_returning_stack_pointer(self): |
| 25 |
mc = InstrBuilder() |
| 26 |
mc.MOV_rr(r.r0.value, r.sp.value) |
| 27 |
mc.MOV_rr(r.pc.value, r.lr.value) |
| 28 |
return mc.materialize(self.cpu, []) |
| 29 |
|
| 30 |
def get_alignment_requirements(self): |
| 31 |
return 8 |
| 32 |
|
| 33 |
def test_call_argument_spilling(self): |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
def func(a): |
| 38 |
return a + 16 |
| 39 |
|
| 40 |
I = lltype.Signed |
| 41 |
FUNC = self.FuncType([I], I) |
| 42 |
FPTR = self.Ptr(FUNC) |
| 43 |
func_ptr = llhelper(FPTR, func) |
| 44 |
calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, EffectInfo.MOST_GENERAL) |
| 45 |
funcbox = self.get_funcbox(self.cpu, func_ptr) |
| 46 |
|
| 47 |
args = ', '.join(['i%d' % i for i in range(11)]) |
| 48 |
ops = """ |
| 49 |
[%s] |
| 50 |
i99 = call(ConstClass(func_ptr), 22, descr=calldescr) |
| 51 |
guard_true(i0) [%s, i99] |
| 52 |
finish()""" % (args, args) |
| 53 |
loop = parse(ops, namespace=locals()) |
| 54 |
looptoken = JitCellToken() |
| 55 |
self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken) |
| 56 |
args = [x for x in range(11)] |
| 57 |
deadframe = self.cpu.execute_token(looptoken, *args) |
| 58 |
for x in range(11): |
| 59 |
assert self.cpu.get_int_value(deadframe, x) == x |
| 60 |
assert self.cpu.get_int_value(deadframe, 11) == 38 |
| 61 |
|
| 62 |
|
| 63 |
def test_float_hf_call_mixed(self): |
| 64 |
if not self.cpu.supports_floats: |
| 65 |
py.test.skip("requires floats") |
| 66 |
cpu = self.cpu |
| 67 |
callargs = [] |
| 68 |
def func(f0, f1, f2, f3, f4, f5, f6, i0, f7, i1, f8, f9): |
| 69 |
callargs.append(zip(range(12), |
| 70 |
[f0, f1, f2, f3, f4, f5, f6, i0, f7, i1, f8, f9])) |
| 71 |
return f0 + f1 + f2 + f3 + f4 + f5 + f6 + float(i0 + i1) + f7 + f8 + f9 |
| 72 |
F = lltype.Float |
| 73 |
I = lltype.Signed |
| 74 |
FUNC = self.FuncType([F] * 7 + [I] + [F] + [I] + [F]* 2, F) |
| 75 |
FPTR = self.Ptr(FUNC) |
| 76 |
func_ptr = llhelper(FPTR, func) |
| 77 |
calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, |
| 78 |
EffectInfo.MOST_GENERAL) |
| 79 |
funcbox = self.get_funcbox(cpu, func_ptr) |
| 80 |
args = ([boxfloat(.1) for i in range(7)] + |
| 81 |
[boxint(1), boxfloat(.2), boxint(2), boxfloat(.3), |
| 82 |
boxfloat(.4)]) |
| 83 |
res = self.execute_operation(rop.CALL_F, |
| 84 |
[funcbox] + args, |
| 85 |
'float', descr=calldescr) |
| 86 |
for i,j in enumerate(callargs[0]): |
| 87 |
box = args[i] |
| 88 |
if box.type == 'f': |
| 89 |
assert (i, args[i].getfloat()) == j |
| 90 |
else: |
| 91 |
assert (i, args[i].getint()) == j |
| 92 |
assert abs(res.getfloat() - 4.6) < 0.0001 |
| 93 |
|
| 94 |
def test_float_hf_call_float(self): |
| 95 |
if not self.cpu.supports_floats: |
| 96 |
py.test.skip("requires floats") |
| 97 |
cpu = self.cpu |
| 98 |
callargs = [] |
| 99 |
def func(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9): |
| 100 |
callargs.append(zip(range(10), |
| 101 |
[f0, f1, f2, f3, f4, f5, f6, f7, f8, f9])) |
| 102 |
return f0 + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 |
| 103 |
F = lltype.Float |
| 104 |
FUNC = self.FuncType([F] * 10, F) |
| 105 |
FPTR = self.Ptr(FUNC) |
| 106 |
func_ptr = llhelper(FPTR, func) |
| 107 |
calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, |
| 108 |
EffectInfo.MOST_GENERAL) |
| 109 |
funcbox = self.get_funcbox(cpu, func_ptr) |
| 110 |
args = ([boxfloat(.1) for i in range(10)]) |
| 111 |
res = self.execute_operation(rop.CALL_F, |
| 112 |
[funcbox] + args, |
| 113 |
'float', descr=calldescr) |
| 114 |
for i,j in enumerate(callargs[0]): |
| 115 |
assert (i, 0.1) == j |
| 116 |
assert abs(res.getfloat() - 1) < 0.0001 |
| 117 |
|
| 118 |
def test_float_hf_call_int(self): |
| 119 |
cpu = self.cpu |
| 120 |
callargs = [] |
| 121 |
def func(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9): |
| 122 |
callargs.append(zip(range(10), |
| 123 |
[f0, f1, f2, f3, f4, f5, f6, f7, f8, f9])) |
| 124 |
return f0 + f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 |
| 125 |
|
| 126 |
I = lltype.Signed |
| 127 |
FUNC = self.FuncType([I] * 10, I) |
| 128 |
FPTR = self.Ptr(FUNC) |
| 129 |
func_ptr = llhelper(FPTR, func) |
| 130 |
calldescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT, |
| 131 |
EffectInfo.MOST_GENERAL) |
| 132 |
funcbox = self.get_funcbox(cpu, func_ptr) |
| 133 |
args = ([boxint(1) for i in range(10)]) |
| 134 |
res = self.execute_operation(rop.CALL_I, |
| 135 |
[funcbox] + args, |
| 136 |
'int', descr=calldescr) |
| 137 |
for i,j in enumerate(callargs[0]): |
| 138 |
assert (i, 1) == j |
| 139 |
assert res.getint() == 10 |