[Python-ideas] More compact bytecode

Sven R. Kunze srkunze at mail.de
Thu Feb 4 12:27:39 EST 2016


On 04.02.2016 17:55, Serhiy Storchaka wrote:
> On 04.02.16 18:16, Victor Stinner wrote:
>>> 1. Add 1-byte dedicated opcodes for most used opcodes with arguments.
>>
>> It means duplicating a lot of code in ceval.c, no? (Even if we use C
>> #define "templates"). I dislike this option.
>
> This needs to add less than 40 lines of code in ceval.c. 5-line macro 
> and 1 line per new opcode. A little more lines need to be added to 
> compiler, peephole optimizer, opcode.py, opcode.h and the documentation.
>

Do you have a working CPython to showcast this?

>>> 2. Use 16-bit opcodes as in WPython.
>>
>> IMHO this is a much more interesting option.
>>
>> It would be great to remove "if (HAS_ARG(opcode)) oparg = NEXTARG();"
>> and always get the argument from the 16-bit opcode. This if() adds
>> more work to the CPU which has to flush the pipeline on branch
>> misprediction. Usually, it doesn't matter. For this if() is really
>> part of the hot path code Python, it's the most important loop running
>> the bytecode. So any instruction matters here ;-)
>
> Actually in common case this "if" is executed at compile time. But I 
> expect a benefit from using simple read of 16-bit value instead of 3 
> reads of 8-bit values.

Same question as above + does it make sense to combine those two options?


Best,
Sven


More information about the Python-ideas mailing list