Author: Richard Plangger <[email protected]>
Branch: s390x-backend
Changeset: r81738:ac53e51faf32
Date: 2016-01-13 13:10 +0100
http://bitbucket.org/pypy/pypy/changeset/ac53e51faf32/

Log:    mul overflow, if right is negative up to now the wrong branch of mul
        overflow has been taken. resulted in abs(v) = abs(x) * neg(z), which
        is wrong

diff --git a/rpython/jit/backend/zarch/helper/regalloc.py 
b/rpython/jit/backend/zarch/helper/regalloc.py
--- a/rpython/jit/backend/zarch/helper/regalloc.py
+++ b/rpython/jit/backend/zarch/helper/regalloc.py
@@ -21,7 +21,7 @@
 def prepare_int_add(self, op):
     a0 = op.getarg(0)
     a1 = op.getarg(1)
-    if check_imm32(a0):
+    if a0.is_constant():
         a0, a1 = a1, a0
     l0 = self.ensure_reg(a0)
     if check_imm32(a1):
@@ -35,7 +35,7 @@
 def prepare_int_mul(self, op):
     a0 = op.getarg(0)
     a1 = op.getarg(1)
-    if check_imm32(a0):
+    if a0.is_constant():
         a0, a1 = a1, a0
     l0 = self.ensure_reg(a0)
     if check_imm32(a1):
@@ -49,7 +49,7 @@
 def prepare_int_mul_ovf(self, op):
     a0 = op.getarg(0)
     a1 = op.getarg(1)
-    if check_imm32(a0):
+    if a0.is_constant():
         a0, a1 = a1, a0
     lr,lq = self.rm.ensure_even_odd_pair(a0, op, bind_first=False)
     if check_imm32(a1):
@@ -96,7 +96,7 @@
 def prepare_int_logic(self, op):
     a0 = op.getarg(0)
     a1 = op.getarg(1)
-    if isinstance(a0, ConstInt):
+    if a0.is_constant():
         a0, a1 = a1, a0
     l0 = self.ensure_reg(a0)
     l1 = self.ensure_reg(a1)
diff --git a/rpython/jit/backend/zarch/opassembler.py 
b/rpython/jit/backend/zarch/opassembler.py
--- a/rpython/jit/backend/zarch/opassembler.py
+++ b/rpython/jit/backend/zarch/opassembler.py
@@ -72,8 +72,9 @@
         bc_set_overflow = mc.OIHL_byte_count + mc.SPM_byte_count
 
         # check left neg
-        mc.CGIJ(lq, l.imm(0), c.LT, l.imm(mc.CGIJ_byte_count*2))
-        mc.CGIJ(l1, l.imm(0), c.GE, l.imm(mc.CGIJ_byte_count*2 + 
bc_one_signed))
+        mc.CGIJ(lq, l.imm(0), c.LT, 
l.imm(mc.CGIJ_byte_count*2+mc.BRC_byte_count))
+        mc.CGIJ(l1, l.imm(0), c.GE, 
l.imm(mc.CGIJ_byte_count*2+mc.BRC_byte_count + bc_one_signed))
+        mc.BRC(c.ANY, l.imm(mc.BRC_byte_count + mc.CGIJ_byte_count)) # right 
is negative 
         mc.CGIJ(l1, l.imm(0), c.LT, l.imm(mc.CGIJ_byte_count + bc_one_signed)) 
# jump if both are negative
         # left or right is negative
         mc.LPGR(lq, lq)
diff --git a/rpython/jit/backend/zarch/pool.py 
b/rpython/jit/backend/zarch/pool.py
--- a/rpython/jit/backend/zarch/pool.py
+++ b/rpython/jit/backend/zarch/pool.py
@@ -85,10 +85,9 @@
                 self.offset_map[arg] = self.size
                 self.reserve_literal(8)
 
-    def get_descr_offset(self, descr):
-        return self.offset_map[descr]
-
     def get_offset(self, box):
+        if not we_are_translated():
+            assert self.offset_map[box] >= 0
         return self.offset_map[box]
 
     def reserve_literal(self, size):
diff --git a/rpython/jit/backend/zarch/test/test_int.py 
b/rpython/jit/backend/zarch/test/test_int.py
--- a/rpython/jit/backend/zarch/test/test_int.py
+++ b/rpython/jit/backend/zarch/test/test_int.py
@@ -116,3 +116,21 @@
         deadframe = self.cpu.execute_token(looptoken, v1)
         fail = self.cpu.get_latest_descr(deadframe)
         assert self.cpu.get_int_value(deadframe, 0) == result
+
+    @py.test.mark.parametrize('v1,v2', [(-189,2),(189,-2)])
+    def test_int_mul_no_overflow_var_var(self, v1, v2):
+        try:
+            result = v1*v2
+        except OverflowError:
+            py.test.skip("this test is not made to check the overflow!")
+        code = """
+        [i0,i2]
+        i1 = int_mul_ovf(i0,i2)
+        finish(i1, descr=faildescr)
+        """.format()
+        loop = parse(code, namespace={"faildescr": BasicFinalDescr(1)})
+        looptoken = JitCellToken()
+        self.cpu.compile_loop(loop.inputargs, loop.operations, looptoken)
+        deadframe = self.cpu.execute_token(looptoken, v1, v2)
+        fail = self.cpu.get_latest_descr(deadframe)
+        assert self.cpu.get_int_value(deadframe, 0) == result
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to