[pypy-svn] r37832 - in pypy/dist/pypy/jit/codegen/ppc: . test

mwh at codespeak.net mwh at codespeak.net
Fri Feb 2 22:28:11 CET 2007


Author: mwh
Date: Fri Feb  2 22:28:09 2007
New Revision: 37832

Modified:
   pypy/dist/pypy/jit/codegen/ppc/emit_moves.py
   pypy/dist/pypy/jit/codegen/ppc/rgenop.py
   pypy/dist/pypy/jit/codegen/ppc/test/test_emit_moves.py
Log:
fix the bug in the smarter version of emit_moves -- if there's a "safe"
conflict then there may be more than one target the source needs to be copied
to.  add a fairly beefy random test.


Modified: pypy/dist/pypy/jit/codegen/ppc/emit_moves.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/ppc/emit_moves.py	(original)
+++ pypy/dist/pypy/jit/codegen/ppc/emit_moves.py	Fri Feb  2 22:28:09 2007
@@ -44,7 +44,7 @@
     data.emitted = []
 
     for tar, src in tar2src.items():
-        data.src2tar[src] = tar
+        data.src2tar.setdefault(src, []).append(tar)
 
     for src, loc in src2loc.items():
         if src in data.src2tar:
@@ -77,7 +77,8 @@
     if conflictsrcvar not in data.srcstack:
         # No cycle on our stack yet
         data.srcstack.append(srcvar)
-        _cycle_walk(gen, data.src2tar[conflictsrcvar], data)
+        for tar in data.src2tar[conflictsrcvar]:
+            _cycle_walk(gen, tar, data)
         srcloc = data.src2loc[srcvar] # warning: may have changed, so reload
         gen.emit_move(tarloc, srcloc)
         data.emitted.append(tarvar)

Modified: pypy/dist/pypy/jit/codegen/ppc/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/ppc/rgenop.py	(original)
+++ pypy/dist/pypy/jit/codegen/ppc/rgenop.py	Fri Feb  2 22:28:09 2007
@@ -184,7 +184,7 @@
                 allocator.free_stack_slots.remove(tloc)
 
     gen = JumpPatchupGenerator(insns, allocator)
-    emit_moves_safe(gen, tarvars, tar2src, tar2loc, src2loc)
+    emit_moves(gen, tarvars, tar2src, tar2loc, src2loc)
 
     for i in range(len(targetlocs)):
         tloc = targetlocs[i]

Modified: pypy/dist/pypy/jit/codegen/ppc/test/test_emit_moves.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/ppc/test/test_emit_moves.py	(original)
+++ pypy/dist/pypy/jit/codegen/ppc/test/test_emit_moves.py	Fri Feb  2 22:28:09 2007
@@ -1,5 +1,5 @@
 import py
-from pypy.jit.codegen.ppc.emit_moves import emit_moves
+from pypy.jit.codegen.ppc.emit_moves import emit_moves, emit_moves_safe
 
 class TheHeap(object):
     def __init__(self, locs):
@@ -53,9 +53,7 @@
     assert heap.data[2] == 2
     assert heap.numlocs == 3 # only creates 1 extra loc
 
-
 def test_one_to_many():
-    py.test.skip("failing :(")
     heap = TheHeap(4)
     tar2src = {'A':'a', 'B':'b', 'C':'a'}
     tar2loc = {'A':2, 'B':1, 'C':3}
@@ -68,3 +66,34 @@
     assert heap.data[1] == 0 # B
     assert heap.data[2] == 1 # A
     assert heap.data[3] == 1 # C
+
+def test_random():
+    for _ in range(20):
+        import random
+        NVAR = random.randrange(1000)
+        heap = TheHeap(NVAR)
+        varlist = range(NVAR)
+        tar2src = {}
+        src2loc = {}
+        tar2loc = {}
+        for i in varlist:
+            tar2src[i] = random.randrange(NVAR)
+        srcs = list(dict.fromkeys(tar2src.values()))
+        srclocs = srcs[:]
+        random.shuffle(srclocs)
+        for j, k in zip(srcs, srclocs):
+            src2loc[j] = k
+        varlist2 = varlist[:]
+        random.shuffle(varlist2)
+        for i, j in zip(varlist, varlist2):
+            tar2loc[i] = j
+        for i in range(10):
+            random.shuffle(varlist)
+            heap1 = TheHeap(NVAR)
+            emit_moves(heap1, varlist,
+                            tar2src.copy(), tar2loc.copy(), src2loc.copy())
+            heap2 = TheHeap(NVAR)
+            emit_moves_safe(heap2, varlist,
+                            tar2src.copy(), tar2loc.copy(), src2loc.copy())
+            for i in range(NVAR):
+                assert heap1.data[i] == heap2.data[i]



More information about the Pypy-commit mailing list