[pypy-svn] r67121 - in pypy/branch/pyjitpl5/pypy/jit/backend/x86: . test

arigo at codespeak.net arigo at codespeak.net
Sun Aug 23 17:17:31 CEST 2009


Author: arigo
Date: Sun Aug 23 17:17:29 2009
New Revision: 67121

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/jump.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_jump.py
Log:
(benjamin, arigo, fijal around)
Start implementing the "real" algorithm from rgenop.py at 57000.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/jump.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/jump.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/jump.py	Sun Aug 23 17:17:29 2009
@@ -1,15 +1,53 @@
+import sys
+from pypy.tool.pairtype import extendabletype
 from pypy.jit.backend.x86.ri386 import *
 
+class __extend__(REG):
+    __metaclass__ = extendabletype
+    def _getregkey(self):
+        return ~self.op
+
+class __extend__(MODRM):
+    __metaclass__ = extendabletype
+    def _getregkey(self):
+        return self.position
+
 
 def remap_stack_layout(assembler, src_locations, dst_locations, tmpreg):
+    pending_dests = len(dst_locations)
+    srccount = {}    # maps dst_locations to how many times the same
+                     # location appears in src_locations
+    for dst in dst_locations:
+        srccount[dst._getregkey()] = 0
     for i in range(len(dst_locations)):
         src = src_locations[i]
-        dst = dst_locations[i]
-        if src is not dst:
-            if isinstance(dst, MODRM):
-                if isinstance(src, MODRM):
-                    assembler.regalloc_load(src, tmpreg)
-                    src = tmpreg
-                assembler.regalloc_store(src, dst)
+        key = src._getregkey()
+        if key in srccount:
+            if key == dst_locations[i]._getregkey():
+                srccount[key] = -sys.maxint     # ignore a move "x = x"
+                pending_dests -= 1
             else:
-                assembler.regalloc_load(src, dst)
+                srccount[key] += 1
+
+    while pending_dests > 0:
+        for i in range(len(dst_locations)):
+            dst = dst_locations[i]
+            key = dst._getregkey()
+            if srccount[key] == 0:
+                srccount[key] = -1       # means "it's done"
+                pending_dests -= 1
+                src = src_locations[i]
+                key = src._getregkey()
+                if key in srccount:
+                    srccount[key] -= 1
+                _move(assembler, src, dst, tmpreg)
+
+
+def _move(assembler, src, dst, tmpreg):
+    if isinstance(dst, MODRM):
+        if isinstance(src, MODRM):
+            assembler.regalloc_load(src, tmpreg)
+            src = tmpreg
+        assembler.regalloc_store(src, dst)
+    else:
+        assembler.regalloc_load(src, dst)

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_jump.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_jump.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_jump.py	Sun Aug 23 17:17:29 2009
@@ -1,4 +1,5 @@
 from pypy.jit.backend.x86.ri386 import *
+from pypy.jit.backend.x86.regalloc import stack_pos
 from pypy.jit.backend.x86.jump import remap_stack_layout
 
 class MockAssembler:
@@ -41,9 +42,9 @@
     remap_stack_layout(assembler, [eax, ebx, ecx, edx, esi, edi],
                                   [eax, ebx, ecx, edx, esi, edi], '?')
     assert assembler.ops == []
-    s8 = mem(ebp, -8)
-    s12 = mem(ebp, -12)
-    s20 = mem(ebp, -20)
+    s8 = stack_pos(1)
+    s12 = stack_pos(31)
+    s20 = stack_pos(6)
     remap_stack_layout(assembler, [eax, ebx, ecx, s20, s8, edx, s12, esi, edi],
                                   [eax, ebx, ecx, s20, s8, edx, s12, esi, edi],
                                   '?')
@@ -58,12 +59,25 @@
 
 def test_simple_stacklocs():
     assembler = MockAssembler()
-    s8 = mem(ebp, -8)
-    s12 = mem(ebp, -12)
-    s20 = mem(ebp, -20)
-    s24 = mem(ebp, -24)
+    s8 = stack_pos(0)
+    s12 = stack_pos(13)
+    s20 = stack_pos(20)
+    s24 = stack_pos(221)
     remap_stack_layout(assembler, [s8, eax, s12], [s20, s24, edi], edx)
     assert assembler.ops == [('load', s8, edx),
                              ('store', edx, s20),
                              ('store', eax, s24),
                              ('load', s12, edi)]
+
+def test_reordering():
+    assembler = MockAssembler()
+    s8 = stack_pos(8)
+    s12 = stack_pos(12)
+    s20 = stack_pos(19)
+    s24 = stack_pos(1)
+    remap_stack_layout(assembler, [eax, s8, s20, ebx],
+                                  [s8, ebx, eax, edi], '?')
+    assert assembler.got([('load', ebx, edi),
+                          ('load', s8, ebx),
+                          ('store', eax, s8),
+                          ('load', s20, eax)])



More information about the Pypy-commit mailing list