[Python-Dev] computed goto's in ceval loop

Simon Burton simon at arrowtheory.com
Wed Jan 18 04:56:12 CET 2006



I have been experimenting with replacing the big switch in ceval.c by
a computed goto construct [1]. It uses #define's to make it optional.
This work was inspired by Mono's MINT interpreter code,
and Neil Norwitz's attempt to use a function pointer table [2].

Result: about 1% slower on the pystone benchmark.

It also seems to have broken the interpreter; at least one test fails (test_StringIO). Whoops.

Not sure if the other switch-speedup hacks (eg. PREDICT(op)) conflict 
at all with this patch (ie. make it slower than it could be).

Mono uses a much larger opcode set, with 2-byte opcodes, that includes
type info in each opcode. This means that the actual case statements are much faster.

My initial thought about using computed goto's (January 2003) was that the python opcode cases
were much fatter than mono's (often involving a function call) so that the overhead of
branching on opcodes would be insignificant. It seems that this is true indeed.

The patch id is 1408710.

[1] http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/Labels-as-Values.html
[2] http://mail.python.org/pipermail/python-dev/2003-February/033705.html

Simon.



-- 
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com 


More information about the Python-Dev mailing list