Author: Richard Plangger <[email protected]>
Branch: s390x-backend
Changeset: r82127:ce150b6b822b
Date: 2016-02-09 18:16 +0100
http://bitbucket.org/pypy/pypy/changeset/ce150b6b822b/

Log:    reviewed guarding, made negate array lookup instead of fiddling with
        the mask bit

diff --git a/rpython/jit/backend/zarch/conditions.py 
b/rpython/jit/backend/zarch/conditions.py
--- a/rpython/jit/backend/zarch/conditions.py
+++ b/rpython/jit/backend/zarch/conditions.py
@@ -5,8 +5,6 @@
     _immutable_ = True
     def __repr__(self):
         s = ""
-        if self.value & 0x10 != 0:
-            s += "!FLOAT! "
         if self.value & 0x1 != 0:
             s += "OF"
         if self.value & 0x2 != 0:
@@ -19,16 +17,22 @@
 
 # normal branch instructions
 FLOAT = ConditionLocation(0x10)
+
 EQ = ConditionLocation(0x8)
 LT = ConditionLocation(0x4)
 GT = ConditionLocation(0x2)
 OF = ConditionLocation(0x1) # overflow
 
 LE = ConditionLocation(EQ.value | LT.value | OF.value)
+FLE = ConditionLocation(EQ.value | LT.value)
 GE = ConditionLocation(EQ.value | GT.value | OF.value)
+FGE = ConditionLocation(EQ.value | GT.value)
 NE = ConditionLocation(LT.value | GT.value | OF.value)
 NO = ConditionLocation(0xe) # NO overflow
 
+FGT = ConditionLocation(GT.value | OF.value)
+FLT = ConditionLocation(LT.value | OF.value)
+
 ANY = ConditionLocation(0xf)
 
 FP_ROUND_DEFAULT = loc.imm(0x0)
@@ -36,22 +40,35 @@
 
 cond_none = loc.imm(-1)
 
+opposites = [None] * 16
+opposites[0] = ANY
+
+opposites[OF.value] = NO
+opposites[GT.value] = LE
+opposites[LT.value] = GE
+opposites[EQ.value] = NE
+
+opposites[NO.value] = OF
+opposites[LE.value] = GT
+opposites[GE.value] = LT
+opposites[NE.value] = EQ
+
+opposites[FGE.value] = FLT
+opposites[FLE.value] = FGT
+
+opposites[FGT.value] = FLE
+opposites[FLT.value] = FGE
+
+opposites[ANY.value] = ConditionLocation(0)
+
 def negate(cond):
-    val = cond.value
-    isfloat = (val & 0x10) != 0
-    cc = (~val) & 0xf
-    if isfloat:
-        # inverting is handeled differently for floats
-        return ConditionLocation(cc | FLOAT.value)
-    return ConditionLocation(cc)
-
-def prepare_float_condition(cond):
-    newcond = ConditionLocation(cond.value | FLOAT.value)
-    return newcond
+    cc = opposites[cond.value]
+    if cc is None:
+        assert 0, "provide a sane value to negate"
+    return cc
 
 def _assert_value(v1, v2):
     assert v1.value == v2.value
-
 _assert_value(negate(EQ), NE)
 _assert_value(negate(NE), EQ)
 _assert_value(negate(LT), GE)
@@ -60,4 +77,11 @@
 _assert_value(negate(GE), LT)
 _assert_value(negate(NO), OF)
 _assert_value(negate(OF), NO)
+
+_assert_value(negate(FLE), FGT)
+_assert_value(negate(FGT), FLE)
+
+_assert_value(negate(FGE), FLT)
+_assert_value(negate(FLT), FGE)
+
 del _assert_value
diff --git a/rpython/jit/backend/zarch/helper/assembler.py 
b/rpython/jit/backend/zarch/helper/assembler.py
--- a/rpython/jit/backend/zarch/helper/assembler.py
+++ b/rpython/jit/backend/zarch/helper/assembler.py
@@ -12,11 +12,6 @@
     assert not l0.is_imm()
     # do the comparison
     self.mc.cmp_op(l0, l1, pool=l1.is_in_pool(), imm=l1.is_imm(), 
signed=signed, fp=fp)
-
-    if fp:
-        # Support for NaNs: S390X sets condition register to 0x3 (unordered)
-        # as soon as any of the operands is NaN
-        condition = c.prepare_float_condition(condition)
     self.flush_cc(condition, arglocs[2])
 
 
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
@@ -240,12 +240,19 @@
     emit_float_mul = gen_emit_rr_or_rpool('MDBR','MDB')
     emit_float_truediv = gen_emit_rr_or_rpool('DDBR','DDB')
 
+    # Support for NaNs: S390X sets condition code to 0x3 (unordered)
+    # whenever any operand is nan.
+    # in the case float_le,float_ge the overflow bit is not set of
+    # the initial condition!
+    # e.g. guard_true(nan <= x): jumps 1100 inv => 0011, bit 3 set
+    # e.g. guard_false(nan <= x): does not jump 1100, bit 3 not set
+    # e.g. guard_true(nan >= nan): jumps 1010 inv => 0101, bit 3 set
     emit_float_lt = gen_emit_cmp_op(c.LT, fp=True)
-    emit_float_le = gen_emit_cmp_op(c.LE, fp=True)
+    emit_float_le = gen_emit_cmp_op(c.FLE, fp=True)
     emit_float_eq = gen_emit_cmp_op(c.EQ, fp=True)
     emit_float_ne = gen_emit_cmp_op(c.NE, fp=True)
     emit_float_gt = gen_emit_cmp_op(c.GT, fp=True)
-    emit_float_ge = gen_emit_cmp_op(c.GE, fp=True)
+    emit_float_ge = gen_emit_cmp_op(c.FGE, fp=True)
 
     def emit_float_neg(self, op, arglocs, regalloc):
         l0, = arglocs
@@ -633,6 +640,7 @@
             self.guard_success_cc = c.cond_none
             assert fcond.value != c.cond_none.value
             fcond = c.negate(fcond)
+
         token = self.build_guard_token(op, arglocs[0].value, arglocs[1:], 
fcond)
         token.pos_jump_offset = self.mc.currpos()
         assert token.guard_not_invalidated() == is_guard_not_invalidated
diff --git a/rpython/jit/backend/zarch/test/test_runner.py 
b/rpython/jit/backend/zarch/test/test_runner.py
--- a/rpython/jit/backend/zarch/test/test_runner.py
+++ b/rpython/jit/backend/zarch/test/test_runner.py
@@ -24,7 +24,7 @@
         cpu.setup_once()
         return cpu
 
-    add_loop_instructions = "lg; lgr; larl; agr; cgfi; je; j;$"
+    add_loop_instructions = "lg; lgr; larl; agr; cgfi; jge; j;$"
     # realloc frame takes the most space (from just after larl, to lay)
     bridge_loop_instructions = "larl; lg; cgfi; jhe; lghi; " \
                                "iilf;( iihf;)? iilf;( iihf;)? basr; lg; br;$"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to