Skip to content

GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. #94168

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

Merged
merged 12 commits into from
Jun 27, 2022
Merged
26 changes: 21 additions & 5 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,13 @@ result back on the stack.

**Binary and in-place operations**

Binary operations remove the top of the stack (TOS) and the second top-most
stack item (TOS1) from the stack. They perform the operation, and put the
result back on the stack.
In the following, TOS is the top-of-stack.
TOS1, TOS2, TOS3 are the second, thrid and fourth items on the stack, respectively.

Binary operations remove the top two items from the stack (TOS and TOS1).
They perform the operation, then put the result back on the stack.

In-place operations are like binary operations, in that they remove TOS and
TOS1, and push the result back on the stack, but the operation is done in-place
In-place operations are like binary operations, but the operation is done in-place
when TOS1 supports it, and the resulting TOS may be (but does not have to be)
the original TOS1.

Expand All @@ -460,6 +461,7 @@ the original TOS1.

Implements the binary and in-place operators (depending on the value of
*op*).
``TOS = TOS1 op TOS``.

.. versionadded:: 3.11

Expand All @@ -479,6 +481,20 @@ the original TOS1.
Implements ``del TOS1[TOS]``.


.. opcode:: BINARY_SLICE

Implements ``TOS = TOS2[TOS1:TOS]``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the preamble to this section in lines 449-456 needs to be updated because it only refers to TOS and TOS1.


.. versionadded:: 3.12


.. opcode:: STORE_SLICE

Implements ``TOS2[TOS1:TOS] = TOS3``.

.. versionadded:: 3.12


**Coroutine opcodes**

.. opcode:: GET_AWAITABLE (where)
Expand Down
58 changes: 30 additions & 28 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_sliceobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern "C" {

extern void _PySlice_Fini(PyInterpreterState *);

extern PyObject *
_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop);

#ifdef __cplusplus
}
Expand Down
112 changes: 57 additions & 55 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12a1 3503 (Shrink LOAD_METHOD cache)
# Python 3.12a1 3504 (Merge LOAD_METHOD back into LOAD_ATTR)
# Python 3.12a1 3505 (Specialization/Cache for FOR_ITER)
# Python 3.12a1 3506 (Add BINARY_SLICE and STORE_SLICE instructions)

# Python 3.13 will start with 3550

Expand All @@ -422,7 +423,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3505).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3506).to_bytes(2, 'little') + b'\r\n'

_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

Expand Down
Loading