summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-01-16 12:35:21 (GMT)
committerGitHub <noreply@github.com>2023-01-16 12:35:21 (GMT)
commit7b14c2ef194b6eed79670aa9d7e29ab8e2256a56 (patch)
tree794188d49a9f359cfa7663c25be587634f070f22 /Lib
parentb1a74a182d8762bda51838401ac92b6ebad9632a (diff)
downloadcpython-7b14c2ef194b6eed79670aa9d7e29ab8e2256a56.zip
cpython-7b14c2ef194b6eed79670aa9d7e29ab8e2256a56.tar.gz
cpython-7b14c2ef194b6eed79670aa9d7e29ab8e2256a56.tar.bz2
GH-100982: Add `COMPARE_AND_BRANCH` instruction (GH-100983)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap_external.py3
-rw-r--r--Lib/opcode.py13
-rw-r--r--Lib/test/test_compile.py14
-rw-r--r--Lib/test/test_dis.py8
4 files changed, 22 insertions, 16 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index cbde913..5a8cbb9 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -429,6 +429,7 @@ _code_type = type(_write_atomic.__code__)
# Python 3.12a1 3513 (Add CALL_INTRINSIC_1 instruction, removed STOPITERATION_ERROR, PRINT_EXPR, IMPORT_STAR)
# Python 3.12a1 3514 (Remove ASYNC_GEN_WRAP, LIST_TO_TUPLE, and UNARY_POSITIVE)
# Python 3.12a1 3515 (Embed jump mask in COMPARE_OP oparg)
+# Python 3.12a1 3516 (Add COMAPRE_AND_BRANCH instruction)
# Python 3.13 will start with 3550
@@ -441,7 +442,7 @@ _code_type = type(_write_atomic.__code__)
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3515).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3516).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 414faa3..46051b2 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -189,6 +189,8 @@ hasfree.append(138)
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
@@ -309,10 +311,10 @@ _specializations = {
"CALL_NO_KW_TUPLE_1",
"CALL_NO_KW_TYPE_1",
],
- "COMPARE_OP": [
- "COMPARE_OP_FLOAT_JUMP",
- "COMPARE_OP_INT_JUMP",
- "COMPARE_OP_STR_JUMP",
+ "COMPARE_AND_BRANCH": [
+ "COMPARE_AND_BRANCH_FLOAT",
+ "COMPARE_AND_BRANCH_INT",
+ "COMPARE_AND_BRANCH_STR",
],
"FOR_ITER": [
"FOR_ITER_LIST",
@@ -392,6 +394,9 @@ _cache_format = {
"COMPARE_OP": {
"counter": 1,
},
+ "COMPARE_AND_BRANCH": {
+ "counter": 1,
+ },
"BINARY_SUBSCR": {
"counter": 1,
"type_version": 2,
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index f74d2ed..1606c9c 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -1121,11 +1121,11 @@ if 1:
check_op_count(aug, "BUILD_SLICE", 0)
def test_compare_positions(self):
- for opname, op in [
- ("COMPARE_OP", "<"),
- ("COMPARE_OP", "<="),
- ("COMPARE_OP", ">"),
- ("COMPARE_OP", ">="),
+ for opname_prefix, op in [
+ ("COMPARE_", "<"),
+ ("COMPARE_", "<="),
+ ("COMPARE_", ">"),
+ ("COMPARE_", ">="),
("CONTAINS_OP", "in"),
("CONTAINS_OP", "not in"),
("IS_OP", "is"),
@@ -1140,7 +1140,7 @@ if 1:
actual_positions = [
instruction.positions
for instruction in dis.get_instructions(code)
- if instruction.opname == opname
+ if instruction.opname.startswith(opname_prefix)
]
with self.subTest(source):
self.assertEqual(actual_positions, expected_positions)
@@ -1270,7 +1270,7 @@ if (a or
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_OP',
+ self.assertOpcodeSourcePositionIs(compiled_code, 'COMPARE_AND_BRANCH',
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',
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 994bb37..cb7e22f 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1561,12 +1561,12 @@ expected_opinfo_jumpy = [
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=58, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=60, starts_line=5, is_jump_target=False, positions=None),
Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=62, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='COMPARE_OP', opcode=107, arg=13, argval='<', argrepr='<', offset=64, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COMPARE_AND_BRANCH', opcode=141, arg=13, argval='<', argrepr='<', offset=64, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=1, argval=72, argrepr='to 72', offset=68, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='JUMP_BACKWARD', opcode=140, arg=22, argval=28, argrepr='to 28', offset=70, starts_line=6, is_jump_target=False, positions=None),
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=72, starts_line=7, is_jump_target=True, positions=None),
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=74, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='COMPARE_OP', opcode=107, arg=68, argval='>', argrepr='>', offset=76, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COMPARE_AND_BRANCH', opcode=141, arg=68, argval='>', argrepr='>', offset=76, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=1, argval=84, argrepr='to 84', offset=80, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='JUMP_BACKWARD', opcode=140, arg=28, argval=28, argrepr='to 28', offset=82, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=84, starts_line=8, is_jump_target=True, positions=None),
@@ -1588,12 +1588,12 @@ expected_opinfo_jumpy = [
Instruction(opname='STORE_FAST', opcode=125, arg=0, argval='i', argrepr='i', offset=154, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=156, starts_line=14, is_jump_target=False, positions=None),
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=6, argrepr='6', offset=158, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='COMPARE_OP', opcode=107, arg=75, argval='>', argrepr='>', offset=160, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COMPARE_AND_BRANCH', opcode=141, arg=75, argval='>', argrepr='>', offset=160, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=1, argval=168, argrepr='to 168', offset=164, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='JUMP_BACKWARD', opcode=140, arg=26, argval=116, argrepr='to 116', offset=166, starts_line=15, is_jump_target=False, positions=None),
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=168, starts_line=16, is_jump_target=True, positions=None),
Instruction(opname='LOAD_CONST', opcode=100, arg=2, argval=4, argrepr='4', offset=170, starts_line=None, is_jump_target=False, positions=None),
- Instruction(opname='COMPARE_OP', opcode=107, arg=13, argval='<', argrepr='<', offset=172, starts_line=None, is_jump_target=False, positions=None),
+ Instruction(opname='COMPARE_AND_BRANCH', opcode=141, arg=13, argval='<', argrepr='<', offset=172, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='POP_JUMP_IF_FALSE', opcode=114, arg=1, argval=180, argrepr='to 180', offset=176, starts_line=None, is_jump_target=False, positions=None),
Instruction(opname='JUMP_FORWARD', opcode=110, arg=16, argval=212, argrepr='to 212', offset=178, starts_line=17, is_jump_target=False, positions=None),
Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=180, starts_line=11, is_jump_target=True, positions=None),