Skip to content

Commit 6183cbd

Browse files
brandtbucherFidget-Spinner
authored andcommitted
pythonGH-100982: Break up COMPARE_AND_BRANCH (pythonGH-102801)
1 parent 9227b98 commit 6183cbd

19 files changed

+232
-332
lines changed

Doc/library/dis.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,15 +1042,6 @@ iterations of the loop.
10421042
``cmp_op[opname]``.
10431043

10441044

1045-
.. opcode:: COMPARE_AND_BRANCH (opname)
1046-
1047-
Compares the top two values on the stack, popping them, then branches.
1048-
The direction and offset of the jump is embedded as a ``POP_JUMP_IF_TRUE``
1049-
or ``POP_JUMP_IF_FALSE`` instruction immediately following the cache.
1050-
1051-
.. versionadded:: 3.12
1052-
1053-
10541045
.. opcode:: IS_OP (invert)
10551046

10561047
Performs ``is`` comparison, or ``is not`` if ``invert`` is 1.

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
244244
int nargs, PyObject *kwnames);
245245
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
246246
int oparg, PyObject **locals);
247-
extern void _Py_Specialize_CompareAndBranch(PyObject *lhs, PyObject *rhs,
247+
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
248248
_Py_CODEUNIT *instr, int oparg);
249249
extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
250250
int oparg);

Include/internal/pycore_opcode.h

Lines changed: 13 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode.h

Lines changed: 53 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def _write_atomic(path, data, mode=0o666):
435435
# Python 3.12a6 3519 (Modify SEND instruction)
436436
# Python 3.12a6 3520 (Remove PREP_RERAISE_STAR, add CALL_INTRINSIC_2)
437437
# Python 3.12a7 3521 (Shrink the LOAD_GLOBAL caches)
438-
# Python 3.12a7 3522 (Removed JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP)
438+
# Python 3.12a7 3523 (Convert COMPARE_AND_BRANCH back to COMPARE_OP)
439439

440440
# Python 3.13 will start with 3550
441441

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

455-
MAGIC_NUMBER = (3522).to_bytes(2, 'little') + b'\r\n'
455+
MAGIC_NUMBER = (3523).to_bytes(2, 'little') + b'\r\n'
456456

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

Lib/opcode.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ def pseudo_op(name, op, real_ops):
191191
def_op('DELETE_DEREF', 139)
192192
hasfree.append(139)
193193
jrel_op('JUMP_BACKWARD', 140) # Number of words to skip (backwards)
194-
def_op('COMPARE_AND_BRANCH', 141) # Comparison and jump
195-
hascompare.append(141)
196194

197195
def_op('CALL_FUNCTION_EX', 142) # Flags
198196

@@ -320,10 +318,10 @@ def pseudo_op(name, op, real_ops):
320318
"CALL_NO_KW_TUPLE_1",
321319
"CALL_NO_KW_TYPE_1",
322320
],
323-
"COMPARE_AND_BRANCH": [
324-
"COMPARE_AND_BRANCH_FLOAT",
325-
"COMPARE_AND_BRANCH_INT",
326-
"COMPARE_AND_BRANCH_STR",
321+
"COMPARE_OP": [
322+
"COMPARE_OP_FLOAT",
323+
"COMPARE_OP_INT",
324+
"COMPARE_OP_STR",
327325
],
328326
"FOR_ITER": [
329327
"FOR_ITER_LIST",
@@ -404,9 +402,6 @@ def pseudo_op(name, op, real_ops):
404402
"COMPARE_OP": {
405403
"counter": 1,
406404
},
407-
"COMPARE_AND_BRANCH": {
408-
"counter": 1,
409-
},
410405
"BINARY_SUBSCR": {
411406
"counter": 1,
412407
"type_version": 2,

Lib/test/test_compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ def test_multiline_boolean_expression(self):
12831283
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_FALSE',
12841284
line=2, end_line=2, column=15, end_column=16, occurrence=2)
12851285
# compare d and 0
1286-
self.assertOpcodeSourcePositionIs(compiled_code, 'COMPARE_AND_BRANCH',
1286+
self.assertOpcodeSourcePositionIs(compiled_code, 'COMPARE_OP',
12871287
line=4, end_line=4, column=8, end_column=13, occurrence=1)
12881288
# jump if comparison it True
12891289
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE',

0 commit comments

Comments
 (0)