Skip to content

Commit 3e9f782

Browse files
Fix handling of EXTENDED_ARG
1 parent 7b5c655 commit 3e9f782

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Python/optimizer.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ PyTypeObject _PyUOpExecutor_Type = {
436436
/* TO DO -- Generate these tables */
437437
static const uint16_t
438438
_PyUOp_Replacements[MAX_UOP_ID + 1] = {
439-
[_CHECK_PERIODIC_AT_END] = _TIER2_RESUME_CHECK,
440439
[_ITER_JUMP_RANGE] = _GUARD_NOT_EXHAUSTED_RANGE,
441440
[_ITER_JUMP_LIST] = _GUARD_NOT_EXHAUSTED_LIST,
442441
[_ITER_JUMP_TUPLE] = _GUARD_NOT_EXHAUSTED_TUPLE,
443442
[_FOR_ITER] = _FOR_ITER_TIER_TWO,
444443
[_ITER_NEXT_LIST] = _ITER_NEXT_LIST_TIER_TWO,
444+
[_CHECK_PERIODIC_AT_END] = _TIER2_RESUME_CHECK,
445445
};
446446

447447
static const uint8_t
@@ -563,6 +563,9 @@ _PyJIT_translate_single_bytecode_to_trace(
563563
uint32_t target = 0;
564564

565565
target = INSTR_IP(target_instr, old_code);
566+
567+
DPRINTF(2, "%d: %s(%d)\n", target, _PyOpcode_OpName[opcode], oparg);
568+
566569
// One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT
567570
max_length -= 2;
568571
if ((uint16_t)oparg != (uint64_t)oparg) {
@@ -575,7 +578,6 @@ _PyJIT_translate_single_bytecode_to_trace(
575578
goto full;
576579
}
577580

578-
DPRINTF(2, "%d: %s(%d)\n", target, _PyOpcode_OpName[opcode], oparg);
579581

580582
if (opcode == EXTENDED_ARG) {
581583
return 1;
@@ -726,10 +728,17 @@ _PyJIT_translate_single_bytecode_to_trace(
726728
uop = _PyUOp_Replacements[uop];
727729
assert(uop != 0);
728730

729-
uint32_t next_inst = target + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[opcode]] + (oparg > 255);
731+
uint32_t next_inst = target + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[opcode]];
730732
if (uop == _TIER2_RESUME_CHECK) {
731733
target = next_inst;
732734
}
735+
#ifdef Py_DEBUG
736+
else if (uop != _FOR_ITER_TIER_TWO) {
737+
uint32_t jump_target = next_inst + oparg;
738+
assert(_Py_GetBaseCodeUnit(old_code, jump_target).op.code == END_FOR);
739+
assert(_Py_GetBaseCodeUnit(old_code, jump_target+1).op.code == POP_ITER);
740+
}
741+
#endif
733742
break;
734743
case OPERAND1_1:
735744
assert(trace[trace_length-1].opcode == uop);
@@ -914,8 +923,7 @@ prepare_for_execution(_PyUOpInstruction *buffer, int length)
914923
if (is_for_iter_test[opcode]) {
915924
/* Target the POP_TOP immediately after the END_FOR,
916925
* leaving only the iterator on the stack. */
917-
int extended_arg = inst->oparg > 255;
918-
int32_t next_inst = target + 1 + INLINE_CACHE_ENTRIES_FOR_ITER + extended_arg;
926+
int32_t next_inst = target + 1 + INLINE_CACHE_ENTRIES_FOR_ITER;
919927
jump_target = next_inst + inst->oparg + 1;
920928
}
921929
if (unique_target || jump_target != current_jump_target || current_exit_op != exit_op) {

0 commit comments

Comments
 (0)