From ced2545ed998af4a125140f2d5bfd1897859e3ef Mon Sep 17 00:00:00 2001 From: sweeneyde Date: Mon, 12 Dec 2022 00:15:47 -0500 Subject: [PATCH 1/5] Reduce misses in BINARY_SUBSCR_LIST_INT --- Python/specialize.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Python/specialize.c b/Python/specialize.c index 7545a7712493e6..62b5f3ad83e0cc 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -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); From 3e6aea7b2b12b7f9589491c16edc55ed8498a64c Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 12 Dec 2022 05:30:15 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst new file mode 100644 index 00000000000000..1bb4448e1756f4 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst @@ -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. From 46a689491fa8bae2de192c69b0d0f10943822638 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Mon, 12 Dec 2022 00:33:53 -0500 Subject: [PATCH 3/5] fix NEWS syntax --- .../2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst index 1bb4448e1756f4..a969a76c63d9f9 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst @@ -1 +1 @@ -The ``BINARY_SUBSCR_LIST_INT`` instruction is no longer used for negative ``int``s, since that instruction always misses when encountering negative integers. +The ``BINARY_SUBSCR_LIST_INT`` instruction is no longer used for negative integers because that instruction always misses when encountering negative integers. From 14953006af5e9dbfd9abee64174091a80a026b09 Mon Sep 17 00:00:00 2001 From: sweeneyde Date: Mon, 12 Dec 2022 00:45:14 -0500 Subject: [PATCH 4/5] do tuples too --- .../2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst | 4 +++- Python/specialize.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst index a969a76c63d9f9..7849a1684aac64 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst @@ -1 +1,3 @@ -The ``BINARY_SUBSCR_LIST_INT`` instruction is no longer used for negative integers because that instruction always misses when encountering negative integers. +The ``BINARY_SUBSCR_LIST_INT`` and ``BINARY_SUBSCR_TUPLE_INT`` +instruction are no longer used for negative integers because +those instruction always miss when encountering negative integers. diff --git a/Python/specialize.c b/Python/specialize.c index 62b5f3ad83e0cc..e8ef8df0097a9b 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1275,8 +1275,12 @@ _Py_Specialize_BinarySubscr( } if (container_type == &PyTuple_Type) { if (PyLong_CheckExact(sub)) { - _Py_SET_OPCODE(*instr, BINARY_SUBSCR_TUPLE_INT); - goto success; + if (Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1) { + _Py_SET_OPCODE(*instr, BINARY_SUBSCR_TUPLE_INT); + goto success; + } + SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_RANGE); + goto fail; } SPECIALIZATION_FAIL(BINARY_SUBSCR, PySlice_Check(sub) ? SPEC_FAIL_SUBSCR_TUPLE_SLICE : SPEC_FAIL_OTHER); From 8e52d1e560b72c919cc93ec68170cf94ca2281d5 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Mon, 12 Dec 2022 00:51:45 -0500 Subject: [PATCH 5/5] grammar --- .../2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst index 7849a1684aac64..ec62fbd582fb00 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst @@ -1,3 +1,3 @@ The ``BINARY_SUBSCR_LIST_INT`` and ``BINARY_SUBSCR_TUPLE_INT`` -instruction are no longer used for negative integers because -those instruction always miss when encountering negative integers. +instructions are no longer used for negative integers because +those instructions always miss when encountering negative integers.