[pypy-commit] pypy ppc-jit-backend: Implemented remaining INT_* operations.

hager noreply at buildbot.pypy.org
Tue Oct 18 19:05:00 CEST 2011


Author: hager <sven.hager at uni-duesseldorf.de>
Branch: ppc-jit-backend
Changeset: r48212:089618b63dd9
Date: 2011-10-18 19:04 +0200
http://bitbucket.org/pypy/pypy/changeset/089618b63dd9/

Log:	Implemented remaining INT_* operations.

diff --git a/pypy/jit/backend/ppc/ppcgen/condition.py b/pypy/jit/backend/ppc/ppcgen/condition.py
--- a/pypy/jit/backend/ppc/ppcgen/condition.py
+++ b/pypy/jit/backend/ppc/ppcgen/condition.py
@@ -10,4 +10,7 @@
 U_GT = 70
 U_GE = 80
 
+IS_TRUE = 90
+IS_ZERO = 100
+
 opposites = {LE: GT, NE: EQ, LT: GE, GE: LT, EQ: NE, GT: LE}
diff --git a/pypy/jit/backend/ppc/ppcgen/helper/assembler.py b/pypy/jit/backend/ppc/ppcgen/helper/assembler.py
--- a/pypy/jit/backend/ppc/ppcgen/helper/assembler.py
+++ b/pypy/jit/backend/ppc/ppcgen/helper/assembler.py
@@ -52,6 +52,22 @@
         self.mc.rlwinm(resval, resval, 1, 31, 31)
     return f
 
+def gen_emit_unary_cmp_op(condition):
+    def f(self, op, arglocs, regalloc):
+        reg, res = arglocs
+
+        self.mc.cmpwi(0, reg.value, 0)
+        if condition == c.IS_ZERO:
+            self.mc.cror(0, 2, 2)
+        elif condition == c.IS_TRUE:
+            self.mc.cror(0, 0, 1)
+        else:
+            assert 0, "condition not known"
+
+        self.mc.mfcr(res.value)
+        self.mc.rlwinm(res.value, res.value, 1, 31, 31)
+    return f
+
 def encode32(mem, i, n):
     mem[i+3] = chr(n & 0xFF)
     mem[i+2] = chr((n >> 8) & 0xFF)
diff --git a/pypy/jit/backend/ppc/ppcgen/helper/regalloc.py b/pypy/jit/backend/ppc/ppcgen/helper/regalloc.py
--- a/pypy/jit/backend/ppc/ppcgen/helper/regalloc.py
+++ b/pypy/jit/backend/ppc/ppcgen/helper/regalloc.py
@@ -29,6 +29,24 @@
         return [l0, l1, res]
     return f
 
+def prepare_unary_cmp():
+    def f(self, op):
+        a0 = op.getarg(0)
+        reg, box = self._ensure_value_is_boxed(a0)
+        res = self.force_allocate_reg(op.result, [box])
+        self.possibly_free_vars([a0, box, op.result])
+        return [reg, res]
+    return f
+
+def prepare_unary_int_op():
+    def f(self, op):
+        l0, box = self._ensure_value_is_boxed(op.getarg(0))
+        self.possibly_free_var(box)
+        res = self.force_allocate_reg(op.result)
+        self.possibly_free_var(op.result)
+        return [l0, res]
+    return f
+
 def prepare_binary_int_op_with_imm():
     def f(self, op):
         boxes = op.getarglist()
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
@@ -1,4 +1,5 @@
-from pypy.jit.backend.ppc.ppcgen.helper.assembler import gen_emit_cmp_op
+from pypy.jit.backend.ppc.ppcgen.helper.assembler import (gen_emit_cmp_op, 
+                                                          gen_emit_unary_cmp_op)
 import pypy.jit.backend.ppc.ppcgen.condition as c
 import pypy.jit.backend.ppc.ppcgen.register as r
 from pypy.jit.backend.ppc.ppcgen.arch import GPR_SAVE_AREA, IS_PPC_32, WORD
@@ -124,6 +125,17 @@
     emit_uint_gt = gen_emit_cmp_op(c.U_GT, signed=False)
     emit_uint_ge = gen_emit_cmp_op(c.U_GE, signed=False)
 
+    emit_int_is_zero = gen_emit_unary_cmp_op(c.IS_ZERO)
+    emit_int_is_true = gen_emit_unary_cmp_op(c.IS_TRUE)
+
+    def emit_int_neg(self, op, arglocs, regalloc):
+        l0, res = arglocs
+        self.mc.neg(res.value, l0.value)
+
+    def emit_int_invert(self, op, arglocs, regalloc):
+        l0, res = arglocs
+        self.mc.not_(res.value, l0.value)
+
     def _emit_guard(self, op, arglocs, fcond, save_exc=False,
             is_guard_not_invalidated=False):
         descr = op.getdescr()
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
@@ -6,8 +6,10 @@
 from pypy.jit.backend.ppc.ppcgen.locations import imm
 from pypy.jit.backend.ppc.ppcgen.helper.regalloc import (_check_imm_arg, 
                                                          prepare_cmp_op,
+                                                         prepare_unary_int_op,
                                                          prepare_binary_int_op,
-                                                         prepare_binary_int_op_with_imm)
+                                                         prepare_binary_int_op_with_imm,
+                                                         prepare_unary_cmp)
 from pypy.jit.metainterp.history import (INT, REF, FLOAT, Const, ConstInt, 
                                          ConstPtr, LoopToken)
 from pypy.jit.metainterp.resoperation import rop
@@ -191,6 +193,9 @@
     prepare_uint_rshift = prepare_binary_int_op()
     prepare_uint_floordiv = prepare_binary_int_op()
 
+    prepare_int_neg = prepare_unary_int_op()
+    prepare_int_invert = prepare_unary_int_op()
+
     prepare_int_le = prepare_cmp_op()
     prepare_int_lt = prepare_cmp_op()
     prepare_int_ge = prepare_cmp_op()
@@ -203,6 +208,9 @@
     prepare_uint_gt = prepare_cmp_op()
     prepare_uint_ge = prepare_cmp_op()
 
+    prepare_int_is_true = prepare_unary_cmp()
+    prepare_int_is_zero = prepare_unary_cmp()
+
     def prepare_finish(self, op):
         args = [locations.imm(self.frame_manager.frame_depth)]
         for i in range(op.numargs()):


More information about the pypy-commit mailing list