Skip to content

Commit

Permalink
Remove specialized opcodes.
Browse files Browse the repository at this point in the history
They are used at runtime, and not written to .pyc / .pyo objects.
  • Loading branch information
zrax committed Aug 12, 2024
1 parent f37caa8 commit 19f8372
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 163 deletions.
15 changes: 0 additions & 15 deletions bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,9 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
case Pyc::IMPORT_FROM_A:
case Pyc::IMPORT_NAME_A:
case Pyc::LOAD_ATTR_A:
case Pyc::LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN_A:
case Pyc::LOAD_ATTR_WITH_HINT_A:
case Pyc::LOAD_LOCAL_A:
case Pyc::LOAD_NAME_A:
case Pyc::STORE_ATTR_A:
case Pyc::STORE_ATTR_WITH_HINT_A:
case Pyc::STORE_GLOBAL_A:
case Pyc::STORE_NAME_A:
case Pyc::STORE_ANNOTATION_A:
Expand All @@ -409,8 +406,6 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
}
break;
case Pyc::LOAD_SUPER_ATTR_A:
case Pyc::LOAD_SUPER_ATTR_ATTR_A:
case Pyc::LOAD_SUPER_ATTR_METHOD_A:
case Pyc::INSTRUMENTED_LOAD_SUPER_ATTR_A:
try {
formatted_print(pyc_output, "%d: %s", operand, code->getName(operand >> 2)->value());
Expand Down Expand Up @@ -461,16 +456,11 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
case Pyc::SETUP_EXCEPT_A:
case Pyc::FOR_LOOP_A:
case Pyc::FOR_ITER_A:
case Pyc::FOR_ITER_GEN_A:
case Pyc::FOR_ITER_LIST_A:
case Pyc::FOR_ITER_RANGE_A:
case Pyc::FOR_ITER_TUPLE_A:
case Pyc::SETUP_WITH_A:
case Pyc::SETUP_ASYNC_WITH_A:
case Pyc::POP_JUMP_FORWARD_IF_FALSE_A:
case Pyc::POP_JUMP_FORWARD_IF_TRUE_A:
case Pyc::SEND_A:
case Pyc::SEND_GEN_A:
case Pyc::POP_JUMP_FORWARD_IF_NOT_NONE_A:
case Pyc::POP_JUMP_FORWARD_IF_NONE_A:
case Pyc::POP_JUMP_IF_NOT_NONE_A:
Expand Down Expand Up @@ -520,9 +510,6 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
}
break;
case Pyc::COMPARE_OP_A:
case Pyc::COMPARE_OP_FLOAT_A:
case Pyc::COMPARE_OP_INT_A:
case Pyc::COMPARE_OP_STR_A:
{
auto arg = operand;
if (mod->verCompare(3, 12) == 0)
Expand All @@ -547,8 +534,6 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
: "UNKNOWN");
break;
case Pyc::CONTAINS_OP_A:
case Pyc::CONTAINS_OP_DICT_A:
case Pyc::CONTAINS_OP_SET_A:
formatted_print(pyc_output, "%d (%s)", operand, (operand == 0) ? "in"
: (operand == 1) ? "not in"
: "UNKNOWN");
Expand Down
75 changes: 0 additions & 75 deletions bytecode_ops.inl
Original file line number Diff line number Diff line change
Expand Up @@ -271,81 +271,6 @@ OPCODE_A(SET_FUNCTION_ATTRIBUTE) // Python 3.13 -> A=attrib
OPCODE_A(STORE_FAST_LOAD_FAST) // Python 3.13 -> A=locals[A<<4]+locals[A&0xf]
OPCODE_A(STORE_FAST_STORE_FAST) // Python 3.13 -> A=locals[A<<4]+locals[A&0xf]

/* Specialized opcode variants added in 3.13 */
OPCODE(BINARY_OP_ADD_FLOAT) // Python 3.13 ->
OPCODE(BINARY_OP_ADD_INT) // Python 3.13 ->
OPCODE(BINARY_OP_ADD_UNICODE) // Python 3.13 ->
OPCODE(BINARY_OP_MULTIPLY_FLOAT) // Python 3.13 ->
OPCODE(BINARY_OP_MULTIPLY_INT) // Python 3.13 ->
OPCODE(BINARY_OP_SUBTRACT_FLOAT) // Python 3.13 ->
OPCODE(BINARY_OP_SUBTRACT_INT) // Python 3.13 ->
OPCODE(BINARY_SUBSCR_DICT) // Python 3.13 ->
OPCODE(BINARY_SUBSCR_GETITEM) // Python 3.13 ->
OPCODE(BINARY_SUBSCR_LIST_INT) // Python 3.13 ->
OPCODE(BINARY_SUBSCR_STR_INT) // Python 3.13 ->
OPCODE(BINARY_SUBSCR_TUPLE_INT) // Python 3.13 ->
OPCODE_A(CALL_ALLOC_AND_ENTER_INIT) // Python 3.13 -> A=#args
OPCODE_A(CALL_BOUND_METHOD_EXACT_ARGS) // Python 3.13 -> A=#args
OPCODE_A(CALL_BOUND_METHOD_GENERAL) // Python 3.13 -> A=#args
OPCODE_A(CALL_BUILTIN_CLASS) // Python 3.13 -> A=#args
OPCODE_A(CALL_BUILTIN_FAST) // Python 3.13 -> A=#args
OPCODE_A(CALL_BUILTIN_FAST_WITH_KEYWORDS) // Python 3.13 -> A=#args
OPCODE_A(CALL_BUILTIN_O) // Python 3.13 -> A=#args
OPCODE_A(CALL_ISINSTANCE) // Python 3.13 -> A=#args
OPCODE_A(CALL_LEN) // Python 3.13 -> A=#args
OPCODE_A(CALL_LIST_APPEND) // Python 3.13 -> A=#args
OPCODE_A(CALL_METHOD_DESCRIPTOR_FAST) // Python 3.13 -> A=#args
OPCODE_A(CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS) // Python 3.13 -> A=#args
OPCODE_A(CALL_METHOD_DESCRIPTOR_NOARGS) // Python 3.13 -> A=#args
OPCODE_A(CALL_METHOD_DESCRIPTOR_O) // Python 3.13 -> A=#args
OPCODE_A(CALL_NON_PY_GENERAL) // Python 3.13 -> A=#args
OPCODE_A(CALL_PY_EXACT_ARGS) // Python 3.13 -> A=#args
OPCODE_A(CALL_PY_GENERAL) // Python 3.13 -> A=#args
OPCODE_A(CALL_STR_1) // Python 3.13 -> A=#args
OPCODE_A(CALL_TUPLE_1) // Python 3.13 -> A=#args
OPCODE_A(CALL_TYPE_1) // Python 3.13 -> A=#args
OPCODE_A(COMPARE_OP_FLOAT) // Python 3.13 -> A=(cmp_ops[A<<5])+(flags)
OPCODE_A(COMPARE_OP_INT) // Python 3.13 -> A=(cmp_ops[A<<5])+(flags)
OPCODE_A(COMPARE_OP_STR) // Python 3.13 -> A=(cmp_ops[A<<5])+(flags)
OPCODE_A(CONTAINS_OP_DICT) // Python 3.13 -> A=inverted
OPCODE_A(CONTAINS_OP_SET) // Python 3.13 -> A=inverted
OPCODE_A(FOR_ITER_GEN) // Python 3.13 -> rel jmp +A
OPCODE_A(FOR_ITER_LIST) // Python 3.13 -> rel jmp +A
OPCODE_A(FOR_ITER_RANGE) // Python 3.13 -> rel jmp +A
OPCODE_A(FOR_ITER_TUPLE) // Python 3.13 -> rel jmp +A
OPCODE_A(LOAD_ATTR_CLASS) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN) // Python 3.13 -> A=(names[A<<1])+(flag)
OPCODE_A(LOAD_ATTR_INSTANCE_VALUE) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_METHOD_LAZY_DICT) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_METHOD_NO_DICT) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_METHOD_WITH_VALUES) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_MODULE) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_NONDESCRIPTOR_NO_DICT) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_PROPERTY) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_SLOT) // Python 3.13 -> A=flag
OPCODE_A(LOAD_ATTR_WITH_HINT) // Python 3.13 -> A=(names[A<<1])+(flag)
OPCODE_A(LOAD_GLOBAL_BUILTIN) // Python 3.13 -> A=flag
OPCODE_A(LOAD_GLOBAL_MODULE) // Python 3.13 -> A=flag
OPCODE_A(LOAD_SUPER_ATTR_ATTR) // Python 3.13 -> A=(flags&0x3)+names[A<<2]
OPCODE_A(LOAD_SUPER_ATTR_METHOD) // Python 3.13 -> A=(flags&0x3)+names[A<<2]
OPCODE_A(RESUME_CHECK) // Python 3.13 -> ???
OPCODE_A(SEND_GEN) // Python 3.13 -> rel jmp +A
OPCODE_A(STORE_ATTR_INSTANCE_VALUE) // Python 3.13 -> A=(ignored)
OPCODE_A(STORE_ATTR_SLOT) // Python 3.13 -> A=(ignored)
OPCODE_A(STORE_ATTR_WITH_HINT) // Python 3.13 -> names[A]
OPCODE(STORE_SUBSCR_DICT) // Python 3.13 ->
OPCODE(STORE_SUBSCR_LIST_INT) // Python 3.13 ->
OPCODE(TO_BOOL_ALWAYS_TRUE) // Python 3.13 ->
OPCODE(TO_BOOL_BOOL) // Python 3.13 ->
OPCODE(TO_BOOL_INT) // Python 3.13 ->
OPCODE(TO_BOOL_LIST) // Python 3.13 ->
OPCODE(TO_BOOL_NONE) // Python 3.13 ->
OPCODE(TO_BOOL_STR) // Python 3.13 ->
OPCODE_A(UNPACK_SEQUENCE_LIST) // Python 3.13 -> A=count
OPCODE_A(UNPACK_SEQUENCE_TUPLE) // Python 3.13 -> A=count
OPCODE_A(UNPACK_SEQUENCE_TWO_TUPLE) // Python 3.13 -> A=count

/* Instrumented opcodes */
OPCODE_A(INSTRUMENTED_LOAD_SUPER_ATTR) // Python 3.12 -> (see LOAD_SUPER_ATTR)
OPCODE_A(INSTRUMENTED_POP_JUMP_IF_NONE) // Python 3.12 -> (see POP_JUMP_IF_NONE)
Expand Down
73 changes: 0 additions & 73 deletions bytes/python_3_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,79 +121,6 @@ BEGIN_MAP(3, 13)
MAP_OP(117, UNPACK_SEQUENCE_A)
MAP_OP(118, YIELD_VALUE_A)
MAP_OP(149, RESUME_A)
MAP_OP(150, BINARY_OP_ADD_FLOAT)
MAP_OP(151, BINARY_OP_ADD_INT)
MAP_OP(152, BINARY_OP_ADD_UNICODE)
MAP_OP(153, BINARY_OP_MULTIPLY_FLOAT)
MAP_OP(154, BINARY_OP_MULTIPLY_INT)
MAP_OP(155, BINARY_OP_SUBTRACT_FLOAT)
MAP_OP(156, BINARY_OP_SUBTRACT_INT)
MAP_OP(157, BINARY_SUBSCR_DICT)
MAP_OP(158, BINARY_SUBSCR_GETITEM)
MAP_OP(159, BINARY_SUBSCR_LIST_INT)
MAP_OP(160, BINARY_SUBSCR_STR_INT)
MAP_OP(161, BINARY_SUBSCR_TUPLE_INT)
MAP_OP(162, CALL_ALLOC_AND_ENTER_INIT_A)
MAP_OP(163, CALL_BOUND_METHOD_EXACT_ARGS_A)
MAP_OP(164, CALL_BOUND_METHOD_GENERAL_A)
MAP_OP(165, CALL_BUILTIN_CLASS_A)
MAP_OP(166, CALL_BUILTIN_FAST_A)
MAP_OP(167, CALL_BUILTIN_FAST_WITH_KEYWORDS_A)
MAP_OP(168, CALL_BUILTIN_O_A)
MAP_OP(169, CALL_ISINSTANCE_A)
MAP_OP(170, CALL_LEN_A)
MAP_OP(171, CALL_LIST_APPEND_A)
MAP_OP(172, CALL_METHOD_DESCRIPTOR_FAST_A)
MAP_OP(173, CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS_A)
MAP_OP(174, CALL_METHOD_DESCRIPTOR_NOARGS_A)
MAP_OP(175, CALL_METHOD_DESCRIPTOR_O_A)
MAP_OP(176, CALL_NON_PY_GENERAL_A)
MAP_OP(177, CALL_PY_EXACT_ARGS_A)
MAP_OP(178, CALL_PY_GENERAL_A)
MAP_OP(179, CALL_STR_1_A)
MAP_OP(180, CALL_TUPLE_1_A)
MAP_OP(181, CALL_TYPE_1_A)
MAP_OP(182, COMPARE_OP_FLOAT_A)
MAP_OP(183, COMPARE_OP_INT_A)
MAP_OP(184, COMPARE_OP_STR_A)
MAP_OP(185, CONTAINS_OP_DICT_A)
MAP_OP(186, CONTAINS_OP_SET_A)
MAP_OP(187, FOR_ITER_GEN_A)
MAP_OP(188, FOR_ITER_LIST_A)
MAP_OP(189, FOR_ITER_RANGE_A)
MAP_OP(190, FOR_ITER_TUPLE_A)
MAP_OP(191, LOAD_ATTR_CLASS_A)
MAP_OP(192, LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN_A)
MAP_OP(193, LOAD_ATTR_INSTANCE_VALUE_A)
MAP_OP(194, LOAD_ATTR_METHOD_LAZY_DICT_A)
MAP_OP(195, LOAD_ATTR_METHOD_NO_DICT_A)
MAP_OP(196, LOAD_ATTR_METHOD_WITH_VALUES_A)
MAP_OP(197, LOAD_ATTR_MODULE_A)
MAP_OP(198, LOAD_ATTR_NONDESCRIPTOR_NO_DICT_A)
MAP_OP(199, LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES_A)
MAP_OP(200, LOAD_ATTR_PROPERTY_A)
MAP_OP(201, LOAD_ATTR_SLOT_A)
MAP_OP(202, LOAD_ATTR_WITH_HINT_A)
MAP_OP(203, LOAD_GLOBAL_BUILTIN_A)
MAP_OP(204, LOAD_GLOBAL_MODULE_A)
MAP_OP(205, LOAD_SUPER_ATTR_ATTR_A)
MAP_OP(206, LOAD_SUPER_ATTR_METHOD_A)
MAP_OP(207, RESUME_CHECK_A)
MAP_OP(208, SEND_GEN_A)
MAP_OP(209, STORE_ATTR_INSTANCE_VALUE_A)
MAP_OP(210, STORE_ATTR_SLOT_A)
MAP_OP(211, STORE_ATTR_WITH_HINT_A)
MAP_OP(212, STORE_SUBSCR_DICT)
MAP_OP(213, STORE_SUBSCR_LIST_INT)
MAP_OP(214, TO_BOOL_ALWAYS_TRUE)
MAP_OP(215, TO_BOOL_BOOL)
MAP_OP(216, TO_BOOL_INT)
MAP_OP(217, TO_BOOL_LIST)
MAP_OP(218, TO_BOOL_NONE)
MAP_OP(219, TO_BOOL_STR)
MAP_OP(220, UNPACK_SEQUENCE_LIST_A)
MAP_OP(221, UNPACK_SEQUENCE_TUPLE_A)
MAP_OP(222, UNPACK_SEQUENCE_TWO_TUPLE_A)
MAP_OP(236, INSTRUMENTED_RESUME_A)
MAP_OP(237, INSTRUMENTED_END_FOR_A)
MAP_OP(238, INSTRUMENTED_END_SEND_A)
Expand Down

0 comments on commit 19f8372

Please sign in to comment.