Skip to content

Commit 18a0642

Browse files
committed
Modernize CALL_BUILTIN_CLASS (a different way)
1 parent 72ab5b1 commit 18a0642

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

Python/bytecodes.c

+12-15
Original file line numberDiff line numberDiff line change
@@ -2576,31 +2576,28 @@ dummy_func(
25762576
CHECK_EVAL_BREAKER();
25772577
}
25782578

2579-
// stack effect: (__0, __array[oparg] -- )
2580-
inst(CALL_BUILTIN_CLASS) {
2581-
int is_meth = is_method(stack_pointer, oparg);
2582-
int total_args = oparg + is_meth;
2579+
inst(CALL_BUILTIN_CLASS, (unused/1, unused/2, unused/1, method, callable, args[oparg] -- res)) {
2580+
int is_meth = method != NULL;
2581+
int total_args = oparg;
2582+
if (is_meth) {
2583+
callable = method;
2584+
args--;
2585+
total_args++;
2586+
}
25832587
int kwnames_len = KWNAMES_LEN();
2584-
PyObject *callable = PEEK(total_args + 1);
25852588
DEOPT_IF(!PyType_Check(callable), CALL);
25862589
PyTypeObject *tp = (PyTypeObject *)callable;
25872590
DEOPT_IF(tp->tp_vectorcall == NULL, CALL);
25882591
STAT_INC(CALL, hit);
2589-
STACK_SHRINK(total_args);
2590-
PyObject *res = tp->tp_vectorcall((PyObject *)tp, stack_pointer,
2591-
total_args-kwnames_len, kwnames);
2592+
res = tp->tp_vectorcall((PyObject *)tp, args,
2593+
total_args - kwnames_len, kwnames);
25922594
kwnames = NULL;
25932595
/* Free the arguments. */
25942596
for (int i = 0; i < total_args; i++) {
2595-
Py_DECREF(stack_pointer[i]);
2597+
Py_DECREF(args[i]);
25962598
}
25972599
Py_DECREF(tp);
2598-
STACK_SHRINK(1-is_meth);
2599-
SET_TOP(res);
2600-
if (res == NULL) {
2601-
goto error;
2602-
}
2603-
JUMPBY(INLINE_CACHE_ENTRIES_CALL);
2600+
ERROR_IF(res == NULL, error);
26042601
CHECK_EVAL_BREAKER();
26052602
}
26062603

Python/generated_cases.c.h

+19-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
301301
case CALL_NO_KW_TUPLE_1:
302302
return oparg + 2;
303303
case CALL_BUILTIN_CLASS:
304-
return -1;
304+
return oparg + 2;
305305
case CALL_NO_KW_BUILTIN_O:
306306
return -1;
307307
case CALL_NO_KW_BUILTIN_FAST:
@@ -647,7 +647,7 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
647647
case CALL_NO_KW_TUPLE_1:
648648
return 1;
649649
case CALL_BUILTIN_CLASS:
650-
return -1;
650+
return 1;
651651
case CALL_NO_KW_BUILTIN_O:
652652
return -1;
653653
case CALL_NO_KW_BUILTIN_FAST:
@@ -849,7 +849,7 @@ struct opcode_metadata {
849849
[CALL_NO_KW_TYPE_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
850850
[CALL_NO_KW_STR_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
851851
[CALL_NO_KW_TUPLE_1] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
852-
[CALL_BUILTIN_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
852+
[CALL_BUILTIN_CLASS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IBC000 },
853853
[CALL_NO_KW_BUILTIN_O] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
854854
[CALL_NO_KW_BUILTIN_FAST] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },
855855
[CALL_BUILTIN_FAST_WITH_KEYWORDS] = { DIR_NONE, DIR_NONE, DIR_NONE, true, INSTR_FMT_IB },

0 commit comments

Comments
 (0)