[pypy-svn] r68192 - in pypy/trunk/pypy/jit/metainterp: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Oct 5 22:10:54 CEST 2009


Author: cfbolz
Date: Mon Oct  5 22:10:52 2009
New Revision: 68192

Modified:
   pypy/trunk/pypy/jit/metainterp/resume.py
   pypy/trunk/pypy/jit/metainterp/test/test_resume.py
Log:
(pedronis jumping around, cfbolz): use a new tag for not-too-large integers in
the resume data to make stuff more compact.


Modified: pypy/trunk/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/resume.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/resume.py	Mon Oct  5 22:10:52 2009
@@ -3,6 +3,7 @@
 from pypy.jit.metainterp.resoperation import rop
 from pypy.rpython.lltypesystem import rffi
 from pypy.rlib import rarithmetic
+from pypy.rlib.objectmodel import we_are_translated
 
 # Logic to encode the chain of frames and the state of the boxes at a
 # guard operation, and to decode it again.  This is a bit advanced,
@@ -80,8 +81,9 @@
     return rarithmetic.widen(x) == rarithmetic.widen(y)
 
 TAGCONST    = 0
-TAGBOX      = 1
-TAGVIRTUAL  = 2
+TAGINT      = 1
+TAGBOX      = 2
+TAGVIRTUAL  = 3
 
 NEXTFRAME = tag(-1, TAGVIRTUAL)
 UNASSIGNED = tag(-1, TAGBOX)
@@ -219,6 +221,15 @@
             return self.liveboxes[box]
 
     def _getconst(self, const):
+        if isinstance(const, ConstInt):
+            val = const.getint()
+            try:
+                if not we_are_translated() and not isinstance(val, int):
+                    # unhappiness, probably a symbolic
+                    raise ValueError
+                return tag(val, TAGINT)
+            except ValueError:
+                pass
         result = tag(len(self.consts), TAGCONST)
         self.consts.append(const)
         return result
@@ -332,6 +343,8 @@
             virtuals = self.virtuals
             assert virtuals is not None
             return virtuals[num]
+        elif tag == TAGINT:
+            return ConstInt(num)
         else:
             assert tag == TAGBOX
             return self.liveboxes[num]

Modified: pypy/trunk/pypy/jit/metainterp/test/test_resume.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_resume.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_resume.py	Mon Oct  5 22:10:52 2009
@@ -60,6 +60,34 @@
     lst = reader.consume_boxes()
     assert lst == [b1s, b2s, b3s]
 
+def test_simple_read_tagged_ints():
+    b1, b2, b3 = [BoxInt(), BoxPtr(), BoxInt()]
+    storage = Storage()
+    storage.rd_frame_infos = []
+    storage.rd_consts = []
+    storage.rd_nums = [tag(0, TAGBOX),
+                       tag(1, TAGINT),
+                       tag(0, TAGBOX),
+                       tag(1, TAGBOX),
+                       NEXTFRAME,
+                       tag(2, TAGINT),
+                       tag(3, TAGINT),
+                       NEXTFRAME,
+                       tag(0, TAGBOX),
+                       tag(1, TAGBOX),
+                       tag(2, TAGBOX),
+                       NEXTFRAME
+                       ]
+    storage.rd_virtuals = None
+    b1s, b2s, b3s = [BoxInt(), BoxPtr(), BoxInt()]
+    assert b1s != b3s
+    reader = ResumeDataReader(storage, [b1s, b2s, b3s])
+    lst = reader.consume_boxes()
+    assert lst == [b1s, ConstInt(1), b1s, b2s]
+    lst = reader.consume_boxes()
+    assert lst == [ConstInt(2), ConstInt(3)]
+    lst = reader.consume_boxes()
+    assert lst == [b1s, b2s, b3s]
 
 def test_frame_info():
     storage = Storage()
@@ -298,6 +326,25 @@
     assert lst == [b1t, b2t, b3t]
     assert metainterp.trace == []
 
+def test_virtual_adder_int_constants():
+    b1s, b2s, b3s = [ConstInt(sys.maxint), ConstInt(2**16), ConstInt(-65)]
+    storage = make_storage(b1s, b2s, b3s)
+    modifier = ResumeDataVirtualAdder(storage)
+    modifier.walk_snapshots({})
+    liveboxes = modifier.finish({})
+    assert storage.rd_snapshot is None
+    metainterp = MyMetaInterp(LLtypeMixin.cpu)
+    reader = ResumeDataReader(storage, [], metainterp)
+    lst = reader.consume_boxes()
+    assert lst == [ConstInt(sys.maxint), ConstInt(1), ConstInt(sys.maxint),
+                   ConstInt(2**16)]
+    lst = reader.consume_boxes()
+    assert lst == [ConstInt(2), ConstInt(3)]
+    lst = reader.consume_boxes()
+    assert lst == [b1s, b2s, b3s]
+    assert metainterp.trace == []
+
+
 def test_virtual_adder_no_op_renaming():
     b1s, b2s, b3s = [BoxInt(1), BoxInt(2), BoxInt(3)]
     storage = make_storage(b1s, b2s, b3s)



More information about the Pypy-commit mailing list