Skip to content

Commit

Permalink
pythonGH-100982: Break up COMPARE_AND_BRANCH (pythonGH-102801)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtbucher authored and Fidget-Spinner committed Mar 27, 2023
1 parent 9227b98 commit 6183cbd
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 332 deletions.
9 changes: 0 additions & 9 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1042,15 +1042,6 @@ iterations of the loop.
``cmp_op[opname]``.


.. opcode:: COMPARE_AND_BRANCH (opname)

Compares the top two values on the stack, popping them, then branches.
The direction and offset of the jump is embedded as a ``POP_JUMP_IF_TRUE``
or ``POP_JUMP_IF_FALSE`` instruction immediately following the cache.

.. versionadded:: 3.12


.. opcode:: IS_OP (invert)

Performs ``is`` comparison, or ``is not`` if ``invert`` is 1.
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames);
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
int oparg, PyObject **locals);
extern void _Py_Specialize_CompareAndBranch(PyObject *lhs, PyObject *rhs,
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
_Py_CODEUNIT *instr, int oparg);
extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
int oparg);
Expand Down
27 changes: 13 additions & 14 deletions Include/internal/pycore_opcode.h

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

107 changes: 53 additions & 54 deletions Include/opcode.h

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

4 changes: 2 additions & 2 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12a6 3519 (Modify SEND instruction)
# Python 3.12a6 3520 (Remove PREP_RERAISE_STAR, add CALL_INTRINSIC_2)
# Python 3.12a7 3521 (Shrink the LOAD_GLOBAL caches)
# Python 3.12a7 3522 (Removed JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP)
# Python 3.12a7 3523 (Convert COMPARE_AND_BRANCH back to COMPARE_OP)

# Python 3.13 will start with 3550

Expand All @@ -452,7 +452,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 = (3522).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3523).to_bytes(2, 'little') + b'\r\n'

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

Expand Down
13 changes: 4 additions & 9 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,6 @@ def pseudo_op(name, op, real_ops):
def_op('DELETE_DEREF', 139)
hasfree.append(139)
jrel_op('JUMP_BACKWARD', 140) # Number of words to skip (backwards)
def_op('COMPARE_AND_BRANCH', 141) # Comparison and jump
hascompare.append(141)

def_op('CALL_FUNCTION_EX', 142) # Flags

Expand Down Expand Up @@ -320,10 +318,10 @@ def pseudo_op(name, op, real_ops):
"CALL_NO_KW_TUPLE_1",
"CALL_NO_KW_TYPE_1",
],
"COMPARE_AND_BRANCH": [
"COMPARE_AND_BRANCH_FLOAT",
"COMPARE_AND_BRANCH_INT",
"COMPARE_AND_BRANCH_STR",
"COMPARE_OP": [
"COMPARE_OP_FLOAT",
"COMPARE_OP_INT",
"COMPARE_OP_STR",
],
"FOR_ITER": [
"FOR_ITER_LIST",
Expand Down Expand Up @@ -404,9 +402,6 @@ def pseudo_op(name, op, real_ops):
"COMPARE_OP": {
"counter": 1,
},
"COMPARE_AND_BRANCH": {
"counter": 1,
},
"BINARY_SUBSCR": {
"counter": 1,
"type_version": 2,
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ def test_multiline_boolean_expression(self):
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_FALSE',
line=2, end_line=2, column=15, end_column=16, occurrence=2)
# compare d and 0
self.assertOpcodeSourcePositionIs(compiled_code, 'COMPARE_AND_BRANCH',
self.assertOpcodeSourcePositionIs(compiled_code, 'COMPARE_OP',
line=4, end_line=4, column=8, end_column=13, occurrence=1)
# jump if comparison it True
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE',
Expand Down
Loading

0 comments on commit 6183cbd

Please sign in to comment.