Skip to content

Commit a0d4ece

Browse files
committed
Modernize CALL_PY_EXACT_ARGS
1 parent 8d551fc commit a0d4ece

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
@@ -2472,27 +2472,27 @@ dummy_func(
24722472
GO_TO_INSTRUCTION(CALL_PY_EXACT_ARGS);
24732473
}
24742474

2475-
// stack effect: (__0, __array[oparg] -- )
2476-
inst(CALL_PY_EXACT_ARGS) {
2475+
inst(CALL_PY_EXACT_ARGS, (unused/1, func_version/2, unused/1, thing1, thing2, unused[oparg] -- unused)) {
24772476
assert(kwnames == NULL);
24782477
DEOPT_IF(tstate->interp->eval_frame, CALL);
2479-
_PyCallCache *cache = (_PyCallCache *)next_instr;
2480-
int is_meth = is_method(stack_pointer, oparg);
2478+
// _PyCallCache *cache = (_PyCallCache *)next_instr;
2479+
int is_meth = thing1 != NULL;
24812480
int argcount = oparg + is_meth;
2482-
PyObject *callable = PEEK(argcount + 1);
2481+
PyObject *callable = is_meth ? thing1 : thing2;
24832482
DEOPT_IF(!PyFunction_Check(callable), CALL);
24842483
PyFunctionObject *func = (PyFunctionObject *)callable;
2485-
DEOPT_IF(func->func_version != read_u32(cache->func_version), CALL);
2484+
DEOPT_IF(func->func_version != func_version, CALL);
24862485
PyCodeObject *code = (PyCodeObject *)func->func_code;
24872486
DEOPT_IF(code->co_argcount != argcount, CALL);
24882487
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize), CALL);
24892488
STAT_INC(CALL, hit);
24902489
_PyInterpreterFrame *new_frame = _PyFrame_PushUnchecked(tstate, func, argcount);
2490+
// Manipulate stack directly since we leave using DISPATCH_INLINED().
24912491
STACK_SHRINK(argcount);
24922492
for (int i = 0; i < argcount; i++) {
24932493
new_frame->localsplus[i] = stack_pointer[i];
24942494
}
2495-
STACK_SHRINK(2-is_meth);
2495+
STACK_SHRINK(2 - is_meth);
24962496
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
24972497
DISPATCH_INLINED(new_frame);
24982498
}

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)