Skip to content
6 changes: 3 additions & 3 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ sub-slots
+---------------------------------------------------------+-----------------------------------+---------------+
| :c:member:`~PyNumberMethods.nb_int` | :c:type:`unaryfunc` | __int__ |
+---------------------------------------------------------+-----------------------------------+---------------+
| :c:member:`~PyNumberMethods.nb_reserved` | void * | |
| :c:member:`~PyNumberMethods.nb_reserved` | :c:type:`unaryfunc` | |
+---------------------------------------------------------+-----------------------------------+---------------+
| :c:member:`~PyNumberMethods.nb_float` | :c:type:`unaryfunc` | __float__ |
+---------------------------------------------------------+-----------------------------------+---------------+
Expand Down Expand Up @@ -2098,7 +2098,7 @@ Number Object Structures
binaryfunc nb_xor;
binaryfunc nb_or;
unaryfunc nb_int;
void *nb_reserved;
unaryfunc nb_reserved;
unaryfunc nb_float;

binaryfunc nb_inplace_add;
Expand Down Expand Up @@ -2155,7 +2155,7 @@ Number Object Structures
.. c:member:: binaryfunc PyNumberMethods.nb_xor
.. c:member:: binaryfunc PyNumberMethods.nb_or
.. c:member:: unaryfunc PyNumberMethods.nb_int
.. c:member:: void *PyNumberMethods.nb_reserved
.. c:member:: unaryfunc PyNumberMethods.nb_reserved
.. c:member:: unaryfunc PyNumberMethods.nb_float
.. c:member:: binaryfunc PyNumberMethods.nb_inplace_add
.. c:member:: binaryfunc PyNumberMethods.nb_inplace_subtract
Expand Down
94 changes: 7 additions & 87 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -422,23 +422,6 @@ result back on the stack.
Implements ``TOS = TOS1 * TOS``.


.. opcode:: BINARY_MATRIX_MULTIPLY

Implements ``TOS = TOS1 @ TOS``.

.. versionadded:: 3.5


.. opcode:: BINARY_FLOOR_DIVIDE

Implements ``TOS = TOS1 // TOS``.


.. opcode:: BINARY_TRUE_DIVIDE

Implements ``TOS = TOS1 / TOS``.


.. opcode:: BINARY_MODULO

Implements ``TOS = TOS1 % TOS``.
Expand All @@ -449,41 +432,18 @@ result back on the stack.
Implements ``TOS = TOS1 + TOS``.


.. opcode:: BINARY_SUBTRACT
.. opcode:: BINARY_OP (op)

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

.. versionadded:: 3.11


.. opcode:: BINARY_SUBSCR

Implements ``TOS = TOS1[TOS]``.


.. opcode:: BINARY_LSHIFT

Implements ``TOS = TOS1 << TOS``.


.. opcode:: BINARY_RSHIFT

Implements ``TOS = TOS1 >> TOS``.


.. opcode:: BINARY_AND

Implements ``TOS = TOS1 & TOS``.


.. opcode:: BINARY_XOR

Implements ``TOS = TOS1 ^ TOS``.


.. opcode:: BINARY_OR

Implements ``TOS = TOS1 | TOS``.


**In-place operations**

In-place operations are like binary operations, in that they remove TOS and
Expand All @@ -501,23 +461,6 @@ the original TOS1.
Implements in-place ``TOS = TOS1 * TOS``.


.. opcode:: INPLACE_MATRIX_MULTIPLY

Implements in-place ``TOS = TOS1 @ TOS``.

.. versionadded:: 3.5


.. opcode:: INPLACE_FLOOR_DIVIDE

Implements in-place ``TOS = TOS1 // TOS``.


.. opcode:: INPLACE_TRUE_DIVIDE

Implements in-place ``TOS = TOS1 / TOS``.


.. opcode:: INPLACE_MODULO

Implements in-place ``TOS = TOS1 % TOS``.
Expand All @@ -528,34 +471,11 @@ the original TOS1.
Implements in-place ``TOS = TOS1 + TOS``.


.. opcode:: INPLACE_SUBTRACT

Implements in-place ``TOS = TOS1 - TOS``.

.. opcode:: INPLACE_OP (op)

.. opcode:: INPLACE_LSHIFT
Implements the remaining in-place operators (depending on the value of *op*).

Implements in-place ``TOS = TOS1 << TOS``.


.. opcode:: INPLACE_RSHIFT

Implements in-place ``TOS = TOS1 >> TOS``.


.. opcode:: INPLACE_AND

Implements in-place ``TOS = TOS1 & TOS``.


.. opcode:: INPLACE_XOR

Implements in-place ``TOS = TOS1 ^ TOS``.


.. opcode:: INPLACE_OR

Implements in-place ``TOS = TOS1 | TOS``.
.. versionadded:: 3.11


.. opcode:: STORE_SUBSCR
Expand Down
6 changes: 6 additions & 0 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ Optimizations
CPython bytecode changes
========================

* Replaced most ``BINARY_*`` instructions with a single :opcode:`BINARY_OP`
implementation.

* Replaced most ``INPLACE_*`` instructions with a single :opcode:`INPLACE_OP`
implementation.

* Added a new :opcode:`CALL_METHOD_KW` opcode. Calls a method in a similar
fashion as :opcode:`CALL_METHOD`, but also supports keyword arguments. Works
in tandem with :opcode:`LOAD_METHOD`.
Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ typedef struct {
binaryfunc nb_xor;
binaryfunc nb_or;
unaryfunc nb_int;
void *nb_reserved; /* the slot formerly known as nb_long */
unaryfunc nb_reserved; /* the slot formerly known as nb_long */
unaryfunc nb_float;

binaryfunc nb_inplace_add;
Expand Down
5 changes: 5 additions & 0 deletions Include/internal/pycore_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ _PyIndex_Check(PyObject *obj)
return (tp_as_number != NULL && tp_as_number->nb_index != NULL);
}

PyObject *_PyNumber_BinaryOp(PyObject *v, PyObject *w, const int op_slot,
const char *op_name);
PyObject *_PyNumber_InPlaceOp(PyObject *v, PyObject *w, const int iop_slot,
const int op_slot, const char *op_name);

#ifdef __cplusplus
}
#endif
Expand Down
Loading