<p>Do know my registervm project? I try to emit better bytecode. See the implementation on</p>
<p><a href="http://hg.python.org/sandbox/registervm" target="_blank">http://hg.python.org/sandbox/registervm</a></p><p>See for example the documentation:<br></p><p><a href="http://hg.python.org/sandbox/registervm" target="_blank">hg.python.org/sandbox/registervm/file/tip/REGISTERVM.txt<br>

</a></p>
<p>I implemented other optimisations. See also WPython project which uses also more efficient bytecode.</p><p><a href="http://code.google.com/p/wpython/">http://code.google.com/p/wpython/</a><br></p>
<p>Victor</p>
<div class="gmail_quote">Le 9 déc. 2012 23:23, "Mark Shannon" <<a href="mailto:mark@hotpy.org" target="_blank">mark@hotpy.org</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



Hi all,<br>
<br>
The current CPython bytecode interpreter is rather more complex than it needs to be. A number of bytecodes could be eliminated and a few more simplified by moving the work involved in handling compound statements (loops, try-blocks, etc) from the interpreter to the compiler.<br>




<br>
This simplest example of this is the while loop...<br>
while cond:<br>
   body<br>
<br>
This currently compiled as<br>
<br>
start:<br>
   if not cond goto end<br>
   body<br>
   goto start<br>
end:<br>
<br>
but it could be compiled as<br>
<br>
goto test:<br>
start:<br>
    body<br>
    if cond goto start<br>
<br>
which eliminates one instruction per iteration.<br>
<br>
A more complex example is a return in a try-finally block.<br>
<br>
try:<br>
    part1<br>
    if cond:<br>
        return X<br>
    part2<br>
finally:<br>
    part3<br>
<br>
Currently, handling the return is complex and involves "pseudo exceptions", but if part3 were duplicated by the compiler, then the RETURN bytecode could just perform a simple return.<br>
The code above would be compiled thus...<br>
<br>
    PUSH_BLOCK try<br>
    part1<br>
    if not X goto endif<br>
    push X<br>
    POP_BLOCK<br>
    part3           <<< duplicated<br>
    RETURN_VALUE<br>
endif:<br>
    part2<br>
    POP_BLOCK<br>
    part3           <<< duplicated<br>
<br>
The changes I am proposing are:<br>
<br>
Allow negative line deltas in the lnotab array (bytecode deltas would remain non-negative)<br>
Remove the SETUP_LOOP, BREAK and CONTINUE bytecodes<br>
Simplify the RETURN bytecode<br>
Eliminate "pseudo exceptions" from the interpreter<br>
Simplify (or perhaps eliminate) SETUP_TRY, END_FINALLY, END_WITH.<br>
Reverse the sense of the FOR_ITER bytecode (ie. jump on not-exhausted)<br>
<br>
<br>
The net effect of these changes would be:<br>
Reduced code size and reduced code complexity.<br>
A small (1-5%)? increase in speed, due the simplification of the<br>
bytecodes and a very small change in the number of bytecodes executed.<br>
A small change in the static size of the bytecodes (-2% to +2%)?<br>
<br>
Although this is a quite intrusive change, I think it is worthwhile as it simplifies ceval.c considerably.<br>
The interpreter has become rather convoluted and any simplification has to be a good thing.<br>
<br>
I've already implemented negative line deltas and the transformed while loop: <a href="https://bitbucket.org/markshannon/cpython-lnotab-signed" target="_blank">https://bitbucket.org/<u></u>markshannon/cpython-lnotab-<u></u>signed</a><br>




I'm currently working on the block unwinding.<br>
<br>
So,<br>
Good idea? Bad idea?<br>
Should I write a PEP or is the bug tracker sufficient?<br>
<br>
Cheers,<br>
Mark.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com" target="_blank">http://mail.python.org/<u></u>mailman/options/python-dev/<u></u>victor.stinner%40gmail.com</a><br>
</blockquote></div>