Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-100188: Reduce misses in BINARY_SUBSCR_LIST_INT #100189

Merged
merged 6 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``BINARY_SUBSCR_LIST_INT`` instruction is no longer used for negative ``int``s, since that instruction always misses when encountering negative integers.
sweeneyde marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 6 additions & 2 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,12 @@ _Py_Specialize_BinarySubscr(
PyTypeObject *container_type = Py_TYPE(container);
if (container_type == &PyList_Type) {
if (PyLong_CheckExact(sub)) {
_Py_SET_OPCODE(*instr, BINARY_SUBSCR_LIST_INT);
goto success;
if (Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1) {
_Py_SET_OPCODE(*instr, BINARY_SUBSCR_LIST_INT);
goto success;
}
SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_RANGE);
goto fail;
}
SPECIALIZATION_FAIL(BINARY_SUBSCR,
PySlice_Check(sub) ? SPEC_FAIL_SUBSCR_LIST_SLICE : SPEC_FAIL_OTHER);
Expand Down