[Python-checkins] gh-100188: Reduce misses in BINARY_SUBSCR_(LIST/TUPLE)_INT (#100189)

sweeneyde webhook-mailer at python.org
Tue Dec 20 15:46:26 EST 2022


https://github.com/python/cpython/commit/c18d83118881333b9a0afd0add83afb2ba7300f7
commit: c18d83118881333b9a0afd0add83afb2ba7300f7
branch: main
author: Dennis Sweeney <36520290+sweeneyde at users.noreply.github.com>
committer: sweeneyde <36520290+sweeneyde at users.noreply.github.com>
date: 2022年12月20日T15:46:16-05:00
summary:
gh-100188: Reduce misses in BINARY_SUBSCR_(LIST/TUPLE)_INT (#100189)
Don't specialize if the index is negative.
files:
A Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst
M Python/specialize.c
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 000000000000..ec62fbd582fb
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-12-05-30-12.gh-issue-100188.sGCSMR.rst	
@@ -0,0 +1,3 @@
+The ``BINARY_SUBSCR_LIST_INT`` and ``BINARY_SUBSCR_TUPLE_INT``
+instructions are no longer used for negative integers because
+those instructions always miss when encountering negative integers.
diff --git a/Python/specialize.c b/Python/specialize.c
index a1666ccc9159..c6c502716478 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -1302,8 +1302,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);
@@ -1311,8 +1315,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);


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /