On 2016-02-05 3:35 PM, Serhiy Storchaka wrote:
I don't think we need to expose the intermediate representation any farther along than the `PyCode_Optimize` step.[^4] Just moving the optimize one step earlier in the chain solves more than enough to be worth it.
LGTM. I did have the same idea when added specialized 8-bit opcodes.
Agree.
Some optimization (like constant folding) it is worth to move yet one step earlier, to AST.
Other idea - instead of EXTENDED_ARG have two sets of instructions: short 16-bit with 8-bit arg, and long 32-bit with 24-bit arg. For simplicity initially only long instructions are emitted (if it makes sense). After optimization the code is packed using short instructions if possible (now we have all needed information and can do this in one pass). At the same time NOPs are removed. For later stages we easy can unpack the code back to long form.
I also had this idea (don't know if it's good or not): 1. have 16 bits per opcode 2. first 8 bits encode the opcode number 3. next 7 bits encode the arg (most args don't need more than 7 bits anyways) 4. if the 16th bit is 1 then the next opcode is the EXTENDED_ARG We can then encode EXTENDED_ARG to follow the same format -- first 15 bits are for the arg, the last one is to add one more EXTENDED_ARG. Yury