[pypy-svn] r35886 - pypy/dist/pypy/jit/codegen/i386
arigo at codespeak.net
arigo at codespeak.net
Tue Dec 19 14:53:18 CET 2006
Author: arigo
Date: Tue Dec 19 14:53:16 2006
New Revision: 35886
Modified:
pypy/dist/pypy/jit/codegen/i386/codebuf.py
pypy/dist/pypy/jit/codegen/i386/rgenop.py
Log:
An optimization that avoids the 'JMP right_to_the_next_insn'
that are now common.
Modified: pypy/dist/pypy/jit/codegen/i386/codebuf.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/codebuf.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/codebuf.py Tue Dec 19 14:53:16 2006
@@ -41,6 +41,11 @@
baseaddr = cast(self._data, c_void_p).value
return baseaddr + self._pos
+ def seekback(self, count):
+ pos = self._pos - count
+ self._pos = pos
+ self._last_dump_start = pos
+
def execute(self, arg1, arg2):
# XXX old testing stuff
fnptr = cast(self._data, binaryfn)
Modified: pypy/dist/pypy/jit/codegen/i386/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/i386/rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/i386/rgenop.py Tue Dec 19 14:53:16 2006
@@ -241,15 +241,32 @@
come_froms = self._pending_come_from
self._pending_come_from = None
for start, (end, insn) in come_froms.iteritems():
- mc = self.rgenop.InMemoryCodeBuilder(start, end)
- self._emit_come_from(mc, insn, self.start)
- mc.done()
+ if end == self.start:
+ # there was a pending JMP just before self.start,
+ # so we can as well overwrite the JMP and start writing
+ # code directly there
+ self.mc.seekback(end - start)
+ self.start = start
+ break
+ for start, (end, insn) in come_froms.iteritems():
+ if start != self.start:
+ mc = self.rgenop.InMemoryCodeBuilder(start, end)
+ self._emit_come_from(mc, insn, self.start)
+ mc.done()
else:
# We have been paused and are being opened again.
- # Patch the jump at the end of the previous codeblock.
- mc = self.rgenop.InMemoryCodeBuilder(*self.tail)
- mc.JMP(rel32(self.mc.tell()))
- mc.done()
+ # Is the new codeblock immediately after the previous one?
+ prevstart, prevend = self.tail
+ curpos = self.mc.tell()
+ if prevend == curpos:
+ # Yes. We can overwrite the JMP and just continue writing
+ # code directly there
+ self.mc.seekback(prevend - prevstart)
+ else:
+ # No. Patch the jump at the end of the previous codeblock.
+ mc = self.rgenop.InMemoryCodeBuilder(prevstart, prevend)
+ mc.JMP(rel32(curpos))
+ mc.done()
def pause(self):
if self.mc is None:
More information about the Pypy-commit
mailing list