Make all jumps relative, and maybe change format. #297
Replies: 8 comments 14 replies
-
Are you thinking we could transition to this new design in time for the feature freeze? Or is this more a 3.12 thing? |
Beta Was this translation helpful? Give feedback.
-
It depends on how everything else goes. I don't see any reason not to do this for 3.11, but we might just run out of time. |
Beta Was this translation helpful? Give feedback.
-
python/cpython#31575 more than doubles the number of |
Beta Was this translation helpful? Give feedback.
-
python/cpython#31575 also reduces the number of |
Beta Was this translation helpful? Give feedback.
-
(This is an elaboration of python/cpython#32215 (comment)) There are four jump instructions,
Which means that having a forward and backward version of each would be wasteful. By fixing up backwards branches in the assembler, we don't need to bloat the interpreter with two versions of each of these opcodes and we don't need to complicate the optimizer.
becomes
becomes
Hopefully, these cases should be very rare. |
Beta Was this translation helpful? Give feedback.
-
Rather than complex bit hacks, we could just have a simple rule:
The compiler will need to cope with this restriction, in two ways
with
This is a bit less efficient for Only having forward branches makes specialization a lot simpler, and only Another advantage of this is that we only need to handle |
Beta Was this translation helpful? Give feedback.
-
Remind me what is the reason a while loop may have a conditional jump back? (I understand the continue situation, presumably it's optimizing |
Beta Was this translation helpful? Give feedback.
-
Yes, it does. But it allows us to skip the eval-breaker check in the conditional branch and simplifies the code in |
Beta Was this translation helpful? Give feedback.
-
Currently
JUMP_FORWARD
is relative, but all others are absolute.We should make all jumps relative, because:
first_instr
to find cache entries. With relative jumps we will not need it all, freeing up a register in the interpreter (or saving a memory access).Possible designs.
opcode oparg
, possibly preceded byEXTENDED_ARG
.oparg
is unsigned, so if jumps were to be relative, then the direction would have to be encoded in the instruction. SoPOP_JUMP_IF_TRUE
would becomePOP_JUMP_IF_TRUE_FORWARD
andPOP_JUMP_IF_TRUE_BACKWARD
.Given that inline caches are going spread out the code, jumps of over 255 are going to become more common.
If we use 32 bit instructions, we could also encode the test in the low bit.
Beta Was this translation helpful? Give feedback.
All reactions