| 1 |
from __future__ import with_statement |
| 2 |
from rpython.jit.backend.arm import conditions as c |
| 3 |
from rpython.jit.backend.arm import registers as r |
| 4 |
from rpython.jit.backend.arm.codebuilder import InstrBuilder |
| 5 |
from rpython.jit.metainterp.history import FLOAT |
| 6 |
from rpython.rlib.rarithmetic import r_uint, r_longlong, intmask |
| 7 |
from rpython.jit.metainterp.resoperation import rop |
| 8 |
|
| 9 |
|
| 10 |
def flush_cc(asm, condition, result_loc): |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
assert asm.guard_success_cc == c.cond_none |
| 18 |
if result_loc is r.fp: |
| 19 |
asm.guard_success_cc = condition |
| 20 |
else: |
| 21 |
asm.mc.MOV_ri(result_loc.value, 1, condition) |
| 22 |
asm.mc.MOV_ri(result_loc.value, 0, c.get_opposite_of(condition)) |
| 23 |
|
| 24 |
|
| 25 |
def gen_emit_op_unary_cmp(name, true_cond): |
| 26 |
def f(self, op, arglocs, regalloc, fcond): |
| 27 |
assert fcond is not None |
| 28 |
reg, res = arglocs |
| 29 |
self.mc.CMP_ri(reg.value, 0) |
| 30 |
flush_cc(self, true_cond, res) |
| 31 |
return fcond |
| 32 |
f.__name__ = 'emit_op_%s' % name |
| 33 |
return f |
| 34 |
|
| 35 |
def gen_emit_op_ri(name, opname): |
| 36 |
ri_op = getattr(InstrBuilder, '%s_ri' % opname) |
| 37 |
rr_op = getattr(InstrBuilder, '%s_rr' % opname) |
| 38 |
def f(self, op, arglocs, regalloc, fcond): |
| 39 |
assert fcond is not None |
| 40 |
l0, l1, res = arglocs |
| 41 |
if l1.is_imm(): |
| 42 |
ri_op(self.mc, res.value, l0.value, imm=l1.value, cond=fcond) |
| 43 |
else: |
| 44 |
rr_op(self.mc, res.value, l0.value, l1.value) |
| 45 |
return fcond |
| 46 |
f.__name__ = 'emit_op_%s' % name |
| 47 |
return f |
| 48 |
|
| 49 |
def gen_emit_cmp_op(name, true_cond): |
| 50 |
def f(self, op, arglocs, regalloc, fcond): |
| 51 |
l0, l1, res = arglocs |
| 52 |
|
| 53 |
if l1.is_imm(): |
| 54 |
self.mc.CMP_ri(l0.value, imm=l1.getint(), cond=fcond) |
| 55 |
else: |
| 56 |
self.mc.CMP_rr(l0.value, l1.value, cond=fcond) |
| 57 |
flush_cc(self, true_cond, res) |
| 58 |
return fcond |
| 59 |
f.__name__ = 'emit_op_%s' % name |
| 60 |
return f |
| 61 |
|
| 62 |
def gen_emit_float_op(name, opname): |
| 63 |
op_rr = getattr(InstrBuilder, opname) |
| 64 |
def f(self, op, arglocs, regalloc, fcond): |
| 65 |
arg1, arg2, result = arglocs |
| 66 |
op_rr(self.mc, result.value, arg1.value, arg2.value) |
| 67 |
return fcond |
| 68 |
f.__name__ = 'emit_op_%s' % name |
| 69 |
return f |
| 70 |
|
| 71 |
def gen_emit_unary_float_op(name, opname): |
| 72 |
op_rr = getattr(InstrBuilder, opname) |
| 73 |
def f(self, op, arglocs, regalloc, fcond): |
| 74 |
arg1, result = arglocs |
| 75 |
op_rr(self.mc, result.value, arg1.value) |
| 76 |
return fcond |
| 77 |
f.__name__ = 'emit_op_%s' % name |
| 78 |
return f |
| 79 |
|
| 80 |
def gen_emit_float_cmp_op(name, true_cond): |
| 81 |
def f(self, op, arglocs, regalloc, fcond): |
| 82 |
arg1, arg2, res = arglocs |
| 83 |
self.mc.VCMP(arg1.value, arg2.value) |
| 84 |
self.mc.VMRS(cond=fcond) |
| 85 |
flush_cc(self, true_cond, res) |
| 86 |
return fcond |
| 87 |
f.__name__ = 'emit_op_%s' % name |
| 88 |
return f |
| 89 |
|
| 90 |
|
| 91 |
class saved_registers(object): |
| 92 |
def __init__(self, cb, regs_to_save, vfp_regs_to_save=None): |
| 93 |
self.cb = cb |
| 94 |
if vfp_regs_to_save is None: |
| 95 |
vfp_regs_to_save = [] |
| 96 |
self.regs = regs_to_save |
| 97 |
self.vfp_regs = vfp_regs_to_save |
| 98 |
|
| 99 |
def __enter__(self): |
| 100 |
if len(self.regs) > 0: |
| 101 |
self.cb.PUSH([r.value for r in self.regs]) |
| 102 |
if len(self.vfp_regs) > 0: |
| 103 |
self.cb.VPUSH([r.value for r in self.vfp_regs]) |
| 104 |
|
| 105 |
def __exit__(self, *args): |
| 106 |
if len(self.vfp_regs) > 0: |
| 107 |
self.cb.VPOP([r.value for r in self.vfp_regs]) |
| 108 |
if len(self.regs) > 0: |
| 109 |
self.cb.POP([r.value for r in self.regs]) |
| 110 |
|
| 111 |
def count_reg_args(args): |
| 112 |
reg_args = 0 |
| 113 |
words = 0 |
| 114 |
count = 0 |
| 115 |
for x in range(min(len(args), 4)): |
| 116 |
if args[x].type == FLOAT: |
| 117 |
words += 2 |
| 118 |
if count % 2 != 0: |
| 119 |
words += 1 |
| 120 |
count = 0 |
| 121 |
else: |
| 122 |
count += 1 |
| 123 |
words += 1 |
| 124 |
reg_args += 1 |
| 125 |
if words > 4: |
| 126 |
reg_args = x |
| 127 |
break |
| 128 |
return reg_args |