| 1 |
from rpython.jit.backend.arm import conditions as c |
| 2 |
from rpython.jit.backend.arm import registers as r |
| 3 |
from rpython.jit.metainterp.history import Const, ConstInt, FLOAT |
| 4 |
from rpython.rlib.objectmodel import we_are_translated |
| 5 |
|
| 6 |
VMEM_imm_size=0x3FC |
| 7 |
default_imm_size=0xFF |
| 8 |
|
| 9 |
def check_imm_arg(arg, size=default_imm_size, allow_zero=True): |
| 10 |
assert not isinstance(arg, Const) |
| 11 |
if not we_are_translated(): |
| 12 |
if not isinstance(arg, int): |
| 13 |
import pdb; pdb.set_trace() |
| 14 |
i = arg |
| 15 |
if allow_zero: |
| 16 |
lower_bound = i >= 0 |
| 17 |
else: |
| 18 |
lower_bound = i > 0 |
| 19 |
return i <= size and lower_bound |
| 20 |
|
| 21 |
def check_imm_box(arg, size=0xFF, allow_zero=True): |
| 22 |
if isinstance(arg, ConstInt): |
| 23 |
return check_imm_arg(arg.getint(), size, allow_zero) |
| 24 |
return False |
| 25 |
|
| 26 |
|
| 27 |
def prepare_op_ri(name=None, imm_size=0xFF, commutative=True, allow_zero=True): |
| 28 |
def f(self, op, fcond): |
| 29 |
assert fcond is not None |
| 30 |
a0 = op.getarg(0) |
| 31 |
a1 = op.getarg(1) |
| 32 |
boxes = list(op.getarglist()) |
| 33 |
imm_a0 = check_imm_box(a0, imm_size, allow_zero=allow_zero) |
| 34 |
imm_a1 = check_imm_box(a1, imm_size, allow_zero=allow_zero) |
| 35 |
if not imm_a0 and imm_a1: |
| 36 |
l0 = self.make_sure_var_in_reg(a0) |
| 37 |
l1 = self.convert_to_imm(a1) |
| 38 |
elif commutative and imm_a0 and not imm_a1: |
| 39 |
l1 = self.convert_to_imm(a0) |
| 40 |
l0 = self.make_sure_var_in_reg(a1, boxes) |
| 41 |
else: |
| 42 |
l0 = self.make_sure_var_in_reg(a0, boxes) |
| 43 |
l1 = self.make_sure_var_in_reg(a1, boxes) |
| 44 |
self.possibly_free_vars_for_op(op) |
| 45 |
self.free_temp_vars() |
| 46 |
res = self.force_allocate_reg(op, boxes) |
| 47 |
return [l0, l1, res] |
| 48 |
if name: |
| 49 |
f.__name__ = name |
| 50 |
return f |
| 51 |
|
| 52 |
def prepare_unary_op(self, op, fcond): |
| 53 |
loc1 = self.make_sure_var_in_reg(op.getarg(0)) |
| 54 |
self.possibly_free_vars_for_op(op) |
| 55 |
self.free_temp_vars() |
| 56 |
res = self.force_allocate_reg(op) |
| 57 |
return [loc1, res] |
| 58 |
|
| 59 |
def prepare_two_regs_op(self, op, fcond): |
| 60 |
loc1 = self.make_sure_var_in_reg(op.getarg(0)) |
| 61 |
loc2 = self.make_sure_var_in_reg(op.getarg(1)) |
| 62 |
self.possibly_free_vars_for_op(op) |
| 63 |
self.free_temp_vars() |
| 64 |
res = self.force_allocate_reg(op) |
| 65 |
return [loc1, loc2, res] |
| 66 |
|
| 67 |
def prepare_float_cmp(self, op, fcond): |
| 68 |
loc1 = self.make_sure_var_in_reg(op.getarg(0)) |
| 69 |
loc2 = self.make_sure_var_in_reg(op.getarg(1)) |
| 70 |
self.possibly_free_vars_for_op(op) |
| 71 |
self.free_temp_vars() |
| 72 |
res = self.force_allocate_reg_or_cc(op) |
| 73 |
return [loc1, loc2, res] |
| 74 |
|
| 75 |
def prepare_int_cmp(self, op, fcond): |
| 76 |
assert fcond is not None |
| 77 |
boxes = list(op.getarglist()) |
| 78 |
arg0, arg1 = boxes |
| 79 |
imm_a1 = check_imm_box(arg1) |
| 80 |
|
| 81 |
l0 = self.make_sure_var_in_reg(arg0, forbidden_vars=boxes) |
| 82 |
if imm_a1: |
| 83 |
l1 = self.convert_to_imm(arg1) |
| 84 |
else: |
| 85 |
l1 = self.make_sure_var_in_reg(arg1, forbidden_vars=boxes) |
| 86 |
|
| 87 |
self.possibly_free_vars_for_op(op) |
| 88 |
self.free_temp_vars() |
| 89 |
res = self.force_allocate_reg_or_cc(op) |
| 90 |
return [l0, l1, res] |
| 91 |
|
| 92 |
def prepare_unary_cmp(self, op, fcond): |
| 93 |
assert fcond is not None |
| 94 |
a0 = op.getarg(0) |
| 95 |
assert not isinstance(a0, Const) |
| 96 |
reg = self.make_sure_var_in_reg(a0) |
| 97 |
self.possibly_free_vars_for_op(op) |
| 98 |
res = self.force_allocate_reg_or_cc(op) |
| 99 |
return [reg, res] |