Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r71304:b9a02124b908 Date: 2014-05-05 18:36 -0400 http://bitbucket.org/pypy/pypy/changeset/b9a02124b908/
Log: add (skipped) struct object test_pypy_c diff --git a/pypy/module/pypyjit/test_pypy_c/test_misc.py b/pypy/module/pypyjit/test_pypy_c/test_misc.py --- a/pypy/module/pypyjit/test_pypy_c/test_misc.py +++ b/pypy/module/pypyjit/test_pypy_c/test_misc.py @@ -348,51 +348,6 @@ loop, = log.loops_by_id("globalread", is_entry_bridge=True) assert len(loop.ops_by_id("globalread")) == 0 - def test_struct_module(self): - def main(): - import struct - i = 1 - while i < 1000: - x = struct.unpack("i", struct.pack("i", i))[0] # ID: struct - i += x / i - return i - - log = self.run(main) - assert log.result == main() - - loop, = log.loops_by_id("struct") - if sys.maxint == 2 ** 63 - 1: - extra = """ - i8 = int_ge(i4, -2147483648) - guard_true(i8, descr=...) - """ - else: - extra = "" - # 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", """ - guard_not_invalidated(descr=...) - # struct.pack - %(32_bit_only)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) - - # 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) - """ % {"32_bit_only": extra}) - def test_eval(self): def main(): i = 1 diff --git a/pypy/module/pypyjit/test_pypy_c/test_struct.py b/pypy/module/pypyjit/test_pypy_c/test_struct.py new file mode 100644 --- /dev/null +++ b/pypy/module/pypyjit/test_pypy_c/test_struct.py @@ -0,0 +1,85 @@ +from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC + + +class TestStruct(BaseTestPyPyC): + def test_struct_function(self): + def main(n): + import struct + i = 1 + while i < n: + x = struct.unpack("i", struct.pack("i", i))[0] # ID: struct + i += x / i + return i + + log = self.run(main, [1000]) + assert log.result == main(1000) + + 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", """ + guard_not_invalidated(descr=...) + # struct.pack + i8 = int_ge(i4, -2147483648) + guard_true(i8, descr=...) + i9 = int_le(i4, 2147483647) + guard_true(i9, descr=...) + 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) + + # 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) + """) + + def test_struct_object(self): + skip("XXX broken") + def main(n): + import struct + s = struct.Struct("i") + i = 1 + while i < n: + x = s.unpack(s.pack(i))[0] # ID: struct + i += x / i + return i + + log = self.run(main, [1000]) + assert log.result == main(1000) + + loop, = log.loops_by_filename(self.filepath) + assert loop.match_by_id('struct', """ + guard_not_invalidated(descr=...) + # struct.pack + i8 = int_ge(i4, -2147483648) + guard_true(i8, descr=...) + i9 = int_le(i4, 2147483647) + guard_true(i9, descr=...) + 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) + + # 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) + """) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit