Understanding bytecode arguments: 1 byte versus 2 bytes

adam.preble at gmail.com adam.preble at gmail.com
Tue Jan 7 00:58:55 EST 2020


I'm trying to understand the difference in disassemblies with 3.6+ versus older versions of CPython. It looks like the basic opcodes like LOAD_FAST are 3 bytes in pre-3.6 versions, but 2 bytes in 3.6+. I read online somewhere that there was a change to the argument sizes in 3.6: it became 2 bytes when it used to be just one. I wanted to verify that. For 3.6, if an opcode takes an argument, can I always assume that argument is just one byte?

I can think of some situations where that doesn't sounds right. For example, JUMP_ABSOLUTE would be a problem, although I have yet to see that opcode in the wild. Actually, I'd be worried about more involved jumps because it sounds like with just a single-byte offset that I'd have to sometimes make trampolines to jump to where I ultimately need to be. Again, I haven't really hit that, but I'm also use 2-byte opcodes.

What I have works, but it looks ... fairly simple for me to reduce the opcode size so I wanted to understand some of the decisions that were made go to a single-byte argument size in 3.6.


More information about the Python-list mailing list