Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct
Changeset: r80874:c32ced64c29f
Date: 2015-11-24 00:58 +0100
http://bitbucket.org/pypy/pypy/changeset/c32ced64c29f/

Log:    fix test_pypy_c/test_struct, to reflect the new optimization

diff --git a/pypy/module/pypyjit/test_pypy_c/test_struct.py 
b/pypy/module/pypyjit/test_pypy_c/test_struct.py
--- a/pypy/module/pypyjit/test_pypy_c/test_struct.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_struct.py
@@ -19,7 +19,8 @@
             import struct
             i = 1
             while i < n:
-                x = struct.unpack("i", struct.pack("i", i))[0]  # ID: struct
+                buf = struct.pack("i", i)       # ID: pack
+                x = struct.unpack("i", buf)[0]  # ID: unpack
                 i += x / i
             return i
 
@@ -29,7 +30,7 @@
         loop, = log.loops_by_filename(self.filepath)
         # This could, of course stand some improvement, to remove all these
         # arithmatic ops, but we've removed all the core overhead.
-        assert loop.match_by_id("struct", """
+        assert loop.match_by_id("pack", """
             guard_not_invalidated(descr=...)
             # struct.pack
             %s
@@ -40,17 +41,22 @@
             i17 = int_and(i16, 255)
             i19 = int_rshift(i16, 8)
             i20 = int_and(i19, 255)
+        """ % extra)
 
+        # the newstr and the strsetitems are because the string is forced,
+        # which is in turn because the optimizer doesn't know how to handle a
+        # getarrayitem_gc_i on a virtual string. It could be improved, but it
+        # is also true that in real life cases struct.unpack is called on
+        # strings which come from the outside, so it's a minor issue.
+        assert loop.match_by_id("unpack", """
             # struct.unpack
-            i22 = int_lshift(i14, 8)
-            i23 = int_or(i11, i22)
-            i25 = int_lshift(i17, 16)
-            i26 = int_or(i23, i25)
-            i28 = int_ge(i20, 128)
-            guard_false(i28, descr=...)
-            i30 = int_lshift(i20, 24)
-            i31 = int_or(i26, i30)
-        """ % extra)
+            p88 = newstr(4)
+            strsetitem(p88, 0, i11)
+            strsetitem(p88, 1, i14)
+            strsetitem(p88, 2, i17)
+            strsetitem(p88, 3, i20)
+            i91 = getarrayitem_gc_i(p88, 0, descr=<ArrayS 4>)
+        """)
 
     def test_struct_object(self):
         def main(n):
@@ -58,7 +64,8 @@
             s = struct.Struct("i")
             i = 1
             while i < n:
-                x = s.unpack(s.pack(i))[0]  # ID: struct
+                buf = s.pack(i)       # ID: pack
+                x = s.unpack(buf)[0]  # ID: unpack
                 i += x / i
             return i
 
@@ -66,7 +73,7 @@
         assert log.result == main(1000)
 
         loop, = log.loops_by_filename(self.filepath)
-        assert loop.match_by_id('struct', """
+        assert loop.match_by_id('pack', """
             guard_not_invalidated(descr=...)
             # struct.pack
             %s
@@ -77,14 +84,14 @@
             i17 = int_and(i16, 255)
             i19 = int_rshift(i16, 8)
             i20 = int_and(i19, 255)
+        """ % extra)
 
+        assert loop.match_by_id('unpack', """
             # struct.unpack
-            i22 = int_lshift(i14, 8)
-            i23 = int_or(i11, i22)
-            i25 = int_lshift(i17, 16)
-            i26 = int_or(i23, i25)
-            i28 = int_ge(i20, 128)
-            guard_false(i28, descr=...)
-            i30 = int_lshift(i20, 24)
-            i31 = int_or(i26, i30)
-        """ % extra)
+            p88 = newstr(4)
+            strsetitem(p88, 0, i11)
+            strsetitem(p88, 1, i14)
+            strsetitem(p88, 2, i17)
+            strsetitem(p88, 3, i20)
+            i91 = getarrayitem_gc_i(p88, 0, descr=<ArrayS 4>)
+        """)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to