Author: hager <[email protected]>
Branch: ppc-jit-backend
Changeset: r51257:65654d65854a
Date: 2012-01-11 16:26 -0800
http://bitbucket.org/pypy/pypy/changeset/65654d65854a/
Log: Use get_scratch_reg to obtain an additional scratch register in
prepare_(set/get)arrayitem_gc
diff --git a/pypy/jit/backend/ppc/ppcgen/opassembler.py
b/pypy/jit/backend/ppc/ppcgen/opassembler.py
--- a/pypy/jit/backend/ppc/ppcgen/opassembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/opassembler.py
@@ -547,17 +547,12 @@
self.mc.load(res.value, base_loc.value, ofs.value)
def emit_setarrayitem_gc(self, op, arglocs, regalloc):
- value_loc, base_loc, ofs_loc, scale, ofs = arglocs
+ value_loc, base_loc, ofs_loc, scratch_loc, scale, ofs = arglocs
assert ofs_loc.is_reg()
- # use r20 as scratch reg
- SAVE_SCRATCH = r.r20
- # save value temporarily
- self.mc.mtctr(SAVE_SCRATCH.value)
-
if scale.value > 0:
#scale_loc = r.SCRATCH
- scale_loc = SAVE_SCRATCH
+ scale_loc = scratch_loc
if IS_PPC_32:
self.mc.slwi(scale_loc.value, ofs_loc.value, scale.value)
else:
@@ -581,23 +576,14 @@
else:
assert 0, "scale %s not supported" % (scale.value)
- # restore value of SAVE_SCRATCH
- self.mc.mfctr(SAVE_SCRATCH.value)
-
emit_setarrayitem_raw = emit_setarrayitem_gc
def emit_getarrayitem_gc(self, op, arglocs, regalloc):
- res, base_loc, ofs_loc, scale, ofs = arglocs
+ res, base_loc, ofs_loc, scratch_loc, scale, ofs = arglocs
assert ofs_loc.is_reg()
- # use r20 as scratch reg
- SAVE_SCRATCH = r.r20
- # save value temporarily
- self.mc.mtctr(SAVE_SCRATCH.value)
-
if scale.value > 0:
- #scale_loc = r.SCRATCH
- scale_loc = SAVE_SCRATCH
+ scale_loc = scratch_loc
if IS_PPC_32:
self.mc.slwi(scale_loc.value, ofs_loc.value, scale.value)
else:
@@ -621,9 +607,6 @@
else:
assert 0
- # restore value of SAVE_SCRATCH
- self.mc.mfctr(SAVE_SCRATCH.value)
-
#XXX Hack, Hack, Hack
if not we_are_translated():
descr = op.getdescr()
diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py
@@ -585,6 +585,7 @@
if op.result:
regalloc.possibly_free_var(op.result)
regalloc.possibly_free_vars_for_op(op)
+ regalloc.free_temp_vars()
regalloc._check_invariants()
def can_merge_with_next_guard(self, op, i, operations):
diff --git a/pypy/jit/backend/ppc/ppcgen/regalloc.py
b/pypy/jit/backend/ppc/ppcgen/regalloc.py
--- a/pypy/jit/backend/ppc/ppcgen/regalloc.py
+++ b/pypy/jit/backend/ppc/ppcgen/regalloc.py
@@ -105,6 +105,14 @@
forbidden_vars=forbidden_vars)
return reg, box
+ def get_scratch_reg(self, type=INT, forbidden_vars=[], selected_reg=None):
+ assert type == INT or type == REF
+ box = TempBox()
+ self.temp_boxes.append(box)
+ reg = self.force_allocate_reg(box, forbidden_vars=forbidden_vars,
+ selected_reg=selected_reg)
+ return reg
+
class PPCFrameManager(FrameManager):
def __init__(self):
FrameManager.__init__(self)
@@ -287,6 +295,15 @@
box = thing
return loc, box
+ def get_scratch_reg(self, type, forbidden_vars=[], selected_reg=None):
+ if type == FLOAT:
+ assert 0, "not implemented yet"
+ else:
+ return self.rm.get_scratch_reg(type, forbidden_vars, selected_reg)
+
+ def free_temp_vars(self):
+ self.rm.free_temp_vars()
+
def make_sure_var_in_reg(self, var, forbidden_vars=[],
selected_reg=None, need_lower_byte=False):
return self.rm.make_sure_var_in_reg(var, forbidden_vars,
@@ -606,7 +623,10 @@
ofs_loc, _ = self._ensure_value_is_boxed(a1, args)
value_loc, _ = self._ensure_value_is_boxed(a2, args)
assert _check_imm_arg(ofs)
- return [value_loc, base_loc, ofs_loc, imm(scale), imm(ofs)]
+ scratch_loc = self.rm.get_scratch_reg(INT, [base_loc, ofs_loc])
+ assert scratch_loc not in [base_loc, ofs_loc]
+ return [value_loc, base_loc, ofs_loc,
+ scratch_loc, imm(scale), imm(ofs)]
prepare_setarrayitem_raw = prepare_setarrayitem_gc
@@ -618,11 +638,14 @@
boxes.append(base_box)
ofs_loc, ofs_box = self._ensure_value_is_boxed(a1, boxes)
boxes.append(ofs_box)
+ scratch_loc = self.rm.get_scratch_reg(INT, [base_loc, ofs_loc])
+ assert scratch_loc not in [base_loc, ofs_loc]
self.possibly_free_vars(boxes)
res = self.force_allocate_reg(op.result)
self.possibly_free_var(op.result)
assert _check_imm_arg(ofs)
- return [res, base_loc, ofs_loc, imm(scale), imm(ofs)]
+ return [res, base_loc, ofs_loc,
+ scratch_loc, imm(scale), imm(ofs)]
prepare_getarrayitem_raw = prepare_getarrayitem_gc
prepare_getarrayitem_gc_pure = prepare_getarrayitem_gc
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit