[pypy-commit] pypy default: eliminate some ops in logical_xor

bdkearns noreply at buildbot.pypy.org
Fri Dec 5 23:27:56 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r74849:794a98c020bf
Date: 2014-12-05 16:39 -0500
http://bitbucket.org/pypy/pypy/changeset/794a98c020bf/

Log:	eliminate some ops in logical_xor

diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -429,14 +429,13 @@
             'getfield_gc': 2,
             'getfield_gc_pure': 11,
             'guard_class': 1,
-            'guard_false': 2,
+            'guard_false': 1,
             'guard_not_invalidated': 1,
-            'guard_true': 4,
+            'guard_true': 5,
             'int_add': 2,
             'int_and': 1,
             'int_ge': 1,
-            'int_is_true': 3,
-            'int_xor': 1,
+            'int_is_true': 2,
             'jump': 1,
             'new_with_vtable': 1,
             'raw_load': 1,
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -285,7 +285,9 @@
 
     @raw_binary_op
     def logical_xor(self, v1, v2):
-        return bool(v1) ^ bool(v2)
+        a = bool(v1)
+        b = bool(v2)
+        return (not b and a) or (not a and b)
 
     @raw_unary_op
     def bool(self, v):
@@ -1258,7 +1260,9 @@
 
     @raw_binary_op
     def logical_xor(self, v1, v2):
-        return self._bool(v1) ^ self._bool(v2)
+        a = self._bool(v1)
+        b = self._bool(v2)
+        return (not b and a) or (not a and b)
 
     def min(self, v1, v2):
         if self.le(v1, v2) or self.isnan(v1):
@@ -1733,7 +1737,9 @@
 
     @str_binary_op
     def logical_xor(self, v1, v2):
-        return bool(v1) ^ bool(v2)
+        a = bool(v1)
+        b = bool(v2)
+        return (not b and a) or (not a and b)
 
     def bool(self, v):
         return bool(self.to_str(v))
diff --git a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
--- a/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_micronumpy.py
@@ -30,9 +30,7 @@
             guard_true(i14, descr=...)
             i15 = getfield_gc_pure(p1, descr=<FieldU pypy.module.micronumpy.boxes.W_BoolBox.inst_value \d+>)
             i16 = int_is_true(i15)
-            i18 = int_xor(i16, 1)
-            i19 = int_is_true(i18)
-            guard_true(i19, descr=...)
+            guard_false(i16, descr=...)
             i20 = getfield_gc(p2, descr=<FieldS pypy.module.micronumpy.iterators.IterState.inst_index \d+>)
             i21 = getfield_gc_pure(p0, descr=<FieldU pypy.module.micronumpy.iterators.ArrayIter.inst_track_index \d+>)
             guard_true(i21, descr=...)


More information about the pypy-commit mailing list