mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-100239: specialize BINARY_OP/SUBSCR for list-slice (#132626)
This commit is contained in:
parent
3831752689
commit
5529213d4e
15 changed files with 552 additions and 354 deletions
72
Python/generated_cases.c.h
generated
72
Python/generated_cases.c.h
generated
|
@ -763,6 +763,78 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BINARY_OP_SUBSCR_LIST_SLICE) {
|
||||
#if Py_TAIL_CALL_INTERP
|
||||
int opcode = BINARY_OP_SUBSCR_LIST_SLICE;
|
||||
(void)(opcode);
|
||||
#endif
|
||||
_Py_CODEUNIT* const this_instr = next_instr;
|
||||
(void)this_instr;
|
||||
frame->instr_ptr = next_instr;
|
||||
next_instr += 6;
|
||||
INSTRUCTION_STATS(BINARY_OP_SUBSCR_LIST_SLICE);
|
||||
static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
|
||||
_PyStackRef tos;
|
||||
_PyStackRef nos;
|
||||
_PyStackRef list_st;
|
||||
_PyStackRef sub_st;
|
||||
_PyStackRef res;
|
||||
// _GUARD_TOS_SLICE
|
||||
{
|
||||
tos = stack_pointer[-1];
|
||||
PyObject *o = PyStackRef_AsPyObjectBorrow(tos);
|
||||
if (!PySlice_Check(o)) {
|
||||
UPDATE_MISS_STATS(BINARY_OP);
|
||||
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
|
||||
JUMP_TO_PREDICTED(BINARY_OP);
|
||||
}
|
||||
}
|
||||
// _GUARD_NOS_LIST
|
||||
{
|
||||
nos = stack_pointer[-2];
|
||||
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
|
||||
if (!PyList_CheckExact(o)) {
|
||||
UPDATE_MISS_STATS(BINARY_OP);
|
||||
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
|
||||
JUMP_TO_PREDICTED(BINARY_OP);
|
||||
}
|
||||
}
|
||||
/* Skip 5 cache entries */
|
||||
// _BINARY_OP_SUBSCR_LIST_SLICE
|
||||
{
|
||||
sub_st = tos;
|
||||
list_st = nos;
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);
|
||||
assert(PySlice_Check(sub));
|
||||
assert(PyList_CheckExact(list));
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
PyObject *res_o = _PyList_SliceSubscript(list, sub);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (res_o == NULL) {
|
||||
UPDATE_MISS_STATS(BINARY_OP);
|
||||
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
|
||||
JUMP_TO_PREDICTED(BINARY_OP);
|
||||
}
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
_PyStackRef tmp = list_st;
|
||||
list_st = res;
|
||||
stack_pointer[-2] = list_st;
|
||||
PyStackRef_CLOSE(tmp);
|
||||
tmp = sub_st;
|
||||
sub_st = PyStackRef_NULL;
|
||||
stack_pointer[-1] = sub_st;
|
||||
PyStackRef_CLOSE(tmp);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
stack_pointer += -1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BINARY_OP_SUBSCR_STR_INT) {
|
||||
#if Py_TAIL_CALL_INTERP
|
||||
int opcode = BINARY_OP_SUBSCR_STR_INT;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue