Author: Richard Plangger <[email protected]>
Branch: s390x-backend
Changeset: r82156:5040efcfecd0
Date: 2016-02-11 09:31 +0100
http://bitbucket.org/pypy/pypy/changeset/5040efcfecd0/

Log:    fixed two tests where the endian could not match the sequence of
        operations

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,8 +19,8 @@
             import struct
             i = 1
             while i < n:
-                buf = struct.pack("i", i)       # ID: pack
-                x = struct.unpack("i", buf)[0]  # ID: unpack
+                buf = struct.pack("<i", i)       # ID: pack
+                x = struct.unpack("<i", buf)[0]  # ID: unpack
                 i += x / i
             return i
 
@@ -43,20 +43,36 @@
             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
-        # gc_load_indexed_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
-            p88 = newstr(4)
-            strsetitem(p88, 0, i11)
-            strsetitem(p88, 1, i14)
-            strsetitem(p88, 2, i17)
-            strsetitem(p88, 3, i20)
-            i91 = gc_load_indexed_i(p88, 0, 1, _, -4)
-        """)
+        if sys.byteorder == 'little':
+            # 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
+            # gc_load_indexed_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
+                p88 = newstr(4)
+                strsetitem(p88, 0, i11)
+                strsetitem(p88, 1, i14)
+                strsetitem(p88, 2, i17)
+                strsetitem(p88, 3, i20)
+                i91 = gc_load_indexed_i(p88, 0, 1, _, -4)
+            """)
+        else:
+            # on a big endian machine we cannot just write into
+            # a char buffer and then use load gc to read the integer,
+            # here manual shifting is applied
+            assert loop.match_by_id("unpack", """
+                # struct.unpack
+                i95 = int_lshift(i90, 8)
+                i96 = int_or(i88, i95)
+                i97 = int_lshift(i92, 16)
+                i98 = int_or(i96, i97)
+                i99 = int_ge(i94, 128)
+                guard_false(i99, descr=...)
+                i100 = int_lshift(i94, 24)
+                i101 = int_or(i98, i100)
+            """)
 
     def test_struct_object(self):
         def main(n):
@@ -72,31 +88,32 @@
         log = self.run(main, [1000])
         assert log.result == main(1000)
 
-        loop, = log.loops_by_filename(self.filepath)
-        assert loop.match_by_id('pack', """
-            guard_not_invalidated(descr=...)
-            # struct.pack
-            %s
-            i11 = int_and(i4, 255)
-            i13 = int_rshift(i4, 8)
-            i14 = int_and(i13, 255)
-            i16 = int_rshift(i13, 8)
-            i17 = int_and(i16, 255)
-            i19 = int_rshift(i16, 8)
-            i20 = int_and(i19, 255)
-        """ % extra)
+        if sys.byteorder == 'little':
+            loop, = log.loops_by_filename(self.filepath)
+            assert loop.match_by_id('pack', """
+                guard_not_invalidated(descr=...)
+                # struct.pack
+                %s
+                i11 = int_and(i4, 255)
+                i13 = int_rshift(i4, 8)
+                i14 = int_and(i13, 255)
+                i16 = int_rshift(i13, 8)
+                i17 = int_and(i16, 255)
+                i19 = int_rshift(i16, 8)
+                i20 = int_and(i19, 255)
+            """ % extra)
 
-        assert loop.match_by_id('unpack', """
-            # struct.unpack
-            p88 = newstr(8)
-            strsetitem(p88, 0, 255)
-            strsetitem(p88, 1, 255)
-            strsetitem(p88, 2, 255)
-            strsetitem(p88, 3, 255)
-            strsetitem(p88, 4, i11)
-            strsetitem(p88, 5, i14)
-            strsetitem(p88, 6, i17)
-            strsetitem(p88, 7, i20)
-            i90 = gc_load_indexed_i(p88, 0, 1, _, -4)
-            i91 = gc_load_indexed_i(p88, 4, 1, _, -4)
-        """)
+            assert loop.match_by_id('unpack', """
+                # struct.unpack
+                p88 = newstr(8)
+                strsetitem(p88, 0, 255)
+                strsetitem(p88, 1, 255)
+                strsetitem(p88, 2, 255)
+                strsetitem(p88, 3, 255)
+                strsetitem(p88, 4, i11)
+                strsetitem(p88, 5, i14)
+                strsetitem(p88, 6, i17)
+                strsetitem(p88, 7, i20)
+                i90 = gc_load_indexed_i(p88, 0, 1, _, -4)
+                i91 = gc_load_indexed_i(p88, 4, 1, _, -4)
+            """)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to