| 1 |
|
| 2 |
from rpython.rlib.objectmodel import we_are_translated |
| 3 |
from rpython.rlib.rarithmetic import r_uint |
| 4 |
from rpython.rtyper.lltypesystem import rffi, lltype |
| 5 |
from rpython.rtyper import rclass |
| 6 |
from rpython.jit.metainterp.history import (AbstractFailDescr, ConstInt, |
| 7 |
INT, FLOAT, REF, VOID) |
| 8 |
from rpython.jit.backend.aarch64 import registers as r |
| 9 |
from rpython.jit.backend.aarch64.codebuilder import OverwritingBuilder |
| 10 |
from rpython.jit.backend.aarch64.callbuilder import Aarch64CallBuilder |
| 11 |
from rpython.jit.backend.arm import conditions as c, shift |
| 12 |
from rpython.jit.backend.aarch64.regalloc import check_imm_arg |
| 13 |
from rpython.jit.backend.aarch64.arch import JITFRAME_FIXED_SIZE, WORD |
| 14 |
from rpython.jit.backend.aarch64 import locations |
| 15 |
from rpython.jit.backend.llsupport.assembler import GuardToken, BaseAssembler |
| 16 |
from rpython.jit.backend.llsupport.gcmap import allocate_gcmap |
| 17 |
from rpython.jit.backend.llsupport.regalloc import get_scale |
| 18 |
from rpython.jit.metainterp.history import TargetToken |
| 19 |
from rpython.jit.metainterp.resoperation import rop |
| 20 |
|
| 21 |
def gen_comp_op(name, flag): |
| 22 |
def emit_op(self, op, arglocs): |
| 23 |
l0, l1, res = arglocs |
| 24 |
|
| 25 |
self.emit_int_comp_op(op, l0, l1) |
| 26 |
self.mc.CSET_r_flag(res.value, c.get_opposite_of(flag)) |
| 27 |
emit_op.__name__ = name |
| 28 |
return emit_op |
| 29 |
|
| 30 |
def gen_float_comp_op(name, flag): |
| 31 |
def emit_op(self, op, arglocs): |
| 32 |
l0, l1, res = arglocs |
| 33 |
self.emit_float_comp_op(op, l0, l1) |
| 34 |
self.mc.CSET_r_flag(res.value, c.get_opposite_of(flag)) |
| 35 |
emit_op.__name__ = name |
| 36 |
return emit_op |
| 37 |
|
| 38 |
def gen_float_comp_op_cc(name, flag): |
| 39 |
def emit_op(self, op, arglocs): |
| 40 |
l0, l1 = arglocs |
| 41 |
self.emit_float_comp_op(op, l0, l1) |
| 42 |
return flag |
| 43 |
emit_op.__name__ = name |
| 44 |
return emit_op |
| 45 |
|
| 46 |
class ResOpAssembler(BaseAssembler): |
| 47 |
def imm(self, v): |
| 48 |
return locations.imm(v) |
| 49 |
|
| 50 |
def int_sub_impl(self, op, arglocs, flags=0): |
| 51 |
l0, l1, res = arglocs |
| 52 |
if flags: |
| 53 |
s = 1 |
| 54 |
else: |
| 55 |
s = 0 |
| 56 |
if l1.is_imm(): |
| 57 |
value = l1.getint() |
| 58 |
assert value >= 0 |
| 59 |
self.mc.SUB_ri(res.value, l0.value, value, s) |
| 60 |
else: |
| 61 |
self.mc.SUB_rr(res.value, l0.value, l1.value, s) |
| 62 |
|
| 63 |
def emit_op_int_sub(self, op, arglocs): |
| 64 |
self.int_sub_impl(op, arglocs) |
| 65 |
|
| 66 |
def int_add_impl(self, op, arglocs, ovfcheck=False): |
| 67 |
l0, l1, res = arglocs |
| 68 |
assert not l0.is_imm() |
| 69 |
if ovfcheck: |
| 70 |
s = 1 |
| 71 |
else: |
| 72 |
s = 0 |
| 73 |
if l1.is_imm(): |
| 74 |
self.mc.ADD_ri(res.value, l0.value, l1.value, s) |
| 75 |
else: |
| 76 |
self.mc.ADD_rr(res.value, l0.value, l1.value, s) |
| 77 |
|
| 78 |
def emit_op_int_add(self, op, arglocs): |
| 79 |
self.int_add_impl(op, arglocs) |
| 80 |
emit_op_nursery_ptr_increment = emit_op_int_add |
| 81 |
|
| 82 |
def emit_comp_op_int_add_ovf(self, op, arglocs): |
| 83 |
self.int_add_impl(op, arglocs, True) |
| 84 |
return 0 |
| 85 |
|
| 86 |
def emit_comp_op_int_sub_ovf(self, op, arglocs): |
| 87 |
self.int_sub_impl(op, arglocs, True) |
| 88 |
return 0 |
| 89 |
|
| 90 |
def emit_op_int_mul(self, op, arglocs): |
| 91 |
reg1, reg2, res = arglocs |
| 92 |
self.mc.MUL_rr(res.value, reg1.value, reg2.value) |
| 93 |
|
| 94 |
def emit_comp_op_int_mul_ovf(self, op, arglocs): |
| 95 |
reg1, reg2, res = arglocs |
| 96 |
self.mc.SMULH_rr(r.ip0.value, reg1.value, reg2.value) |
| 97 |
self.mc.MUL_rr(res.value, reg1.value, reg2.value) |
| 98 |
self.mc.CMP_rr_shifted(r.ip0.value, res.value, 63) |
| 99 |
return 0 |
| 100 |
|
| 101 |
def emit_op_int_and(self, op, arglocs): |
| 102 |
l0, l1, res = arglocs |
| 103 |
self.mc.AND_rr(res.value, l0.value, l1.value) |
| 104 |
|
| 105 |
def emit_op_int_or(self, op, arglocs): |
| 106 |
l0, l1, res = arglocs |
| 107 |
self.mc.ORR_rr(res.value, l0.value, l1.value) |
| 108 |
|
| 109 |
def emit_op_int_xor(self, op, arglocs): |
| 110 |
l0, l1, res = arglocs |
| 111 |
self.mc.EOR_rr(res.value, l0.value, l1.value) |
| 112 |
|
| 113 |
def emit_op_int_lshift(self, op, arglocs): |
| 114 |
l0, l1, res = arglocs |
| 115 |
self.mc.LSL_rr(res.value, l0.value, l1.value) |
| 116 |
|
| 117 |
def emit_op_int_rshift(self, op, arglocs): |
| 118 |
l0, l1, res = arglocs |
| 119 |
self.mc.ASR_rr(res.value, l0.value, l1.value) |
| 120 |
|
| 121 |
def emit_op_uint_rshift(self, op, arglocs): |
| 122 |
l0, l1, res = arglocs |
| 123 |
self.mc.LSR_rr(res.value, l0.value, l1.value) |
| 124 |
|
| 125 |
def emit_op_uint_mul_high(self, op, arglocs): |
| 126 |
l0, l1, res = arglocs |
| 127 |
self.mc.UMULH_rr(res.value, l0.value, l1.value) |
| 128 |
|
| 129 |
def emit_int_comp_op(self, op, l0, l1): |
| 130 |
if l1.is_imm(): |
| 131 |
self.mc.CMP_ri(l0.value, l1.getint()) |
| 132 |
else: |
| 133 |
self.mc.CMP_rr(l0.value, l1.value) |
| 134 |
|
| 135 |
def emit_float_comp_op(self, op, l0, l1): |
| 136 |
self.mc.FCMP_dd(l0.value, l1.value) |
| 137 |
|
| 138 |
emit_comp_op_float_lt = gen_float_comp_op_cc('float_lt', c.VFP_LT) |
| 139 |
emit_comp_op_float_le = gen_float_comp_op_cc('float_le', c.VFP_LE) |
| 140 |
emit_comp_op_float_eq = gen_float_comp_op_cc('float_eq', c.EQ) |
| 141 |
emit_comp_op_float_ne = gen_float_comp_op_cc('float_ne', c.NE) |
| 142 |
emit_comp_op_float_gt = gen_float_comp_op_cc('float_gt', c.GT) |
| 143 |
emit_comp_op_float_ge = gen_float_comp_op_cc('float_ge', c.GE) |
| 144 |
|
| 145 |
def emit_comp_op_int_lt(self, op, arglocs): |
| 146 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 147 |
return c.LT |
| 148 |
|
| 149 |
def emit_comp_op_int_le(self, op, arglocs): |
| 150 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 151 |
return c.LE |
| 152 |
|
| 153 |
def emit_comp_op_int_gt(self, op, arglocs): |
| 154 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 155 |
return c.GT |
| 156 |
|
| 157 |
def emit_comp_op_int_ge(self, op, arglocs): |
| 158 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 159 |
return c.GE |
| 160 |
|
| 161 |
def emit_comp_op_int_eq(self, op, arglocs): |
| 162 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 163 |
return c.EQ |
| 164 |
|
| 165 |
emit_comp_op_ptr_eq = emit_comp_op_instance_ptr_eq = emit_comp_op_int_eq |
| 166 |
|
| 167 |
def emit_comp_op_int_ne(self, op, arglocs): |
| 168 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 169 |
return c.NE |
| 170 |
|
| 171 |
emit_comp_op_ptr_ne = emit_comp_op_instance_ptr_ne = emit_comp_op_int_ne |
| 172 |
|
| 173 |
def emit_comp_op_uint_lt(self, op, arglocs): |
| 174 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 175 |
return c.LO |
| 176 |
|
| 177 |
def emit_comp_op_uint_le(self, op, arglocs): |
| 178 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 179 |
return c.LS |
| 180 |
|
| 181 |
def emit_comp_op_uint_gt(self, op, arglocs): |
| 182 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 183 |
return c.HI |
| 184 |
|
| 185 |
def emit_comp_op_uint_ge(self, op, arglocs): |
| 186 |
self.emit_int_comp_op(op, arglocs[0], arglocs[1]) |
| 187 |
return c.HS |
| 188 |
|
| 189 |
emit_op_int_lt = gen_comp_op('emit_op_int_lt', c.LT) |
| 190 |
emit_op_int_le = gen_comp_op('emit_op_int_le', c.LE) |
| 191 |
emit_op_int_gt = gen_comp_op('emit_op_int_gt', c.GT) |
| 192 |
emit_op_int_ge = gen_comp_op('emit_op_int_ge', c.GE) |
| 193 |
emit_op_int_eq = gen_comp_op('emit_op_int_eq', c.EQ) |
| 194 |
emit_op_int_ne = gen_comp_op('emit_op_int_ne', c.NE) |
| 195 |
|
| 196 |
emit_op_uint_lt = gen_comp_op('emit_op_uint_lt', c.LO) |
| 197 |
emit_op_uint_gt = gen_comp_op('emit_op_uint_gt', c.HI) |
| 198 |
emit_op_uint_le = gen_comp_op('emit_op_uint_le', c.LS) |
| 199 |
emit_op_uint_ge = gen_comp_op('emit_op_uint_ge', c.HS) |
| 200 |
|
| 201 |
emit_op_ptr_eq = emit_op_instance_ptr_eq = emit_op_int_eq |
| 202 |
emit_op_ptr_ne = emit_op_instance_ptr_ne = emit_op_int_ne |
| 203 |
|
| 204 |
def emit_op_int_is_true(self, op, arglocs): |
| 205 |
reg, res = arglocs |
| 206 |
|
| 207 |
self.mc.CMP_ri(reg.value, 0) |
| 208 |
self.mc.CSET_r_flag(res.value, c.EQ) |
| 209 |
|
| 210 |
def emit_comp_op_int_is_true(self, op, arglocs): |
| 211 |
self.mc.CMP_ri(arglocs[0].value, 0) |
| 212 |
return c.NE |
| 213 |
|
| 214 |
def emit_op_int_is_zero(self, op, arglocs): |
| 215 |
reg, res = arglocs |
| 216 |
|
| 217 |
self.mc.CMP_ri(reg.value, 0) |
| 218 |
self.mc.CSET_r_flag(res.value, c.NE) |
| 219 |
|
| 220 |
def emit_comp_op_int_is_zero(self, op, arglocs): |
| 221 |
self.mc.CMP_ri(arglocs[0].value, 0) |
| 222 |
return c.EQ |
| 223 |
|
| 224 |
def emit_op_int_neg(self, op, arglocs): |
| 225 |
reg, res = arglocs |
| 226 |
self.mc.SUB_rr_shifted(res.value, r.xzr.value, reg.value) |
| 227 |
|
| 228 |
def emit_op_int_invert(self, op, arglocs): |
| 229 |
reg, res = arglocs |
| 230 |
self.mc.MVN_rr(res.value, reg.value) |
| 231 |
|
| 232 |
def emit_op_int_force_ge_zero(self, op, arglocs): |
| 233 |
arg, res = arglocs |
| 234 |
self.mc.MOVZ_r_u16(res.value, 0, 0) |
| 235 |
self.mc.CMP_ri(arg.value, 0) |
| 236 |
self.mc.B_ofs_cond(8, c.LT) |
| 237 |
self.mc.MOV_rr(res.value, arg.value) |
| 238 |
|
| 239 |
|
| 240 |
def emit_op_int_signext(self, op, arglocs): |
| 241 |
arg, numbytes, res = arglocs |
| 242 |
assert numbytes.is_imm() |
| 243 |
if numbytes.value == 1: |
| 244 |
self.mc.SXTB_rr(res.value, arg.value) |
| 245 |
elif numbytes.value == 2: |
| 246 |
self.mc.SXTH_rr(res.value, arg.value) |
| 247 |
elif numbytes.value == 4: |
| 248 |
self.mc.SXTW_rr(res.value, arg.value) |
| 249 |
else: |
| 250 |
raise AssertionError("bad number of bytes") |
| 251 |
|
| 252 |
def emit_op_increment_debug_counter(self, op, arglocs): |
| 253 |
base_loc, value_loc = arglocs |
| 254 |
self.mc.LDR_ri(value_loc.value, base_loc.value, 0) |
| 255 |
self.mc.ADD_ri(value_loc.value, value_loc.value, 1) |
| 256 |
self.mc.STR_ri(value_loc.value, base_loc.value, 0) |
| 257 |
|
| 258 |
def emit_op_check_memory_error(self, op, arglocs): |
| 259 |
self.propagate_memoryerror_if_reg_is_null(arglocs[0]) |
| 260 |
|
| 261 |
def _genop_same_as(self, op, arglocs): |
| 262 |
argloc, resloc = arglocs |
| 263 |
if argloc is not resloc: |
| 264 |
self.mov_loc_loc(argloc, resloc) |
| 265 |
|
| 266 |
emit_op_same_as_i = _genop_same_as |
| 267 |
emit_op_same_as_r = _genop_same_as |
| 268 |
emit_op_same_as_f = _genop_same_as |
| 269 |
emit_op_cast_ptr_to_int = _genop_same_as |
| 270 |
emit_op_cast_int_to_ptr = _genop_same_as |
| 271 |
|
| 272 |
def emit_op_float_add(self, op, arglocs): |
| 273 |
arg1, arg2, res = arglocs |
| 274 |
self.mc.FADD_dd(res.value, arg1.value, arg2.value) |
| 275 |
|
| 276 |
def emit_op_float_sub(self, op, arglocs): |
| 277 |
arg1, arg2, res = arglocs |
| 278 |
self.mc.FSUB_dd(res.value, arg1.value, arg2.value) |
| 279 |
|
| 280 |
def emit_op_float_mul(self, op, arglocs): |
| 281 |
arg1, arg2, res = arglocs |
| 282 |
self.mc.FMUL_dd(res.value, arg1.value, arg2.value) |
| 283 |
|
| 284 |
def emit_op_float_truediv(self, op, arglocs): |
| 285 |
arg1, arg2, res = arglocs |
| 286 |
self.mc.FDIV_dd(res.value, arg1.value, arg2.value) |
| 287 |
|
| 288 |
def emit_op_convert_float_bytes_to_longlong(self, op, arglocs): |
| 289 |
arg, res = arglocs |
| 290 |
self.mc.UMOV_rd(res.value, arg.value) |
| 291 |
|
| 292 |
def emit_op_convert_longlong_bytes_to_float(self, op, arglocs): |
| 293 |
arg, res = arglocs |
| 294 |
self.mc.INS_dr(res.value, arg.value) |
| 295 |
|
| 296 |
def math_sqrt(self, op, arglocs): |
| 297 |
arg, res = arglocs |
| 298 |
self.mc.FSQRT_dd(res.value, arg.value) |
| 299 |
|
| 300 |
def threadlocalref_get(self, op, arglocs): |
| 301 |
res_loc, = arglocs |
| 302 |
ofs_loc = self.imm(op.getarg(1).getint()) |
| 303 |
calldescr = op.getdescr() |
| 304 |
ofs = self.saved_threadlocal_addr |
| 305 |
self.load_reg(self.mc, res_loc, r.sp, ofs) |
| 306 |
scale = get_scale(calldescr.get_result_size()) |
| 307 |
signed = (calldescr.is_result_signed() != 0) |
| 308 |
self._load_from_mem(res_loc, res_loc, ofs_loc, scale, signed) |
| 309 |
|
| 310 |
emit_op_float_lt = gen_float_comp_op('float_lt', c.VFP_LT) |
| 311 |
emit_op_float_le = gen_float_comp_op('float_le', c.VFP_LE) |
| 312 |
emit_op_float_eq = gen_float_comp_op('float_eq', c.EQ) |
| 313 |
emit_op_float_ne = gen_float_comp_op('float_ne', c.NE) |
| 314 |
emit_op_float_gt = gen_float_comp_op('float_gt', c.GT) |
| 315 |
emit_op_float_ge = gen_float_comp_op('float_ge', c.GE) |
| 316 |
|
| 317 |
def emit_op_float_neg(self, op, arglocs): |
| 318 |
arg, res = arglocs |
| 319 |
self.mc.FNEG_d(res.value, arg.value) |
| 320 |
|
| 321 |
def emit_op_float_abs(self, op, arglocs): |
| 322 |
arg, res = arglocs |
| 323 |
self.mc.FABS_d(res.value, arg.value) |
| 324 |
|
| 325 |
def emit_op_cast_float_to_int(self, op, arglocs): |
| 326 |
arg, res = arglocs |
| 327 |
self.mc.FCVTZS_d(res.value, arg.value) |
| 328 |
|
| 329 |
def emit_op_cast_int_to_float(self, op, arglocs): |
| 330 |
arg, res = arglocs |
| 331 |
self.mc.SCVTF_r(res.value, arg.value) |
| 332 |
|
| 333 |
def emit_op_load_from_gc_table(self, op, arglocs): |
| 334 |
res_loc, = arglocs |
| 335 |
index = op.getarg(0).getint() |
| 336 |
self.load_from_gc_table(res_loc.value, index) |
| 337 |
|
| 338 |
def emit_op_load_effective_address(self, op, arglocs): |
| 339 |
self._gen_address(arglocs[4], arglocs[0], arglocs[1], arglocs[3].value, |
| 340 |
arglocs[2].value) |
| 341 |
|
| 342 |
|
| 343 |
def _gen_address(self, result, base_loc, scaled_loc, scale=0, static_offset=0): |
| 344 |
assert scaled_loc.is_core_reg() |
| 345 |
assert base_loc.is_core_reg() |
| 346 |
if scale > 0: |
| 347 |
self.mc.LSL_ri(r.ip0.value, scaled_loc.value, scale) |
| 348 |
scaled_loc = r.ip0 |
| 349 |
else: |
| 350 |
scaled_loc = scaled_loc |
| 351 |
self.mc.ADD_rr(result.value, base_loc.value, scaled_loc.value) |
| 352 |
self.mc.ADD_ri(result.value, result.value, static_offset) |
| 353 |
|
| 354 |
def emit_op_debug_merge_point(self, op, arglocs): |
| 355 |
pass |
| 356 |
|
| 357 |
emit_op_jit_debug = emit_op_debug_merge_point |
| 358 |
emit_op_keepalive = emit_op_debug_merge_point |
| 359 |
emit_op_enter_portal_frame = emit_op_debug_merge_point |
| 360 |
emit_op_leave_portal_frame = emit_op_debug_merge_point |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
def emit_op_gc_store(self, op, arglocs): |
| 366 |
value_loc, base_loc, ofs_loc, size_loc = arglocs |
| 367 |
scale = get_scale(size_loc.value) |
| 368 |
self._write_to_mem(value_loc, base_loc, ofs_loc, scale) |
| 369 |
|
| 370 |
def _emit_op_gc_load(self, op, arglocs): |
| 371 |
base_loc, ofs_loc, res_loc, nsize_loc = arglocs |
| 372 |
nsize = nsize_loc.value |
| 373 |
signed = (nsize < 0) |
| 374 |
scale = get_scale(abs(nsize)) |
| 375 |
self._load_from_mem(res_loc, base_loc, ofs_loc, scale, signed) |
| 376 |
|
| 377 |
emit_op_gc_load_i = _emit_op_gc_load |
| 378 |
emit_op_gc_load_r = _emit_op_gc_load |
| 379 |
emit_op_gc_load_f = _emit_op_gc_load |
| 380 |
|
| 381 |
def emit_op_gc_store_indexed(self, op, arglocs): |
| 382 |
value_loc, base_loc, index_loc, size_loc, ofs_loc = arglocs |
| 383 |
assert index_loc.is_core_reg() |
| 384 |
|
| 385 |
if ofs_loc.value != 0: |
| 386 |
if check_imm_arg(ofs_loc.value): |
| 387 |
self.mc.ADD_ri(r.ip0.value, index_loc.value, ofs_loc.value) |
| 388 |
else: |
| 389 |
|
| 390 |
self.load(r.ip0, ofs_loc) |
| 391 |
self.mc.ADD_rr(r.ip0.value, r.ip0.value, index_loc.value) |
| 392 |
index_loc = r.ip0 |
| 393 |
scale = get_scale(size_loc.value) |
| 394 |
self._write_to_mem(value_loc, base_loc, index_loc, scale) |
| 395 |
|
| 396 |
def _emit_op_gc_load_indexed(self, op, arglocs): |
| 397 |
res_loc, base_loc, index_loc, nsize_loc, ofs_loc = arglocs |
| 398 |
assert index_loc.is_core_reg() |
| 399 |
nsize = nsize_loc.value |
| 400 |
signed = (nsize < 0) |
| 401 |
|
| 402 |
if ofs_loc.value != 0: |
| 403 |
if check_imm_arg(ofs_loc.value): |
| 404 |
self.mc.ADD_ri(r.ip0.value, index_loc.value, ofs_loc.value) |
| 405 |
else: |
| 406 |
|
| 407 |
self.load(r.ip0, ofs_loc) |
| 408 |
self.mc.ADD_rr(r.ip0.value, r.ip0.value, index_loc.value) |
| 409 |
index_loc = r.ip0 |
| 410 |
|
| 411 |
scale = get_scale(abs(nsize)) |
| 412 |
self._load_from_mem(res_loc, base_loc, index_loc, scale, signed) |
| 413 |
|
| 414 |
emit_op_gc_load_indexed_i = _emit_op_gc_load_indexed |
| 415 |
emit_op_gc_load_indexed_r = _emit_op_gc_load_indexed |
| 416 |
emit_op_gc_load_indexed_f = _emit_op_gc_load_indexed |
| 417 |
|
| 418 |
def _write_to_mem(self, value_loc, base_loc, ofs_loc, scale): |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
assert base_loc.is_core_reg() |
| 423 |
if scale == 3: |
| 424 |
|
| 425 |
if value_loc.is_float(): |
| 426 |
if ofs_loc.is_imm(): |
| 427 |
self.mc.STR_di(value_loc.value, base_loc.value, |
| 428 |
ofs_loc.value) |
| 429 |
else: |
| 430 |
self.mc.STR_dd(value_loc.value, base_loc.value, |
| 431 |
ofs_loc.value) |
| 432 |
return |
| 433 |
if ofs_loc.is_imm(): |
| 434 |
self.mc.STR_ri(value_loc.value, base_loc.value, |
| 435 |
ofs_loc.value) |
| 436 |
else: |
| 437 |
self.mc.STR_size_rr(3, value_loc.value, base_loc.value, |
| 438 |
ofs_loc.value) |
| 439 |
else: |
| 440 |
if ofs_loc.is_imm(): |
| 441 |
self.mc.STR_size_ri(scale, value_loc.value, base_loc.value, |
| 442 |
ofs_loc.value) |
| 443 |
else: |
| 444 |
self.mc.STR_size_rr(scale, value_loc.value, base_loc.value, |
| 445 |
ofs_loc.value) |
| 446 |
|
| 447 |
def _load_from_mem(self, res_loc, base_loc, ofs_loc, scale, |
| 448 |
signed=False): |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
if scale == 3: |
| 454 |
|
| 455 |
if res_loc.is_float(): |
| 456 |
if ofs_loc.is_imm(): |
| 457 |
self.mc.LDR_di(res_loc.value, base_loc.value, ofs_loc.value) |
| 458 |
else: |
| 459 |
self.mc.LDR_dr(res_loc.value, base_loc.value, ofs_loc.value) |
| 460 |
return |
| 461 |
if ofs_loc.is_imm(): |
| 462 |
self.mc.LDR_ri(res_loc.value, base_loc.value, ofs_loc.value) |
| 463 |
else: |
| 464 |
self.mc.LDR_rr(res_loc.value, base_loc.value, ofs_loc.value) |
| 465 |
return |
| 466 |
if scale == 2: |
| 467 |
|
| 468 |
if not signed: |
| 469 |
if ofs_loc.is_imm(): |
| 470 |
self.mc.LDR_uint32_ri(res_loc.value, base_loc.value, |
| 471 |
ofs_loc.value) |
| 472 |
else: |
| 473 |
self.mc.LDR_uint32_rr(res_loc.value, base_loc.value, |
| 474 |
ofs_loc.value) |
| 475 |
else: |
| 476 |
if ofs_loc.is_imm(): |
| 477 |
self.mc.LDRSW_ri(res_loc.value, base_loc.value, |
| 478 |
ofs_loc.value) |
| 479 |
else: |
| 480 |
self.mc.LDRSW_rr(res_loc.value, base_loc.value, |
| 481 |
ofs_loc.value) |
| 482 |
return |
| 483 |
if scale == 1: |
| 484 |
|
| 485 |
if not signed: |
| 486 |
if ofs_loc.is_imm(): |
| 487 |
self.mc.LDRH_ri(res_loc.value, base_loc.value, ofs_loc.value) |
| 488 |
else: |
| 489 |
self.mc.LDRH_rr(res_loc.value, base_loc.value, ofs_loc.value) |
| 490 |
else: |
| 491 |
if ofs_loc.is_imm(): |
| 492 |
self.mc.LDRSH_ri(res_loc.value, base_loc.value, ofs_loc.value) |
| 493 |
else: |
| 494 |
self.mc.LDRSH_rr(res_loc.value, base_loc.value, ofs_loc.value) |
| 495 |
return |
| 496 |
assert scale == 0 |
| 497 |
if not signed: |
| 498 |
if ofs_loc.is_imm(): |
| 499 |
self.mc.LDRB_ri(res_loc.value, base_loc.value, ofs_loc.value) |
| 500 |
else: |
| 501 |
self.mc.LDRB_rr(res_loc.value, base_loc.value, ofs_loc.value) |
| 502 |
else: |
| 503 |
if ofs_loc.is_imm(): |
| 504 |
self.mc.LDRSB_ri(res_loc.value, base_loc.value, ofs_loc.value) |
| 505 |
else: |
| 506 |
self.mc.LDRSB_rr(res_loc.value, base_loc.value, ofs_loc.value) |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
def build_guard_token(self, op, frame_depth, arglocs, offset, fcond, |
| 511 |
extra_offset=-1, extra_cond=-1): |
| 512 |
descr = op.getdescr() |
| 513 |
assert isinstance(descr, AbstractFailDescr) |
| 514 |
|
| 515 |
gcmap = allocate_gcmap(self, frame_depth, JITFRAME_FIXED_SIZE) |
| 516 |
faildescrindex = self.get_gcref_from_faildescr(descr) |
| 517 |
token = GuardToken(self.cpu, gcmap, descr, |
| 518 |
failargs=op.getfailargs(), |
| 519 |
fail_locs=arglocs, |
| 520 |
guard_opnum=op.getopnum(), |
| 521 |
frame_depth=frame_depth, |
| 522 |
faildescrindex=faildescrindex) |
| 523 |
token.fcond = fcond |
| 524 |
token.extra_offset = extra_offset |
| 525 |
token.extra_cond = extra_cond |
| 526 |
return token |
| 527 |
|
| 528 |
def _emit_guard(self, op, fcond, arglocs, is_guard_not_invalidated=False, |
| 529 |
extra_offset=-1, extra_cond=-1): |
| 530 |
pos = self.mc.currpos() |
| 531 |
token = self.build_guard_token(op, arglocs[0].value, arglocs[1:], pos, |
| 532 |
fcond, extra_offset, extra_cond) |
| 533 |
token.offset = pos |
| 534 |
self.pending_guards.append(token) |
| 535 |
assert token.guard_not_invalidated() == is_guard_not_invalidated |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
if is_guard_not_invalidated: |
| 541 |
self.mc.NOP() |
| 542 |
else: |
| 543 |
self.mc.BRK() |
| 544 |
|
| 545 |
def emit_guard_op_guard_true(self, op, guard_op, fcond, arglocs): |
| 546 |
self._emit_guard(guard_op, fcond, arglocs) |
| 547 |
emit_guard_op_guard_no_overflow = emit_guard_op_guard_true |
| 548 |
|
| 549 |
def emit_guard_op_guard_false(self, op, guard_op, fcond, arglocs): |
| 550 |
self._emit_guard(guard_op, c.get_opposite_of(fcond), arglocs) |
| 551 |
emit_guard_op_guard_overflow = emit_guard_op_guard_false |
| 552 |
|
| 553 |
def emit_op_guard_not_invalidated(self, op, arglocs): |
| 554 |
self._emit_guard(op, 0, arglocs, True) |
| 555 |
|
| 556 |
def load_condition_into_cc(self, loc): |
| 557 |
if not loc.is_core_reg(): |
| 558 |
if loc.is_stack(): |
| 559 |
self.regalloc_mov(loc, r.ip0) |
| 560 |
else: |
| 561 |
assert loc.is_imm() |
| 562 |
self.mc.gen_load_int(r.ip0.value, loc.value) |
| 563 |
loc = r.ip0 |
| 564 |
self.mc.CMP_ri(loc.value, 0) |
| 565 |
|
| 566 |
def emit_op_guard_false(self, op, arglocs): |
| 567 |
self.load_condition_into_cc(arglocs[0]) |
| 568 |
self._emit_guard(op, c.EQ, arglocs[1:]) |
| 569 |
emit_op_guard_isnull = emit_op_guard_false |
| 570 |
|
| 571 |
def emit_op_guard_true(self, op, arglocs): |
| 572 |
self.load_condition_into_cc(arglocs[0]) |
| 573 |
self._emit_guard(op, c.NE, arglocs[1:]) |
| 574 |
emit_op_guard_nonnull = emit_op_guard_true |
| 575 |
|
| 576 |
def emit_op_guard_value(self, op, arglocs): |
| 577 |
v0 = arglocs[0] |
| 578 |
v1 = arglocs[1] |
| 579 |
if v0.is_core_reg(): |
| 580 |
if v1.is_core_reg(): |
| 581 |
loc = v1 |
| 582 |
elif v1.is_imm(): |
| 583 |
self.mc.gen_load_int(r.ip0.value, v1.value) |
| 584 |
loc = r.ip0 |
| 585 |
else: |
| 586 |
assert v1.is_stack() |
| 587 |
self.mc.LDR_ri(r.ip0.value, r.fp.value, v1.value) |
| 588 |
loc = r.ip0 |
| 589 |
self.mc.CMP_rr(v0.value, loc.value) |
| 590 |
else: |
| 591 |
assert v0.is_vfp_reg() |
| 592 |
if v1.is_vfp_reg(): |
| 593 |
loc = v1 |
| 594 |
else: |
| 595 |
assert v1.is_stack() |
| 596 |
loc = r.vfp_ip |
| 597 |
self.mc.LDR_di(r.vfp_ip.value, r.fp.value, v1.value) |
| 598 |
self.mc.FCMP_dd(v0.value, loc.value) |
| 599 |
self._emit_guard(op, c.EQ, arglocs[2:]) |
| 600 |
|
| 601 |
def emit_op_guard_class(self, op, arglocs): |
| 602 |
offset = self.cpu.vtable_offset |
| 603 |
if offset is not None: |
| 604 |
self.mc.LDR_ri(r.ip0.value, arglocs[0].value, offset) |
| 605 |
self.mc.gen_load_int(r.ip1.value, arglocs[1].value) |
| 606 |
self.mc.CMP_rr(r.ip0.value, r.ip1.value) |
| 607 |
else: |
| 608 |
expected_typeid = (self.cpu.gc_ll_descr |
| 609 |
.get_typeid_from_classptr_if_gcremovetypeptr(arglocs[1].value)) |
| 610 |
self._cmp_guard_gc_type(arglocs[0], expected_typeid) |
| 611 |
self._emit_guard(op, c.EQ, arglocs[2:]) |
| 612 |
|
| 613 |
def _cmp_guard_gc_type(self, loc_ptr, expected_typeid): |
| 614 |
|
| 615 |
|
| 616 |
assert self.cpu.supports_guard_gc_type |
| 617 |
self.mc.LDR_uint32_ri(r.ip0.value, loc_ptr.value, 0) |
| 618 |
self.mc.gen_load_int(r.ip1.value, expected_typeid) |
| 619 |
self.mc.CMP_rr(r.ip0.value, r.ip1.value) |
| 620 |
|
| 621 |
def emit_op_guard_nonnull_class(self, op, arglocs): |
| 622 |
offset = self.cpu.vtable_offset |
| 623 |
if offset is not None: |
| 624 |
|
| 625 |
|
| 626 |
self.mc.MOVZ_r_u16(r.ip0.value, 1, 0) |
| 627 |
self.mc.MOVZ_r_u16(r.ip1.value, 0, 0) |
| 628 |
self.mc.CMP_ri(arglocs[0].value, 0) |
| 629 |
self.mc.B_ofs_cond(4 * (4 + 2), c.EQ) |
| 630 |
self.mc.LDR_ri(r.ip0.value, arglocs[0].value, offset) |
| 631 |
self.mc.gen_load_int_full(r.ip1.value, arglocs[1].value) |
| 632 |
self.mc.CMP_rr(r.ip0.value, r.ip1.value) |
| 633 |
self._emit_guard(op, c.EQ, arglocs[2:]) |
| 634 |
else: |
| 635 |
self.mc.CMP_ri(arglocs[0].value, 0) |
| 636 |
extra_offset = self.mc.currpos() |
| 637 |
self.mc.BRK() |
| 638 |
expected_typeid = (self.cpu.gc_ll_descr |
| 639 |
.get_typeid_from_classptr_if_gcremovetypeptr(arglocs[1].value)) |
| 640 |
self._cmp_guard_gc_type(arglocs[0], expected_typeid) |
| 641 |
self._emit_guard(op, c.EQ, arglocs[2:], False, extra_offset, c.NE) |
| 642 |
|
| 643 |
def emit_op_guard_gc_type(self, op, arglocs): |
| 644 |
self._cmp_guard_gc_type(arglocs[0], arglocs[1].value) |
| 645 |
self._emit_guard(op, c.EQ, arglocs[2:]) |
| 646 |
|
| 647 |
def emit_op_guard_is_object(self, op, arglocs): |
| 648 |
assert self.cpu.supports_guard_gc_type |
| 649 |
loc_object = arglocs[0] |
| 650 |
|
| 651 |
|
| 652 |
self.mc.LDR_uint32_ri(r.ip0.value, loc_object.value, 0) |
| 653 |
|
| 654 |
|
| 655 |
base_type_info, shift_by, sizeof_ti = ( |
| 656 |
self.cpu.gc_ll_descr.get_translated_info_for_typeinfo()) |
| 657 |
infobits_offset, IS_OBJECT_FLAG = ( |
| 658 |
self.cpu.gc_ll_descr.get_translated_info_for_guard_is_object()) |
| 659 |
|
| 660 |
self.mc.gen_load_int(r.ip1.value, base_type_info + infobits_offset) |
| 661 |
if shift_by > 0: |
| 662 |
self.mc.LSL_ri(r.ip0.value, r.ip0.value, shift_by) |
| 663 |
self.mc.LDRB_rr(r.ip0.value, r.ip0.value, r.ip1.value) |
| 664 |
self.mc.MOVZ_r_u16(r.ip1.value, IS_OBJECT_FLAG & 0xff, 0) |
| 665 |
self.mc.TST_rr_shift(r.ip0.value, r.ip1.value, 0) |
| 666 |
self._emit_guard(op, c.NE, arglocs[1:]) |
| 667 |
|
| 668 |
def emit_op_guard_subclass(self, op, arglocs): |
| 669 |
assert self.cpu.supports_guard_gc_type |
| 670 |
loc_object = arglocs[0] |
| 671 |
loc_check_against_class = arglocs[1] |
| 672 |
offset = self.cpu.vtable_offset |
| 673 |
offset2 = self.cpu.subclassrange_min_offset |
| 674 |
if offset is not None: |
| 675 |
|
| 676 |
self.mc.LDR_ri(r.ip0.value, loc_object.value, offset) |
| 677 |
|
| 678 |
self.mc.LDR_ri(r.ip0.value, r.ip0.value, offset2) |
| 679 |
else: |
| 680 |
|
| 681 |
self.mc.LDR_uint32_ri(r.ip0.value, loc_object.value, 0) |
| 682 |
|
| 683 |
|
| 684 |
base_type_info, shift_by, sizeof_ti = ( |
| 685 |
self.cpu.gc_ll_descr.get_translated_info_for_typeinfo()) |
| 686 |
|
| 687 |
self.mc.gen_load_int(r.ip1.value, |
| 688 |
base_type_info + sizeof_ti + offset2) |
| 689 |
if shift_by > 0: |
| 690 |
self.mc.LSL_ri(r.ip0.value, r.ip0.value, shift_by) |
| 691 |
self.mc.LDR_rr(r.ip0.value, r.ip0.value, r.ip1.value) |
| 692 |
|
| 693 |
|
| 694 |
vtable_ptr = loc_check_against_class.getint() |
| 695 |
vtable_ptr = rffi.cast(rclass.CLASSTYPE, vtable_ptr) |
| 696 |
check_min = vtable_ptr.subclassrange_min |
| 697 |
check_max = vtable_ptr.subclassrange_max |
| 698 |
assert check_max > check_min |
| 699 |
check_diff = check_max - check_min - 1 |
| 700 |
|
| 701 |
self.mc.gen_load_int(r.ip1.value, check_min) |
| 702 |
self.mc.SUB_rr(r.ip0.value, r.ip0.value, r.ip1.value) |
| 703 |
if check_diff <= 0xff: |
| 704 |
self.mc.CMP_ri(r.ip0.value, check_diff) |
| 705 |
else: |
| 706 |
self.mc.gen_load_int(r.ip1.value, check_diff) |
| 707 |
self.mc.CMP_rr(r.ip0.value, r.ip1.value) |
| 708 |
|
| 709 |
self._emit_guard(op, c.LS, arglocs[2:]) |
| 710 |
|
| 711 |
def emit_op_guard_exception(self, op, arglocs): |
| 712 |
loc, resloc, pos_exc_value, pos_exception = arglocs[:4] |
| 713 |
failargs = arglocs[4:] |
| 714 |
self.mc.gen_load_int(r.ip1.value, pos_exception.value) |
| 715 |
self.mc.LDR_ri(r.ip0.value, r.ip1.value, 0) |
| 716 |
|
| 717 |
self.mc.CMP_rr(r.ip0.value, loc.value) |
| 718 |
self._emit_guard(op, c.EQ, failargs) |
| 719 |
self._store_and_reset_exception(self.mc, resloc) |
| 720 |
|
| 721 |
def emit_op_guard_no_exception(self, op, arglocs): |
| 722 |
loc = arglocs[0] |
| 723 |
failargs = arglocs[1:] |
| 724 |
self.mc.LDR_ri(loc.value, loc.value, 0) |
| 725 |
self.mc.CMP_ri(loc.value, 0) |
| 726 |
self._emit_guard(op, c.EQ, failargs) |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
def emit_op_save_exc_class(self, op, arglocs): |
| 736 |
resloc = arglocs[0] |
| 737 |
self.mc.gen_load_int(r.ip0.value, self.cpu.pos_exception()) |
| 738 |
self.load_reg(self.mc, resloc, r.ip0) |
| 739 |
|
| 740 |
def emit_op_save_exception(self, op, arglocs): |
| 741 |
resloc = arglocs[0] |
| 742 |
self._store_and_reset_exception(self.mc, resloc) |
| 743 |
|
| 744 |
def emit_op_restore_exception(self, op, arglocs): |
| 745 |
self._restore_exception(self.mc, arglocs[1], arglocs[0]) |
| 746 |
|
| 747 |
def emit_op_cond_call_gc_wb(self, op, arglocs): |
| 748 |
self._write_barrier_fastpath(self.mc, op.getdescr(), arglocs) |
| 749 |
|
| 750 |
def emit_op_cond_call_gc_wb_array(self, op, arglocs): |
| 751 |
self._write_barrier_fastpath(self.mc, op.getdescr(), arglocs, |
| 752 |
array=True) |
| 753 |
|
| 754 |
|
| 755 |
def emit_op_zero_array(self, op, arglocs): |
| 756 |
from rpython.jit.backend.llsupport.descr import unpack_arraydescr |
| 757 |
assert len(arglocs) == 0 |
| 758 |
size_box = op.getarg(2) |
| 759 |
if isinstance(size_box, ConstInt) and size_box.getint() == 0: |
| 760 |
return |
| 761 |
itemsize, baseofs, _ = unpack_arraydescr(op.getdescr()) |
| 762 |
args = op.getarglist() |
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
assert args[3].getint() == 1 |
| 768 |
assert args[4].getint() == 1 |
| 769 |
|
| 770 |
base_loc = self._regalloc.rm.make_sure_var_in_reg(args[0], args) |
| 771 |
startbyte_box = args[1] |
| 772 |
if isinstance(startbyte_box, ConstInt): |
| 773 |
startbyte_loc = None |
| 774 |
startbyte = startbyte_box.getint() |
| 775 |
assert startbyte >= 0 |
| 776 |
else: |
| 777 |
startbyte_loc = self._regalloc.rm.make_sure_var_in_reg(startbyte_box, |
| 778 |
args) |
| 779 |
startbyte = -1 |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
dstaddr_loc = r.ip1 |
| 787 |
if startbyte >= 0: |
| 788 |
ofs = baseofs + startbyte |
| 789 |
reg = base_loc.value |
| 790 |
else: |
| 791 |
self.mc.ADD_rr(dstaddr_loc.value, |
| 792 |
base_loc.value, startbyte_loc.value) |
| 793 |
ofs = baseofs |
| 794 |
reg = dstaddr_loc.value |
| 795 |
if check_imm_arg(ofs): |
| 796 |
self.mc.ADD_ri(dstaddr_loc.value, reg, ofs) |
| 797 |
else: |
| 798 |
self.mc.gen_load_int(r.ip0.value, ofs) |
| 799 |
self.mc.ADD_rr(dstaddr_loc.value, reg, r.ip0.value) |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
if itemsize & 1: itemsize = 1 |
| 804 |
elif itemsize & 2: itemsize = 2 |
| 805 |
elif itemsize & 4: itemsize = 4 |
| 806 |
else: itemsize = 8 |
| 807 |
limit = itemsize |
| 808 |
next_group = -1 |
| 809 |
if itemsize < 8 and startbyte >= 0: |
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
next_group = (-startbyte) & 7 |
| 814 |
limit = 8 |
| 815 |
|
| 816 |
if (isinstance(size_box, ConstInt) and |
| 817 |
size_box.getint() <= 14 * limit): |
| 818 |
|
| 819 |
|
| 820 |
self.mc.gen_load_int(r.ip0.value, 0) |
| 821 |
i = dst_i = 0 |
| 822 |
total_size = size_box.getint() |
| 823 |
while i < total_size: |
| 824 |
sz = itemsize |
| 825 |
if i == next_group: |
| 826 |
next_group += 8 |
| 827 |
if next_group <= total_size: |
| 828 |
sz = 8 |
| 829 |
if dst_i % 8: |
| 830 |
self.mc.ADD_ri(dstaddr_loc.value, dstaddr_loc.value, dst_i) |
| 831 |
dst_i = 0 |
| 832 |
if sz == 8: |
| 833 |
self.mc.STR_ri(r.ip0.value, dstaddr_loc.value, dst_i) |
| 834 |
elif sz == 4: |
| 835 |
self.mc.STRW_ri(r.ip0.value, dstaddr_loc.value, dst_i) |
| 836 |
elif sz == 2: |
| 837 |
self.mc.STRH_ri(r.ip0.value, dstaddr_loc.value, dst_i) |
| 838 |
else: |
| 839 |
self.mc.STRB_ri(r.ip0.value, dstaddr_loc.value, dst_i) |
| 840 |
i += sz |
| 841 |
dst_i += sz |
| 842 |
|
| 843 |
else: |
| 844 |
if isinstance(size_box, ConstInt): |
| 845 |
size_loc = self.imm(size_box.getint()) |
| 846 |
else: |
| 847 |
|
| 848 |
size_loc = self._regalloc.rm.make_sure_var_in_reg(size_box, |
| 849 |
[]) |
| 850 |
|
| 851 |
|
| 852 |
self._regalloc.before_call() |
| 853 |
self.simple_call_no_collect(self.imm(self.memset_addr), |
| 854 |
[dstaddr_loc, self.imm(0), size_loc]) |
| 855 |
self._regalloc.rm.possibly_free_var(size_box) |
| 856 |
|
| 857 |
def _emit_op_cond_call(self, op, arglocs, fcond): |
| 858 |
if len(arglocs) == 2: |
| 859 |
res_loc = arglocs[1] |
| 860 |
else: |
| 861 |
res_loc = None |
| 862 |
|
| 863 |
|
| 864 |
if arglocs[0] is not None: |
| 865 |
self.mc.CMP_ri(arglocs[0].value, 0) |
| 866 |
|
| 867 |
gcmap = self._regalloc.get_gcmap([res_loc]) |
| 868 |
|
| 869 |
jmp_adr = self.mc.currpos() |
| 870 |
self.mc.BRK() |
| 871 |
|
| 872 |
self.push_gcmap(self.mc, gcmap) |
| 873 |
self.mc.gen_load_int(r.ip1.value, rffi.cast(lltype.Signed, |
| 874 |
op.getarg(1).getint())) |
| 875 |
|
| 876 |
callee_only = False |
| 877 |
floats = False |
| 878 |
if self._regalloc is not None: |
| 879 |
for reg in self._regalloc.rm.reg_bindings.values(): |
| 880 |
if reg not in self._regalloc.rm.save_around_call_regs: |
| 881 |
break |
| 882 |
else: |
| 883 |
callee_only = True |
| 884 |
if len(self._regalloc.vfprm.reg_bindings): |
| 885 |
floats = True |
| 886 |
cond_call_adr = self.cond_call_slowpath[floats * 2 + callee_only] |
| 887 |
assert cond_call_adr |
| 888 |
|
| 889 |
self.mc.BL(cond_call_adr) |
| 890 |
|
| 891 |
|
| 892 |
if res_loc is not None: |
| 893 |
self.mc.MOV_rr(res_loc.value, r.ip1.value) |
| 894 |
|
| 895 |
self.pop_gcmap(self.mc) |
| 896 |
pmc = OverwritingBuilder(self.mc, jmp_adr, WORD) |
| 897 |
pmc.B_ofs_cond(self.mc.currpos() - jmp_adr, fcond) |
| 898 |
|
| 899 |
|
| 900 |
self.previous_cond_call_jcond = jmp_adr, fcond |
| 901 |
|
| 902 |
def emit_op_cond_call(self, op, arglocs): |
| 903 |
self._emit_op_cond_call(op, arglocs, c.EQ) |
| 904 |
|
| 905 |
def emit_op_cond_call_value_i(self, op, arglocs): |
| 906 |
self._emit_op_cond_call(op, arglocs, c.NE) |
| 907 |
emit_op_cond_call_value_r = emit_op_cond_call_value_i |
| 908 |
|
| 909 |
def emit_guard_op_cond_call(self, prevop, op, fcond, arglocs): |
| 910 |
self._emit_op_cond_call(op, arglocs, c.get_opposite_of(fcond)) |
| 911 |
|
| 912 |
def _write_barrier_fastpath(self, mc, descr, arglocs, array=False, is_frame=False): |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
if we_are_translated(): |
| 918 |
cls = self.cpu.gc_ll_descr.has_write_barrier_class() |
| 919 |
assert cls is not None and isinstance(descr, cls) |
| 920 |
|
| 921 |
card_marking = False |
| 922 |
mask = descr.jit_wb_if_flag_singlebyte |
| 923 |
if array and descr.jit_wb_cards_set != 0: |
| 924 |
|
| 925 |
assert (descr.jit_wb_cards_set_byteofs == |
| 926 |
descr.jit_wb_if_flag_byteofs) |
| 927 |
assert descr.jit_wb_cards_set_singlebyte == -0x80 |
| 928 |
card_marking = True |
| 929 |
mask = descr.jit_wb_if_flag_singlebyte | -0x80 |
| 930 |
|
| 931 |
loc_base = arglocs[0] |
| 932 |
if is_frame: |
| 933 |
assert loc_base is r.fp |
| 934 |
mc.LDRB_ri(r.ip0.value, loc_base.value, descr.jit_wb_if_flag_byteofs) |
| 935 |
mask &= 0xFF |
| 936 |
mc.MOVZ_r_u16(r.ip1.value, mask, 0) |
| 937 |
mc.TST_rr_shift(r.ip0.value, r.ip1.value, 0) |
| 938 |
jz_location = mc.currpos() |
| 939 |
mc.BRK() |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
if card_marking: |
| 944 |
mc.MOVZ_r_u16(r.ip1.value, 0x80, 0) |
| 945 |
|
| 946 |
mc.TST_rr_shift(r.ip0.value, r.ip1.value, 0) |
| 947 |
|
| 948 |
js_location = mc.currpos() |
| 949 |
mc.BRK() |
| 950 |
else: |
| 951 |
js_location = 0 |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
helper_num = card_marking |
| 957 |
if is_frame: |
| 958 |
helper_num = 4 |
| 959 |
elif self._regalloc is not None and len(self._regalloc.vfprm.reg_bindings): |
| 960 |
helper_num += 2 |
| 961 |
if self.wb_slowpath[helper_num] == 0: |
| 962 |
assert not we_are_translated() |
| 963 |
self.cpu.gc_ll_descr.write_barrier_descr = descr |
| 964 |
self._build_wb_slowpath(card_marking, |
| 965 |
bool(len(self._regalloc.vfprm.reg_bindings))) |
| 966 |
assert self.wb_slowpath[helper_num] != 0 |
| 967 |
|
| 968 |
if loc_base is not r.x0: |
| 969 |
|
| 970 |
mc.SUB_ri(r.sp.value, r.sp.value, 2 * WORD) |
| 971 |
mc.STR_ri(r.x0.value, r.sp.value, WORD) |
| 972 |
mc.STR_ri(loc_base.value, r.sp.value, 0) |
| 973 |
mc.MOV_rr(r.x0.value, loc_base.value) |
| 974 |
if is_frame: |
| 975 |
assert loc_base is r.fp |
| 976 |
mc.BL(self.wb_slowpath[helper_num]) |
| 977 |
if loc_base is not r.x0: |
| 978 |
mc.LDR_ri(r.x0.value, r.sp.value, WORD) |
| 979 |
mc.LDR_ri(loc_base.value, r.sp.value, 0) |
| 980 |
mc.ADD_ri(r.sp.value, r.sp.value, 2 * WORD) |
| 981 |
|
| 982 |
if card_marking: |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
jns_location = mc.currpos() |
| 987 |
mc.BRK() |
| 988 |
|
| 989 |
|
| 990 |
offset = mc.currpos() - js_location |
| 991 |
pmc = OverwritingBuilder(mc, js_location, WORD) |
| 992 |
pmc.B_ofs_cond(offset, c.NE) |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
loc_index = arglocs[1] |
| 997 |
assert loc_index.is_core_reg() |
| 998 |
tmp1 = r.ip1 |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
s = 3 + descr.jit_wb_card_page_shift |
| 1003 |
mc.MVN_rr_shifted(r.lr.value, loc_index.value, s, shifttype=shift.LSR) |
| 1004 |
|
| 1005 |
|
| 1006 |
mc.MOVZ_r_u16(r.ip0.value, 7, 0) |
| 1007 |
mc.AND_rr_shift(tmp1.value, r.ip0.value, loc_index.value, |
| 1008 |
descr.jit_wb_card_page_shift, shifttype=shift.LSR) |
| 1009 |
|
| 1010 |
|
| 1011 |
mc.MOVZ_r_u16(r.ip0.value, 1, 0) |
| 1012 |
mc.LSL_rr(tmp1.value, r.ip0.value, tmp1.value) |
| 1013 |
mc.LDRB_rr(r.ip0.value, loc_base.value, r.lr.value) |
| 1014 |
mc.ORR_rr(r.ip0.value, r.ip0.value, tmp1.value) |
| 1015 |
mc.STR_size_rr(0, r.ip0.value, loc_base.value, r.lr.value) |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
offset = mc.currpos() - jns_location |
| 1020 |
pmc = OverwritingBuilder(mc, jns_location, WORD) |
| 1021 |
pmc.B_ofs_cond(offset, c.EQ) |
| 1022 |
|
| 1023 |
offset = mc.currpos() - jz_location |
| 1024 |
pmc = OverwritingBuilder(mc, jz_location, WORD) |
| 1025 |
pmc.B_ofs_cond(offset, c.EQ) |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
def _genop_call(self, op, arglocs): |
| 1030 |
return self._emit_call(op, arglocs) |
| 1031 |
emit_op_call_i = _genop_call |
| 1032 |
emit_op_call_r = _genop_call |
| 1033 |
emit_op_call_f = _genop_call |
| 1034 |
emit_op_call_n = _genop_call |
| 1035 |
|
| 1036 |
def _emit_call(self, op, arglocs): |
| 1037 |
is_call_release_gil = rop.is_call_release_gil(op.getopnum()) |
| 1038 |
|
| 1039 |
from rpython.jit.backend.llsupport.descr import CallDescr |
| 1040 |
|
| 1041 |
func_index = 3 + is_call_release_gil |
| 1042 |
cb = Aarch64CallBuilder(self, arglocs[func_index], |
| 1043 |
arglocs[func_index+1:], arglocs[0]) |
| 1044 |
|
| 1045 |
descr = op.getdescr() |
| 1046 |
assert isinstance(descr, CallDescr) |
| 1047 |
cb.callconv = descr.get_call_conv() |
| 1048 |
cb.argtypes = descr.get_arg_types() |
| 1049 |
cb.restype = descr.get_result_type() |
| 1050 |
sizeloc = arglocs[1] |
| 1051 |
assert sizeloc.is_imm() |
| 1052 |
cb.ressize = sizeloc.value |
| 1053 |
signloc = arglocs[2] |
| 1054 |
assert signloc.is_imm() |
| 1055 |
cb.ressign = signloc.value |
| 1056 |
|
| 1057 |
if is_call_release_gil: |
| 1058 |
saveerrloc = arglocs[3] |
| 1059 |
assert saveerrloc.is_imm() |
| 1060 |
cb.emit_call_release_gil(saveerrloc.value) |
| 1061 |
else: |
| 1062 |
effectinfo = descr.get_extra_info() |
| 1063 |
if effectinfo is None or effectinfo.check_can_collect(): |
| 1064 |
cb.emit() |
| 1065 |
else: |
| 1066 |
cb.emit_no_collect() |
| 1067 |
|
| 1068 |
def simple_call(self, fnloc, arglocs, result_loc=r.x0): |
| 1069 |
if result_loc is None: |
| 1070 |
result_type = VOID |
| 1071 |
result_size = 0 |
| 1072 |
elif result_loc.is_vfp_reg(): |
| 1073 |
result_type = FLOAT |
| 1074 |
result_size = WORD |
| 1075 |
else: |
| 1076 |
result_type = INT |
| 1077 |
result_size = WORD |
| 1078 |
cb = Aarch64CallBuilder(self, fnloc, arglocs, |
| 1079 |
result_loc, result_type, |
| 1080 |
result_size) |
| 1081 |
cb.emit() |
| 1082 |
|
| 1083 |
def simple_call_no_collect(self, fnloc, arglocs): |
| 1084 |
cb = Aarch64CallBuilder(self, fnloc, arglocs) |
| 1085 |
cb.emit_no_collect() |
| 1086 |
|
| 1087 |
def emit_guard_op_guard_not_forced(self, op, guard_op, fcond, arglocs): |
| 1088 |
|
| 1089 |
if rop.is_call_assembler(op.getopnum()): |
| 1090 |
if fcond == 4: |
| 1091 |
[argloc, vloc, result_loc, tmploc] = arglocs[:4] |
| 1092 |
else: |
| 1093 |
[argloc, result_loc, tmploc] = arglocs[:3] |
| 1094 |
vloc = locations.imm(0) |
| 1095 |
guard_locs = arglocs[fcond:] |
| 1096 |
self._store_force_index(guard_op) |
| 1097 |
self.call_assembler(op, argloc, vloc, result_loc, tmploc) |
| 1098 |
else: |
| 1099 |
assert fcond == op.numargs() + 3 |
| 1100 |
call_args = arglocs[:fcond] |
| 1101 |
guard_locs = arglocs[fcond:] |
| 1102 |
self._store_force_index(guard_op) |
| 1103 |
self._emit_call(op, call_args) |
| 1104 |
|
| 1105 |
ofs = self.cpu.get_ofs_of_frame_field('jf_descr') |
| 1106 |
self.mc.LDR_ri(r.ip0.value, r.fp.value, ofs) |
| 1107 |
self.mc.CMP_ri(r.ip0.value, 0) |
| 1108 |
self._emit_guard(guard_op, c.EQ, guard_locs) |
| 1109 |
|
| 1110 |
def _call_assembler_emit_call(self, addr, argloc, resloc): |
| 1111 |
ofs = self.saved_threadlocal_addr |
| 1112 |
|
| 1113 |
|
| 1114 |
self.mc.LDR_ri(r.x1.value, r.sp.value, ofs) |
| 1115 |
self.simple_call(addr, [argloc], result_loc=resloc) |
| 1116 |
|
| 1117 |
def _call_assembler_emit_helper_call(self, addr, arglocs, resloc): |
| 1118 |
self.simple_call(addr, arglocs, result_loc=resloc) |
| 1119 |
|
| 1120 |
def _call_assembler_check_descr(self, value, tmploc): |
| 1121 |
ofs = self.cpu.get_ofs_of_frame_field('jf_descr') |
| 1122 |
self.mc.LDR_ri(r.ip0.value, tmploc.value, ofs) |
| 1123 |
if check_imm_arg(value): |
| 1124 |
self.mc.CMP_ri(r.ip0.value, value) |
| 1125 |
else: |
| 1126 |
self.mc.gen_load_int(r.ip1.value, value) |
| 1127 |
self.mc.CMP_rr(r.ip0.value, r.ip1.value) |
| 1128 |
pos = self.mc.currpos() |
| 1129 |
self.mc.BRK() |
| 1130 |
return pos |
| 1131 |
|
| 1132 |
def _call_assembler_patch_je(self, result_loc, jmp_location): |
| 1133 |
pos = self.mc.currpos() |
| 1134 |
self.mc.BRK() |
| 1135 |
|
| 1136 |
pmc = OverwritingBuilder(self.mc, jmp_location, WORD) |
| 1137 |
pmc.B_ofs_cond(self.mc.currpos() - jmp_location, c.EQ) |
| 1138 |
return pos |
| 1139 |
|
| 1140 |
def _call_assembler_load_result(self, op, result_loc): |
| 1141 |
if op.type != 'v': |
| 1142 |
|
| 1143 |
kind = op.type |
| 1144 |
descr = self.cpu.getarraydescr_for_frame(kind) |
| 1145 |
if kind == FLOAT: |
| 1146 |
ofs = self.cpu.unpack_arraydescr(descr) |
| 1147 |
assert check_imm_arg(ofs) |
| 1148 |
assert result_loc.is_vfp_reg() |
| 1149 |
|
| 1150 |
|
| 1151 |
self.mc.LDR_di(result_loc.value, r.x0.value, ofs) |
| 1152 |
else: |
| 1153 |
assert result_loc is r.x0 |
| 1154 |
ofs = self.cpu.unpack_arraydescr(descr) |
| 1155 |
assert check_imm_arg(ofs) |
| 1156 |
self.mc.LDR_ri(result_loc.value, r.x0.value, ofs) |
| 1157 |
|
| 1158 |
def _call_assembler_patch_jmp(self, jmp_location): |
| 1159 |
|
| 1160 |
currpos = self.mc.currpos() |
| 1161 |
pmc = OverwritingBuilder(self.mc, jmp_location, WORD) |
| 1162 |
pmc.B_ofs(currpos - jmp_location) |
| 1163 |
|
| 1164 |
def _store_force_index(self, guard_op): |
| 1165 |
faildescr = guard_op.getdescr() |
| 1166 |
faildescrindex = self.get_gcref_from_faildescr(faildescr) |
| 1167 |
ofs = self.cpu.get_ofs_of_frame_field('jf_force_descr') |
| 1168 |
self.load_from_gc_table(r.ip0.value, faildescrindex) |
| 1169 |
self.store_reg(self.mc, r.ip0, r.fp, ofs) |
| 1170 |
|
| 1171 |
def emit_op_guard_not_forced_2(self, op, arglocs): |
| 1172 |
self.store_force_descr(op, arglocs[1:], arglocs[0].value) |
| 1173 |
|
| 1174 |
def store_force_descr(self, op, fail_locs, frame_depth): |
| 1175 |
pos = self.mc.currpos() |
| 1176 |
guard_token = self.build_guard_token(op, frame_depth, fail_locs, pos, c.AL) |
| 1177 |
self._finish_gcmap = guard_token.gcmap |
| 1178 |
self._store_force_index(op) |
| 1179 |
self.store_info_on_descr(pos, guard_token) |
| 1180 |
|
| 1181 |
def emit_op_force_token(self, op, arglocs): |
| 1182 |
self.mc.MOV_rr(arglocs[0].value, r.fp.value) |
| 1183 |
|
| 1184 |
def emit_op_label(self, op, arglocs): |
| 1185 |
pass |
| 1186 |
|
| 1187 |
def emit_op_jump(self, op, arglocs): |
| 1188 |
target_token = op.getdescr() |
| 1189 |
assert isinstance(target_token, TargetToken) |
| 1190 |
target = target_token._ll_loop_code |
| 1191 |
if target_token in self.target_tokens_currently_compiling: |
| 1192 |
self.mc.B_ofs(target - self.mc.currpos()) |
| 1193 |
else: |
| 1194 |
self.mc.B(target) |
| 1195 |
|
| 1196 |
def emit_op_finish(self, op, arglocs): |
| 1197 |
base_ofs = self.cpu.get_baseofs_of_frame_field() |
| 1198 |
if len(arglocs) > 0: |
| 1199 |
[return_val] = arglocs |
| 1200 |
self.store_reg(self.mc, return_val, r.fp, base_ofs) |
| 1201 |
ofs = self.cpu.get_ofs_of_frame_field('jf_descr') |
| 1202 |
|
| 1203 |
faildescrindex = self.get_gcref_from_faildescr(op.getdescr()) |
| 1204 |
self.load_from_gc_table(r.ip0.value, faildescrindex) |
| 1205 |
|
| 1206 |
self.store_reg(self.mc, r.ip0, r.fp, ofs) |
| 1207 |
if op.numargs() > 0 and op.getarg(0).type == REF: |
| 1208 |
if self._finish_gcmap: |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
self._finish_gcmap[0] |= r_uint(1) |
| 1213 |
gcmap = self._finish_gcmap |
| 1214 |
else: |
| 1215 |
gcmap = self.gcmap_for_finish |
| 1216 |
self.push_gcmap(self.mc, gcmap) |
| 1217 |
elif self._finish_gcmap: |
| 1218 |
|
| 1219 |
gcmap = self._finish_gcmap |
| 1220 |
self.push_gcmap(self.mc, gcmap) |
| 1221 |
else: |
| 1222 |
|
| 1223 |
|
| 1224 |
ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap') |
| 1225 |
self.store_reg(self.mc, r.xzr, r.fp, ofs) |
| 1226 |
self.mc.MOV_rr(r.x0.value, r.fp.value) |
| 1227 |
|
| 1228 |
self.gen_func_epilog() |