| 1 |
from rpython.jit.metainterp.compile import ResumeGuardDescr |
| 2 |
from rpython.jit.metainterp.history import (ConstInt, INT, FLOAT) |
| 3 |
from rpython.jit.backend.llsupport.descr import (ArrayDescr, |
| 4 |
unpack_arraydescr) |
| 5 |
from rpython.jit.metainterp.resoperation import VectorOp, rop |
| 6 |
from rpython.rlib.objectmodel import we_are_translated |
| 7 |
from rpython.rtyper.lltypesystem.lloperation import llop |
| 8 |
from rpython.rtyper.lltypesystem import lltype |
| 9 |
from rpython.jit.backend.zarch.detect_feature import detect_simd_z |
| 10 |
import rpython.jit.backend.zarch.registers as r |
| 11 |
import rpython.jit.backend.zarch.conditions as c |
| 12 |
import rpython.jit.backend.zarch.locations as l |
| 13 |
import rpython.jit.backend.zarch.masks as m |
| 14 |
from rpython.jit.backend.zarch.locations import imm |
| 15 |
from rpython.rtyper.lltypesystem import rffi |
| 16 |
from rpython.jit.codewriter import longlong |
| 17 |
from rpython.rlib.objectmodel import always_inline |
| 18 |
from rpython.jit.backend.zarch.arch import WORD |
| 19 |
from rpython.jit.backend.llsupport.vector_ext import (VectorExt, |
| 20 |
OpRestrict, TR_INT64_2) |
| 21 |
|
| 22 |
def not_implemented(msg): |
| 23 |
msg = '[zarch/vector_ext] %s\n' % msg |
| 24 |
if we_are_translated(): |
| 25 |
llop.debug_print(lltype.Void, msg) |
| 26 |
raise NotImplementedError(msg) |
| 27 |
|
| 28 |
@always_inline |
| 29 |
def permi(v1,v2): |
| 30 |
return l.imm((v1 << 2 | v2) & 0xf) |
| 31 |
|
| 32 |
def flush_vec_cc(asm, regalloc, condition, size, resultloc): |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
if resultloc is r.SPP: |
| 41 |
asm.guard_success_cc = condition |
| 42 |
else: |
| 43 |
ones = regalloc.vrm.get_scratch_reg() |
| 44 |
zeros = regalloc.vrm.get_scratch_reg() |
| 45 |
asm.mc.VX(zeros, zeros, zeros) |
| 46 |
asm.mc.VREPI(ones, l.imm(1), l.itemsize_to_mask(size)) |
| 47 |
asm.mc.VSEL(resultloc, ones, zeros, resultloc) |
| 48 |
|
| 49 |
class ZSIMDVectorExt(VectorExt): |
| 50 |
def setup_once(self, asm): |
| 51 |
if detect_simd_z(): |
| 52 |
self.enable(16, accum=True) |
| 53 |
asm.setup_once_vector() |
| 54 |
self._setup = True |
| 55 |
ZSIMDVectorExt.TR_MAPPING[rop.VEC_CAST_INT_TO_FLOAT] = OpRestrict([TR_INT64_2]) |
| 56 |
|
| 57 |
class VectorAssembler(object): |
| 58 |
_mixin_ = True |
| 59 |
|
| 60 |
def setup_once_vector(self): |
| 61 |
pass |
| 62 |
|
| 63 |
def emit_vec_load_f(self, op, arglocs, regalloc): |
| 64 |
resloc, baseloc, indexloc, size_loc, offsetloc, integer_loc = arglocs |
| 65 |
addrloc = self._load_address(baseloc, indexloc, offsetloc) |
| 66 |
self.mc.VL(resloc, addrloc) |
| 67 |
|
| 68 |
emit_vec_load_i = emit_vec_load_f |
| 69 |
|
| 70 |
def emit_vec_store(self, op, arglocs, regalloc): |
| 71 |
baseloc, indexloc, valueloc, sizeloc, offsetloc, integer_loc = arglocs |
| 72 |
addrloc = self._load_address(baseloc, indexloc, offsetloc) |
| 73 |
self.mc.VST(valueloc, addrloc) |
| 74 |
|
| 75 |
def emit_vec_int_add(self, op, arglocs, regalloc): |
| 76 |
resloc, loc0, loc1, size_loc = arglocs |
| 77 |
mask = l.itemsize_to_mask(size_loc.value) |
| 78 |
self.mc.VA(resloc, loc0, loc1, mask) |
| 79 |
|
| 80 |
def emit_vec_int_sub(self, op, arglocs, regalloc): |
| 81 |
resloc, loc0, loc1, size_loc = arglocs |
| 82 |
mask = l.itemsize_to_mask(size_loc.value) |
| 83 |
self.mc.VS(resloc, loc0, loc1, mask) |
| 84 |
|
| 85 |
def emit_vec_float_add(self, op, arglocs, regalloc): |
| 86 |
resloc, loc0, loc1, itemsize_loc = arglocs |
| 87 |
itemsize = itemsize_loc.value |
| 88 |
if itemsize == 8: |
| 89 |
self.mc.VFA(resloc, loc0, loc1, l.imm(3), l.imm(0), l.imm(0)) |
| 90 |
return |
| 91 |
not_implemented("vec_float_add of size %d" % itemsize) |
| 92 |
|
| 93 |
def emit_vec_float_sub(self, op, arglocs, regalloc): |
| 94 |
resloc, loc0, loc1, itemsize_loc = arglocs |
| 95 |
itemsize = itemsize_loc.value |
| 96 |
if itemsize == 8: |
| 97 |
self.mc.VFS(resloc, loc0, loc1, l.imm(3), l.imm(0), l.imm(0)) |
| 98 |
return |
| 99 |
not_implemented("vec_float_sub of size %d" % itemsize) |
| 100 |
|
| 101 |
def emit_vec_float_mul(self, op, arglocs, regalloc): |
| 102 |
resloc, loc0, loc1, itemsize_loc = arglocs |
| 103 |
itemsize = itemsize_loc.value |
| 104 |
if itemsize == 8: |
| 105 |
self.mc.VFM(resloc, loc0, loc1, l.imm(3), l.imm(0), l.imm(0)) |
| 106 |
return |
| 107 |
not_implemented("vec_float_mul of size %d" % itemsize) |
| 108 |
|
| 109 |
def emit_vec_float_truediv(self, op, arglocs, regalloc): |
| 110 |
resloc, loc0, loc1, itemsize_loc = arglocs |
| 111 |
itemsize = itemsize_loc.value |
| 112 |
if itemsize == 8: |
| 113 |
self.mc.VFD(resloc, loc0, loc1, l.imm(3), l.imm(0), l.imm(0)) |
| 114 |
return |
| 115 |
not_implemented("vec_float_truediv of size %d" % itemsize) |
| 116 |
|
| 117 |
def emit_vec_int_and(self, op, arglocs, regalloc): |
| 118 |
resloc, loc0, loc1, sizeloc = arglocs |
| 119 |
self.mc.VN(resloc, loc0, loc1) |
| 120 |
|
| 121 |
def emit_vec_int_or(self, op, arglocs, regalloc): |
| 122 |
resloc, loc0, loc1, sizeloc = arglocs |
| 123 |
self.mc.VO(resloc, loc0, loc1) |
| 124 |
|
| 125 |
def emit_vec_int_xor(self, op, arglocs, regalloc): |
| 126 |
resloc, loc0, loc1, sizeloc = arglocs |
| 127 |
self.mc.VX(resloc, loc0, loc1) |
| 128 |
|
| 129 |
def emit_vec_int_signext(self, op, arglocs, regalloc): |
| 130 |
resloc, loc0, osizeloc, nsizeloc = arglocs |
| 131 |
|
| 132 |
|
| 133 |
osize = osizeloc.value |
| 134 |
nsize = nsizeloc.value |
| 135 |
if osize == nsize: |
| 136 |
self.regalloc_mov(loc0, resloc) |
| 137 |
elif (osize == 4 and nsize == 8) or (osize == 8 and nsize == 4): |
| 138 |
self.mc.VLGV(r.SCRATCH, loc0, l.addr(0), l.itemsize_to_mask(osize)) |
| 139 |
self.mc.VLVG(resloc, r.SCRATCH, l.addr(0), l.itemsize_to_mask(nsize)) |
| 140 |
self.mc.VLGV(r.SCRATCH, loc0, l.addr(1), l.itemsize_to_mask(osize)) |
| 141 |
self.mc.VLVG(resloc, r.SCRATCH, l.addr(1), l.itemsize_to_mask(nsize)) |
| 142 |
if nsize == 8: |
| 143 |
self.mc.VSEG(resloc, resloc, l.itemsize_to_mask(osize)) |
| 144 |
|
| 145 |
def emit_vec_float_abs(self, op, arglocs, regalloc): |
| 146 |
resloc, argloc, sizeloc = arglocs |
| 147 |
size = sizeloc.value |
| 148 |
if size == 8: |
| 149 |
self.mc.VFPSO(resloc, argloc, l.imm(3), l.imm(0), l.imm(2)) |
| 150 |
return |
| 151 |
not_implemented("vec_float_abs of size %d" % size) |
| 152 |
|
| 153 |
def emit_vec_float_neg(self, op, arglocs, regalloc): |
| 154 |
resloc, argloc, sizeloc = arglocs |
| 155 |
size = sizeloc.value |
| 156 |
if size == 8: |
| 157 |
self.mc.VFPSO(resloc, argloc, l.imm(3), l.imm(0), l.imm(0)) |
| 158 |
return |
| 159 |
not_implemented("vec_float_abs of size %d" % size) |
| 160 |
|
| 161 |
def emit_vec_guard_true(self, guard_op, arglocs, regalloc): |
| 162 |
self._emit_guard(guard_op, arglocs) |
| 163 |
|
| 164 |
def emit_vec_guard_false(self, guard_op, arglocs, regalloc): |
| 165 |
self.guard_success_cc = c.negate(self.guard_success_cc) |
| 166 |
self._emit_guard(guard_op, arglocs) |
| 167 |
|
| 168 |
def _update_at_exit(self, fail_locs, fail_args, faildescr, regalloc): |
| 169 |
""" If accumulation is done in this loop, at the guard exit |
| 170 |
some vector registers must be adjusted to yield the correct value |
| 171 |
""" |
| 172 |
if not isinstance(faildescr, ResumeGuardDescr): |
| 173 |
return |
| 174 |
accum_info = faildescr.rd_vector_info |
| 175 |
while accum_info: |
| 176 |
pos = accum_info.getpos_in_failargs() |
| 177 |
scalar_loc = fail_locs[pos] |
| 178 |
vector_loc = accum_info.location |
| 179 |
|
| 180 |
scalar_arg = accum_info.getoriginal() |
| 181 |
orig_scalar_loc = scalar_loc |
| 182 |
if not scalar_loc.is_reg(): |
| 183 |
if scalar_arg.type == FLOAT: |
| 184 |
scalar_loc = r.FP_SCRATCH |
| 185 |
else: |
| 186 |
scalar_loc = r.SCRATCH2 |
| 187 |
self.regalloc_mov(orig_scalar_loc, scalar_loc) |
| 188 |
assert scalar_arg is not None |
| 189 |
op = accum_info.accum_operation |
| 190 |
self._accum_reduce(op, scalar_arg, vector_loc, scalar_loc) |
| 191 |
if scalar_loc is not orig_scalar_loc: |
| 192 |
self.regalloc_mov(scalar_loc, orig_scalar_loc) |
| 193 |
accum_info = accum_info.next() |
| 194 |
|
| 195 |
def _accum_reduce(self, op, arg, accumloc, targetloc): |
| 196 |
|
| 197 |
if arg.type == FLOAT: |
| 198 |
self.mc.VPDI(targetloc, accumloc, accumloc, permi(1,0)) |
| 199 |
if op == '+': |
| 200 |
self.mc.VFA(targetloc, targetloc, accumloc, l.imm3, l.imm(0b1000), l.imm(0)) |
| 201 |
return |
| 202 |
elif op == '*': |
| 203 |
self.mc.VFM(targetloc, targetloc, accumloc, l.imm3, l.imm(0b1000), l.imm(0)) |
| 204 |
return |
| 205 |
else: |
| 206 |
assert arg.type == INT |
| 207 |
|
| 208 |
self.mc.VLGV(r.SCRATCH, accumloc, l.addr(0), l.itemsize_to_mask(8)) |
| 209 |
self.mc.VLGV(targetloc, accumloc, l.addr(1), l.itemsize_to_mask(8)) |
| 210 |
if op == '+': |
| 211 |
self.mc.AGR(targetloc, r.SCRATCH) |
| 212 |
return |
| 213 |
elif op == '*': |
| 214 |
self.mc.MSGR(targetloc, r.SCRATCH) |
| 215 |
return |
| 216 |
not_implemented("reduce sum for %s not impl." % arg) |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
def emit_vec_int_is_true(self, op, arglocs, regalloc): |
| 221 |
assert isinstance(op, VectorOp) |
| 222 |
resloc, argloc, sizeloc = arglocs |
| 223 |
size = sizeloc.value |
| 224 |
tmploc = regalloc.vrm.get_scratch_reg() |
| 225 |
self.mc.VX(tmploc, tmploc, tmploc) |
| 226 |
self.mc.VCHL(resloc, argloc, tmploc, l.itemsize_to_mask(size), l.imm(0b0001)) |
| 227 |
flush_vec_cc(self, regalloc, c.VEQI, op.bytesize, resloc) |
| 228 |
|
| 229 |
def emit_vec_float_eq(self, op, arglocs, regalloc): |
| 230 |
assert isinstance(op, VectorOp) |
| 231 |
resloc, loc0, loc1, sizeloc = arglocs |
| 232 |
size = sizeloc.value |
| 233 |
if size == 8: |
| 234 |
|
| 235 |
self.mc.VFCE(resloc, loc0, loc1, l.imm(3), l.imm(0), l.imm(1)) |
| 236 |
else: |
| 237 |
not_implemented("[zarch/assembler] float == for size %d" % size) |
| 238 |
flush_vec_cc(self, regalloc, c.VEQI, op.bytesize, resloc) |
| 239 |
|
| 240 |
def emit_vec_float_xor(self, op, arglocs, regalloc): |
| 241 |
resloc, loc0, loc1, sizeloc = arglocs |
| 242 |
self.mc.VX(resloc, loc0, loc1) |
| 243 |
|
| 244 |
def emit_vec_float_ne(self, op, arglocs, regalloc): |
| 245 |
assert isinstance(op, VectorOp) |
| 246 |
resloc, loc0, loc1, sizeloc = arglocs |
| 247 |
size = sizeloc.value |
| 248 |
if size == 8: |
| 249 |
|
| 250 |
self.mc.VFCE(resloc, loc0, loc1, l.imm(3), l.imm(0), l.imm(1)) |
| 251 |
self.mc.VNO(resloc, resloc, resloc) |
| 252 |
else: |
| 253 |
not_implemented("[zarch/assembler] float != for size %d" % size) |
| 254 |
flush_vec_cc(self, regalloc, c.VNEI, op.bytesize, resloc) |
| 255 |
|
| 256 |
def emit_vec_cast_int_to_float(self, op, arglocs, regalloc): |
| 257 |
resloc, loc0 = arglocs |
| 258 |
self.mc.VCDG(resloc, loc0, l.imm(3), l.imm(4), m.RND_TOZERO) |
| 259 |
|
| 260 |
def emit_vec_int_eq(self, op, arglocs, regalloc): |
| 261 |
assert isinstance(op, VectorOp) |
| 262 |
resloc, loc0, loc1, sizeloc = arglocs |
| 263 |
size = sizeloc.value |
| 264 |
self.mc.VCEQ(resloc, loc0, loc1, l.itemsize_to_mask(size), l.imm(1)) |
| 265 |
flush_vec_cc(self, regalloc, c.VEQI, op.bytesize, resloc) |
| 266 |
|
| 267 |
def emit_vec_int_ne(self, op, arglocs, regalloc): |
| 268 |
assert isinstance(op, VectorOp) |
| 269 |
resloc, loc0, loc1, sizeloc = arglocs |
| 270 |
size = sizeloc.value |
| 271 |
self.mc.VCEQ(resloc, loc0, loc1, l.itemsize_to_mask(size), l.imm(1)) |
| 272 |
self.mc.VNO(resloc, resloc, resloc) |
| 273 |
flush_vec_cc(self, regalloc, c.VNEI, op.bytesize, resloc) |
| 274 |
|
| 275 |
def emit_vec_cast_float_to_int(self, op, arglocs, regalloc): |
| 276 |
resloc, loc0 = arglocs |
| 277 |
|
| 278 |
self.mc.VCGD(resloc, loc0, l.imm(3), l.imm(4), m.RND_TOZERO) |
| 279 |
|
| 280 |
def emit_vec_expand_i(self, op, arglocs, regalloc): |
| 281 |
assert isinstance(op, VectorOp) |
| 282 |
resloc, loc0 = arglocs |
| 283 |
size = op.bytesize |
| 284 |
if loc0.is_core_reg(): |
| 285 |
self.mc.VLVG(resloc, loc0, l.addr(0), l.itemsize_to_mask(size)) |
| 286 |
self.mc.VREP(resloc, resloc, l.imm0, l.itemsize_to_mask(size)) |
| 287 |
else: |
| 288 |
self.mc.VLREP(resloc, loc0, l.itemsize_to_mask(size)) |
| 289 |
|
| 290 |
def emit_vec_expand_f(self, op, arglocs, regalloc): |
| 291 |
assert isinstance(op, VectorOp) |
| 292 |
resloc, loc0 = arglocs |
| 293 |
size = op.bytesize |
| 294 |
if loc0.is_fp_reg(): |
| 295 |
self.mc.VREP(resloc, loc0, l.imm0, l.itemsize_to_mask(size)) |
| 296 |
else: |
| 297 |
self.mc.VLREP(resloc, loc0, l.itemsize_to_mask(size)) |
| 298 |
|
| 299 |
def emit_vec_pack_i(self, op, arglocs, regalloc): |
| 300 |
assert isinstance(op, VectorOp) |
| 301 |
resloc, vecloc, sourceloc, residxloc, srcidxloc, countloc, sizeloc = arglocs |
| 302 |
residx = residxloc.value |
| 303 |
srcidx = srcidxloc.value |
| 304 |
count = countloc.value |
| 305 |
size = sizeloc.value |
| 306 |
assert isinstance(op, VectorOp) |
| 307 |
newsize = op.bytesize |
| 308 |
if count == 1: |
| 309 |
if resloc.is_core_reg(): |
| 310 |
assert sourceloc.is_vector_reg() |
| 311 |
index = l.addr(srcidx) |
| 312 |
self.mc.VLGV(resloc, sourceloc, index, l.itemsize_to_mask(size)) |
| 313 |
else: |
| 314 |
assert sourceloc.is_core_reg() |
| 315 |
assert resloc.is_vector_reg() |
| 316 |
index = l.addr(residx) |
| 317 |
self.mc.VLR(resloc, vecloc) |
| 318 |
self.mc.VLVG(resloc, sourceloc, index, l.itemsize_to_mask(newsize)) |
| 319 |
else: |
| 320 |
assert resloc.is_vector_reg() |
| 321 |
assert sourceloc.is_vector_reg() |
| 322 |
self.mc.VLR(resloc, vecloc) |
| 323 |
for j in range(count): |
| 324 |
sindex = l.addr(j + srcidx) |
| 325 |
|
| 326 |
self.mc.VLGV(r.SCRATCH, sourceloc, sindex, l.itemsize_to_mask(size)) |
| 327 |
rindex = l.addr(j + residx) |
| 328 |
self.mc.VLVG(resloc, r.SCRATCH, rindex, l.itemsize_to_mask(newsize)) |
| 329 |
|
| 330 |
emit_vec_unpack_i = emit_vec_pack_i |
| 331 |
|
| 332 |
def emit_vec_pack_f(self, op, arglocs, regalloc): |
| 333 |
assert isinstance(op, VectorOp) |
| 334 |
resloc, vecloc, srcloc, residxloc, srcidxloc, countloc = arglocs |
| 335 |
residx = residxloc.value |
| 336 |
srcidx = srcidxloc.value |
| 337 |
|
| 338 |
|
| 339 |
if srcidx == 0: |
| 340 |
if residx == 0: |
| 341 |
|
| 342 |
self.mc.VPDI(resloc, srcloc, vecloc, permi(0,1)) |
| 343 |
else: |
| 344 |
assert residx == 1 |
| 345 |
|
| 346 |
self.mc.VPDI(resloc, vecloc, srcloc, permi(0,0)) |
| 347 |
else: |
| 348 |
assert srcidx == 1 |
| 349 |
if residx == 0: |
| 350 |
|
| 351 |
self.mc.VPDI(resloc, srcloc, vecloc, permi(1,1)) |
| 352 |
else: |
| 353 |
assert residx == 1 |
| 354 |
|
| 355 |
self.mc.VPDI(resloc, vecloc, srcloc, permi(0,1)) |
| 356 |
|
| 357 |
def emit_vec_unpack_f(self, op, arglocs, regalloc): |
| 358 |
assert isinstance(op, VectorOp) |
| 359 |
resloc, srcloc, srcidxloc, countloc = arglocs |
| 360 |
srcidx = srcidxloc.value |
| 361 |
|
| 362 |
|
| 363 |
if srcidx == 0: |
| 364 |
|
| 365 |
self.mc.VPDI(resloc, srcloc, srcloc, permi(0,1)) |
| 366 |
return |
| 367 |
else: |
| 368 |
|
| 369 |
self.mc.VPDI(resloc, srcloc, srcloc, permi(1,0)) |
| 370 |
return |
| 371 |
not_implemented("unpack for combination src %d -> res %d" % (srcidx, 0)) |
| 372 |
|
| 373 |
def emit_vec_f(self, op, arglocs, regalloc): |
| 374 |
pass |
| 375 |
emit_vec_i = emit_vec_f |
| 376 |
|
| 377 |
class VectorRegalloc(object): |
| 378 |
_mixin_ = True |
| 379 |
|
| 380 |
def force_allocate_vector_reg(self, op): |
| 381 |
forbidden_vars = self.vrm.temp_boxes |
| 382 |
return self.vrm.force_allocate_reg(op, forbidden_vars) |
| 383 |
|
| 384 |
def force_allocate_vector_reg_or_cc(self, op): |
| 385 |
assert op.type == INT |
| 386 |
if self.next_op_can_accept_cc(self.operations, self.rm.position): |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
self.rm.force_allocate_frame_reg(op) |
| 391 |
return r.SPP |
| 392 |
else: |
| 393 |
return self.force_allocate_vector_reg(op) |
| 394 |
|
| 395 |
def ensure_vector_reg(self, box): |
| 396 |
return self.vrm.make_sure_var_in_reg(box, |
| 397 |
forbidden_vars=self.vrm.temp_boxes) |
| 398 |
|
| 399 |
def _prepare_load(self, op): |
| 400 |
descr = op.getdescr() |
| 401 |
assert isinstance(descr, ArrayDescr) |
| 402 |
assert not descr.is_array_of_pointers() and \ |
| 403 |
not descr.is_array_of_structs() |
| 404 |
itemsize, ofs, _ = unpack_arraydescr(descr) |
| 405 |
integer = not (descr.is_array_of_floats() or descr.getconcrete_type() == FLOAT) |
| 406 |
a0 = op.getarg(0) |
| 407 |
a1 = op.getarg(1) |
| 408 |
base_loc = self.ensure_reg(a0) |
| 409 |
ofs_loc = self.ensure_reg(a1) |
| 410 |
result_loc = self.force_allocate_vector_reg(op) |
| 411 |
return [result_loc, base_loc, ofs_loc, imm(itemsize), imm(ofs), |
| 412 |
imm(integer)] |
| 413 |
|
| 414 |
prepare_vec_load_i = _prepare_load |
| 415 |
prepare_vec_load_f = _prepare_load |
| 416 |
|
| 417 |
def prepare_vec_arith(self, op): |
| 418 |
assert isinstance(op, VectorOp) |
| 419 |
a0 = op.getarg(0) |
| 420 |
a1 = op.getarg(1) |
| 421 |
size = op.bytesize |
| 422 |
loc0 = self.ensure_vector_reg(a0) |
| 423 |
loc1 = self.ensure_vector_reg(a1) |
| 424 |
resloc = self.force_allocate_vector_reg(op) |
| 425 |
return [resloc, loc0, loc1, imm(size)] |
| 426 |
|
| 427 |
prepare_vec_int_add = prepare_vec_arith |
| 428 |
prepare_vec_int_sub = prepare_vec_arith |
| 429 |
prepare_vec_int_mul = prepare_vec_arith |
| 430 |
prepare_vec_float_add = prepare_vec_arith |
| 431 |
prepare_vec_float_sub = prepare_vec_arith |
| 432 |
prepare_vec_float_mul = prepare_vec_arith |
| 433 |
prepare_vec_float_truediv = prepare_vec_arith |
| 434 |
|
| 435 |
|
| 436 |
prepare_vec_int_and = prepare_vec_arith |
| 437 |
prepare_vec_int_or = prepare_vec_arith |
| 438 |
prepare_vec_int_xor = prepare_vec_arith |
| 439 |
prepare_vec_float_xor = prepare_vec_arith |
| 440 |
del prepare_vec_arith |
| 441 |
|
| 442 |
def prepare_vec_bool(self, op): |
| 443 |
assert isinstance(op, VectorOp) |
| 444 |
a0 = op.getarg(0) |
| 445 |
a1 = op.getarg(1) |
| 446 |
size = op.bytesize |
| 447 |
loc0 = self.ensure_vector_reg(a0) |
| 448 |
loc1 = self.ensure_vector_reg(a1) |
| 449 |
resloc = self.force_allocate_vector_reg_or_cc(op) |
| 450 |
return [resloc, loc0, loc1, imm(size)] |
| 451 |
|
| 452 |
prepare_vec_float_eq = prepare_vec_bool |
| 453 |
prepare_vec_float_ne = prepare_vec_bool |
| 454 |
prepare_vec_int_eq = prepare_vec_bool |
| 455 |
prepare_vec_int_ne = prepare_vec_bool |
| 456 |
del prepare_vec_bool |
| 457 |
|
| 458 |
def prepare_vec_store(self, op): |
| 459 |
descr = op.getdescr() |
| 460 |
assert isinstance(descr, ArrayDescr) |
| 461 |
assert not descr.is_array_of_pointers() and \ |
| 462 |
not descr.is_array_of_structs() |
| 463 |
itemsize, ofs, _ = unpack_arraydescr(descr) |
| 464 |
a0 = op.getarg(0) |
| 465 |
a1 = op.getarg(1) |
| 466 |
a2 = op.getarg(2) |
| 467 |
baseloc = self.ensure_reg(a0) |
| 468 |
ofsloc = self.ensure_reg(a1) |
| 469 |
valueloc = self.ensure_vector_reg(a2) |
| 470 |
|
| 471 |
integer = not (descr.is_array_of_floats() or descr.getconcrete_type() == FLOAT) |
| 472 |
return [baseloc, ofsloc, valueloc, |
| 473 |
imm(itemsize), imm(ofs), imm(integer)] |
| 474 |
|
| 475 |
def prepare_vec_int_signext(self, op): |
| 476 |
assert isinstance(op, VectorOp) |
| 477 |
a0 = op.getarg(0) |
| 478 |
assert isinstance(a0, VectorOp) |
| 479 |
loc0 = self.ensure_vector_reg(a0) |
| 480 |
resloc = self.force_allocate_vector_reg(op) |
| 481 |
return [resloc, loc0, imm(a0.bytesize), imm(op.bytesize)] |
| 482 |
|
| 483 |
def prepare_vec_arith_unary(self, op): |
| 484 |
assert isinstance(op, VectorOp) |
| 485 |
a0 = op.getarg(0) |
| 486 |
loc0 = self.ensure_vector_reg(a0) |
| 487 |
resloc = self.force_allocate_vector_reg(op) |
| 488 |
sizeloc = imm(op.bytesize) |
| 489 |
return [resloc, loc0, sizeloc] |
| 490 |
|
| 491 |
prepare_vec_float_neg = prepare_vec_arith_unary |
| 492 |
prepare_vec_float_abs = prepare_vec_arith_unary |
| 493 |
del prepare_vec_arith_unary |
| 494 |
|
| 495 |
def prepare_vec_pack_i(self, op): |
| 496 |
|
| 497 |
assert isinstance(op, VectorOp) |
| 498 |
arg = op.getarg(1) |
| 499 |
index = op.getarg(2) |
| 500 |
count = op.getarg(3) |
| 501 |
assert isinstance(index, ConstInt) |
| 502 |
assert isinstance(count, ConstInt) |
| 503 |
arg0 = op.getarg(0) |
| 504 |
assert isinstance(arg0, VectorOp) |
| 505 |
vloc = self.ensure_vector_reg(arg0) |
| 506 |
srcloc = self.ensure_reg(arg) |
| 507 |
resloc = self.force_allocate_vector_reg(op) |
| 508 |
residx = index.value |
| 509 |
srcidx = 0 |
| 510 |
return [resloc, vloc, srcloc, imm(residx), imm(srcidx), imm(count.value), imm(arg0.bytesize)] |
| 511 |
|
| 512 |
def prepare_vec_unpack_i(self, op): |
| 513 |
assert isinstance(op, VectorOp) |
| 514 |
index = op.getarg(1) |
| 515 |
count = op.getarg(2) |
| 516 |
assert isinstance(index, ConstInt) |
| 517 |
assert isinstance(count, ConstInt) |
| 518 |
arg = op.getarg(0) |
| 519 |
if arg.is_vector(): |
| 520 |
srcloc = self.ensure_vector_reg(arg) |
| 521 |
assert isinstance(arg, VectorOp) |
| 522 |
size = arg.bytesize |
| 523 |
else: |
| 524 |
|
| 525 |
srcloc = self.ensure_reg(arg) |
| 526 |
size = WORD |
| 527 |
if op.is_vector(): |
| 528 |
resloc = self.force_allocate_vector_reg(op) |
| 529 |
else: |
| 530 |
resloc = self.force_allocate_reg(op) |
| 531 |
return [resloc, srcloc, srcloc, imm(0), imm(index.value), imm(count.value), imm(size)] |
| 532 |
|
| 533 |
def prepare_vec_pack_f(self, op): |
| 534 |
|
| 535 |
assert isinstance(op, VectorOp) |
| 536 |
arg = op.getarg(1) |
| 537 |
index = op.getarg(2) |
| 538 |
count = op.getarg(3) |
| 539 |
assert isinstance(index, ConstInt) |
| 540 |
assert isinstance(count, ConstInt) |
| 541 |
assert not arg.is_vector() |
| 542 |
srcloc = self.ensure_reg(arg) |
| 543 |
vloc = self.ensure_vector_reg(op.getarg(0)) |
| 544 |
if op.is_vector(): |
| 545 |
resloc = self.force_allocate_vector_reg(op) |
| 546 |
else: |
| 547 |
resloc = self.force_allocate_reg(op) |
| 548 |
residx = index.value |
| 549 |
srcidx = 0 |
| 550 |
return [resloc, vloc, srcloc, imm(residx), imm(srcidx), imm(count.value)] |
| 551 |
|
| 552 |
def prepare_vec_unpack_f(self, op): |
| 553 |
index = op.getarg(1) |
| 554 |
count = op.getarg(2) |
| 555 |
assert isinstance(index, ConstInt) |
| 556 |
assert isinstance(count, ConstInt) |
| 557 |
srcloc = self.ensure_vector_reg(op.getarg(0)) |
| 558 |
resloc = self.force_allocate_reg(op) |
| 559 |
return [resloc, srcloc, imm(index.value), imm(count.value)] |
| 560 |
|
| 561 |
def expand_float(self, size, box): |
| 562 |
adr = self.assembler.datablockwrapper.malloc_aligned(16, 16) |
| 563 |
fs = box.getfloatstorage() |
| 564 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[0] = fs |
| 565 |
rffi.cast(rffi.CArrayPtr(longlong.FLOATSTORAGE), adr)[1] = fs |
| 566 |
return l.ConstFloatLoc(adr) |
| 567 |
|
| 568 |
def prepare_vec_expand_f(self, op): |
| 569 |
assert isinstance(op, VectorOp) |
| 570 |
arg = op.getarg(0) |
| 571 |
l0 = self.ensure_reg_or_pool(arg) |
| 572 |
res = self.force_allocate_vector_reg(op) |
| 573 |
return [res, l0] |
| 574 |
|
| 575 |
prepare_vec_expand_i = prepare_vec_expand_f |
| 576 |
|
| 577 |
def prepare_vec_int_is_true(self, op): |
| 578 |
assert isinstance(op, VectorOp) |
| 579 |
arg = op.getarg(0) |
| 580 |
assert isinstance(arg, VectorOp) |
| 581 |
argloc = self.ensure_vector_reg(arg) |
| 582 |
resloc = self.force_allocate_vector_reg_or_cc(op) |
| 583 |
return [resloc, argloc, imm(arg.bytesize)] |
| 584 |
|
| 585 |
def _prepare_vec(self, op): |
| 586 |
|
| 587 |
return [self.force_allocate_vector_reg(op)] |
| 588 |
|
| 589 |
prepare_vec_i = _prepare_vec |
| 590 |
prepare_vec_f = _prepare_vec |
| 591 |
|
| 592 |
def prepare_vec_cast_float_to_int(self, op): |
| 593 |
l0 = self.ensure_vector_reg(op.getarg(0)) |
| 594 |
res = self.force_allocate_vector_reg(op) |
| 595 |
return [res, l0] |
| 596 |
|
| 597 |
prepare_vec_cast_int_to_float = prepare_vec_cast_float_to_int |
| 598 |
|
| 599 |
def prepare_vec_guard_true(self, op): |
| 600 |
self.assembler.guard_success_cc = c.EQ |
| 601 |
return self._prepare_guard(op) |
| 602 |
|
| 603 |
def prepare_vec_guard_false(self, op): |
| 604 |
self.assembler.guard_success_cc = c.NE |
| 605 |
return self._prepare_guard(op) |