Skip to content

Commit c6d56d4

Browse files
committed
Modernize CALL_PY_EXACT_ARGS
1 parent 2613ac4 commit c6d56d4

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

Python/bytecodes.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,27 +2484,27 @@ dummy_func(
24842484
GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS);
24852485
}
24862486

2487-
// stack effect: (__0, __array[oparg] -- )
2488-
inst(CALL_PY_EXACT_ARGS) {
2487+
inst(CALL_PY_EXACT_ARGS, (unused/1, func_version/2, unused/1, thing1, thing2, unused[oparg] -- unused)) {
24892488
assert(kwnames == NULL);
24902489
DEOPT_IF(tstate->interp->eval_frame, CALL);
2491-
_PyCallCache *cache = (_PyCallCache *)next_instr;
2492-
int is_meth = is_method(stack_pointer, oparg);
2490+
// _PyCallCache *cache = (_PyCallCache *)next_instr;
2491+
int is_meth = thing1 != NULL;
24932492
int argcount = oparg + is_meth;
2494-
PyObject *callable = PEEK(argcount + 1);
2493+
PyObject *callable = is_meth ? thing1 : thing2;
24952494
DEOPT_IF(!PyFunction_Check(callable), CALL);
24962495
PyFunctionObject *func = (PyFunctionObject *)callable;
2497-
DEOPT_IF(func->func_version != read_u32(cache->func_version), CALL);
2496+
DEOPT_IF(func->func_version != func_version, CALL);
24982497
PyCodeObject *code = (PyCodeObject *)func->func_code;
24992498
DEOPT_IF(code->co_argcount != argcount, CALL);
25002499
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
25012500
STAT_INC(CALL, hit);
25022501
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func, argcount);
2502+
// Manipulate stack directly since we leave using DISPATCH_INLINED().
25032503
STACK_SHRINK(argcount);
25042504
for (int i = 0; i < argcount; i++) {
25052505
new_frame->localsplus[i] = stack_pointer[i];
25062506
}
2507-
STACK_SHRINK(2-is_meth);
2507+
STACK_SHRINK(2 - is_meth);
25082508
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
25092509
DISPATCH_INLINED(new_frame);
25102510
}

Python/generated_cases.c.h

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
291291
case CALL_BOUND_METHOD_EXACT_ARGS:
292292
return oparg + 2;
293293
case CALL_PY_EXACT_ARGS:
294-
return -1;
294+
return oparg + 2;
295295
case CALL_PY_WITH_DEFAULTS:
296296
return -1;
297297
case CALL_NO_KW_TYPE_1:
@@ -637,7 +637,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
637637
case CALL_BOUND_METHOD_EXACT_ARGS:
638638
return 1;
639639
case CALL_PY_EXACT_ARGS:
640-
return -1;
640+
return 1;
641641
case CALL_PY_WITH_DEFAULTS:
642642
return -1;
643643
case CALL_NO_KW_TYPE_1:
@@ -844,7 +844,7 @@ struct opcode_metadata {
844844
[KW_NAMES] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
845845
[CALL] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
846846
[CALL_BOUND_METHOD_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
847-
[CALL_PY_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
847+
[CALL_PY_EXACT_ARGS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
848848
[CALL_PY_WITH_DEFAULTS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
849849
[CALL_NO_KW_TYPE_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
850850
[CALL_NO_KW_STR_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
 (0)