| 1 |
import rpython.jit.backend.ppc.condition as c |
| 2 |
from rpython.rlib.rarithmetic import intmask |
| 3 |
from rpython.jit.backend.ppc.arch import MAX_REG_PARAMS, IS_PPC_32, WORD |
| 4 |
from rpython.jit.metainterp.history import FLOAT |
| 5 |
from rpython.jit.metainterp.resoperation import rop |
| 6 |
import rpython.jit.backend.ppc.register as r |
| 7 |
from rpython.rtyper.lltypesystem import rffi, lltype |
| 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.SPP: |
| 19 |
asm.guard_success_cc = condition |
| 20 |
else: |
| 21 |
|
| 22 |
bit, invert = c.encoding[condition] |
| 23 |
assert 0 <= bit <= 3 |
| 24 |
if invert == 12: |
| 25 |
pass |
| 26 |
elif invert == 4: |
| 27 |
asm.mc.crnor(bit, bit, bit) |
| 28 |
else: |
| 29 |
assert 0 |
| 30 |
|
| 31 |
resval = result_loc.value |
| 32 |
|
| 33 |
asm.mc.mfcr(resval) |
| 34 |
|
| 35 |
asm.mc.rlwinm(resval, resval, 1 + bit, 31, 31) |
| 36 |
|
| 37 |
|
| 38 |
def do_emit_cmp_op(self, arglocs, condition, signed, fp): |
| 39 |
l0 = arglocs[0] |
| 40 |
l1 = arglocs[1] |
| 41 |
assert not l0.is_imm() |
| 42 |
|
| 43 |
self.mc.cmp_op(0, l0.value, l1.value, |
| 44 |
imm=l1.is_imm(), signed=signed, fp=fp) |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if fp: |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
if condition == c.LE: |
| 58 |
self.mc.crnor(1, 1, 3) |
| 59 |
condition = c.GT |
| 60 |
elif condition == c.GE: |
| 61 |
self.mc.crnor(0, 0, 3) |
| 62 |
condition = c.LT |
| 63 |
|
| 64 |
flush_cc(self, condition, arglocs[2]) |
| 65 |
|
| 66 |
|
| 67 |
def gen_emit_cmp_op(condition, signed=True, fp=False): |
| 68 |
def f(self, op, arglocs, regalloc): |
| 69 |
do_emit_cmp_op(self, arglocs, condition, signed, fp) |
| 70 |
return f |
| 71 |
|
| 72 |
def count_reg_args(args): |
| 73 |
reg_args = 0 |
| 74 |
words = 0 |
| 75 |
count = 0 |
| 76 |
for x in range(min(len(args), MAX_REG_PARAMS)): |
| 77 |
if args[x].type == FLOAT: |
| 78 |
count += 1 |
| 79 |
words += 1 |
| 80 |
else: |
| 81 |
count += 1 |
| 82 |
words += 1 |
| 83 |
reg_args += 1 |
| 84 |
if words > MAX_REG_PARAMS: |
| 85 |
reg_args = x |
| 86 |
break |
| 87 |
return reg_args |
| 88 |
|
| 89 |
class Saved_Volatiles(object): |
| 90 |
""" used in _gen_leave_jitted_hook_code to save volatile registers |
| 91 |
in ENCODING AREA around calls |
| 92 |
""" |
| 93 |
|
| 94 |
def __init__(self, codebuilder, save_RES=True, save_FLOAT=True): |
| 95 |
self.mc = codebuilder |
| 96 |
self.save_RES = save_RES |
| 97 |
self.save_FLOAT = save_FLOAT |
| 98 |
self.FLOAT_OFFSET = len(r.VOLATILES) |
| 99 |
|
| 100 |
def __enter__(self): |
| 101 |
""" before a call, volatile registers are saved in ENCODING AREA |
| 102 |
""" |
| 103 |
for i, reg in enumerate(r.VOLATILES): |
| 104 |
if not self.save_RES and reg is r.RES: |
| 105 |
continue |
| 106 |
self.mc.store(reg.value, r.SPP.value, i * WORD) |
| 107 |
if self.save_FLOAT: |
| 108 |
for i, reg in enumerate(r.VOLATILES_FLOAT): |
| 109 |
if not self.save_RES and reg is r.f1: |
| 110 |
continue |
| 111 |
self.mc.stfd(reg.value, r.SPP.value, |
| 112 |
(i + self.FLOAT_OFFSET) * WORD) |
| 113 |
|
| 114 |
def __exit__(self, *args): |
| 115 |
""" after call, volatile registers have to be restored |
| 116 |
""" |
| 117 |
for i, reg in enumerate(r.VOLATILES): |
| 118 |
if not self.save_RES and reg is r.RES: |
| 119 |
continue |
| 120 |
self.mc.load(reg.value, r.SPP.value, i * WORD) |
| 121 |
if self.save_FLOAT: |
| 122 |
for i, reg in enumerate(r.VOLATILES_FLOAT): |
| 123 |
if not self.save_RES and reg is r.f1: |
| 124 |
continue |
| 125 |
self.mc.lfd(reg.value, r.SPP.value, |
| 126 |
(i + self.FLOAT_OFFSET) * WORD) |