[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Understanding bytecode arguments: 1 byte versus 2 bytes

On Tue, Jan 7, 2020 at 5:01 PM <adam.preble at> wrote:
> 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.

There was an extensive discussion about it. If you want to go poking
around, the keyword to search for is "wordcode". It's quite an
interesting read.... if you are in no hurry to go anywhere else. :)