[pypy-svn] r77001 - pypy/branch/jit-generator/pypy/jit/backend/x86

arigo at codespeak.net arigo at codespeak.net
Fri Sep 10 15:11:06 CEST 2010


Author: arigo
Date: Fri Sep 10 15:11:04 2010
New Revision: 77001

Modified:
   pypy/branch/jit-generator/pypy/jit/backend/x86/assembler.py
Log:
Fix: don't rely on the exact stack layout to be the same --
it is not in large examples.


Modified: pypy/branch/jit-generator/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/jit-generator/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/jit-generator/pypy/jit/backend/x86/assembler.py	Fri Sep 10 15:11:04 2010
@@ -326,9 +326,8 @@
         looptoken._x86_param_depth = param_depth
 
         looptoken._x86_direct_bootstrap_code = self.mc.tell()
-        finaljmp = self._assemble_bootstrap_direct_call(arglocs, curadr,
-                                                       frame_depth+param_depth)
-        looptoken._x86_redirect_call_assembler = finaljmp
+        self._assemble_bootstrap_direct_call(arglocs, curadr,
+                                             frame_depth+param_depth)
         #
         debug_print("Loop #", looptoken.number, "has address",
                     looptoken._x86_loop_code, "to", self.mc.tell())
@@ -529,24 +528,6 @@
                 assert isinstance(loc, StackLoc)
                 self.mc.MOVSD_bx(loc.value, xmmtmp.value)
         self.mc.JMP_l(jmpadr)
-        return self.mc.tell()
-
-    def redirect_call_assembler(self, oldlooptoken, newlooptoken):
-        # some minimal sanity checking
-        oldnonfloatlocs, oldfloatlocs = oldlooptoken._x86_arglocs
-        newnonfloatlocs, newfloatlocs = newlooptoken._x86_arglocs
-        assert len(oldnonfloatlocs) == len(newnonfloatlocs)
-        assert len(oldfloatlocs) == len(newfloatlocs)
-        # must patch the JMP at the end of the oldlooptoken's bootstrap-
-        # -direct-call code to go to the new loop's body
-        adr = oldlooptoken._x86_redirect_call_assembler
-        target = newlooptoken._x86_loop_code
-        if IS_X86_64:
-            self.redirect_call_assembler_64(oldlooptoken, newlooptoken)
-        else:
-            mc = codebuf.InMemoryCodeBuilder(adr - 4, adr)
-            mc.writeimm32(target - adr)
-            mc.done()
 
     def _assemble_bootstrap_direct_call_64(self, arglocs, jmpadr, stackdepth):
         # XXX: Very similar to _emit_call_64
@@ -601,15 +582,19 @@
 
         finaljmp = self.mc.tell()
         self.mc.JMP(imm(jmpadr))
-        # leave a total of 16 bytes, enough for all encodings of JMP
-        for i in range(self.mc.tell() - finaljmp, 16):
-            self.mc.NOP()
-        return finaljmp
-
-    def redirect_call_assembler_64(self, adr, target):
-        # we have a total of 16 bytes free to overwrite the JMP,
-        # reserved by _assemble_bootstrap_direct_call_64()
-        mc = codebuf.InMemoryCodeBuilder(adr, adr + 16)
+
+    def redirect_call_assembler(self, oldlooptoken, newlooptoken):
+        # some minimal sanity checking
+        oldnonfloatlocs, oldfloatlocs = oldlooptoken._x86_arglocs
+        newnonfloatlocs, newfloatlocs = newlooptoken._x86_arglocs
+        assert len(oldnonfloatlocs) == len(newnonfloatlocs)
+        assert len(oldfloatlocs) == len(newfloatlocs)
+        # we overwrite the instructions at the old _x86_direct_bootstrap_code
+        # to start with a JMP to the new _x86_direct_bootstrap_code.
+        # Ideally we should rather patch all existing CALLs, but well.
+        oldadr = oldlooptoken._x86_direct_bootstrap_code
+        target = newlooptoken._x86_direct_bootstrap_code
+        mc = codebuf.InMemoryCodeBuilder(oldadr, oldadr + 16)
         mc.JMP(imm(target))
         mc.done()
 



More information about the Pypy-commit mailing list