gh-139757: Add BINARY_OP_SUBSCR_USTR_INT (GH-143389)

This commit is contained in:
Chris Eibl 2026-01-04 15:14:27 +01:00 committed by GitHub
parent 6116d70bbd
commit e6bfe4d886
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 1462 additions and 1197 deletions

View File

@ -286,7 +286,8 @@ Known values:
Python 3.15a1 3653 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
Python 3.15a1 3654 (Fix missing exception handlers in logical expression)
Python 3.15a1 3655 (Fix miscompilation of some module-level annotations)
Python 3.15a1 3656 (Add TRACE_RECORD instruction, for platforms with switch based interpreter)
Python 3.15a2 3656 (Add TRACE_RECORD instruction, for platforms with switch based interpreter)
Python 3.15a4 3657 (Add BINARY_OP_SUBSCR_USTR_INT)
Python 3.16 will start with 3700
@ -300,7 +301,7 @@ PC/launcher.c must also be updated.
*/
#define PYC_MAGIC_NUMBER 3656
#define PYC_MAGIC_NUMBER 3657
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \

View File

@ -66,6 +66,8 @@ int _PyOpcode_num_popped(int opcode, int oparg) {
return 2;
case BINARY_OP_SUBSCR_TUPLE_INT:
return 2;
case BINARY_OP_SUBSCR_USTR_INT:
return 2;
case BINARY_OP_SUBTRACT_FLOAT:
return 2;
case BINARY_OP_SUBTRACT_INT:
@ -551,6 +553,8 @@ int _PyOpcode_num_pushed(int opcode, int oparg) {
return 1;
case BINARY_OP_SUBSCR_TUPLE_INT:
return 1;
case BINARY_OP_SUBSCR_USTR_INT:
return 1;
case BINARY_OP_SUBTRACT_FLOAT:
return 1;
case BINARY_OP_SUBTRACT_INT:
@ -1090,8 +1094,9 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[267] = {
[BINARY_OP_SUBSCR_GETITEM] = { true, INSTR_FMT_IXC0000, HAS_DEOPT_FLAG | HAS_SYNC_SP_FLAG | HAS_NEEDS_GUARD_IP_FLAG },
[BINARY_OP_SUBSCR_LIST_INT] = { true, INSTR_FMT_IXC0000, HAS_DEOPT_FLAG | HAS_EXIT_FLAG | HAS_ESCAPES_FLAG },
[BINARY_OP_SUBSCR_LIST_SLICE] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
[BINARY_OP_SUBSCR_STR_INT] = { true, INSTR_FMT_IXC0000, HAS_DEOPT_FLAG | HAS_EXIT_FLAG | HAS_ESCAPES_FLAG },
[BINARY_OP_SUBSCR_STR_INT] = { true, INSTR_FMT_IXC0000, HAS_DEOPT_FLAG | HAS_EXIT_FLAG },
[BINARY_OP_SUBSCR_TUPLE_INT] = { true, INSTR_FMT_IXC0000, HAS_DEOPT_FLAG | HAS_EXIT_FLAG | HAS_ESCAPES_FLAG },
[BINARY_OP_SUBSCR_USTR_INT] = { true, INSTR_FMT_IXC0000, HAS_DEOPT_FLAG | HAS_EXIT_FLAG },
[BINARY_OP_SUBTRACT_FLOAT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG | HAS_ERROR_FLAG | HAS_ERROR_NO_POP_FLAG },
[BINARY_OP_SUBTRACT_INT] = { true, INSTR_FMT_IXC0000, HAS_EXIT_FLAG },
[BINARY_SLICE] = { true, INSTR_FMT_IX, HAS_ERROR_FLAG | HAS_ESCAPES_FLAG },
@ -1340,8 +1345,9 @@ _PyOpcode_macro_expansion[256] = {
[BINARY_OP_SUBSCR_GETITEM] = { .nuops = 4, .uops = { { _CHECK_PEP_523, OPARG_SIMPLE, 5 }, { _BINARY_OP_SUBSCR_CHECK_FUNC, OPARG_SIMPLE, 5 }, { _BINARY_OP_SUBSCR_INIT_CALL, OPARG_SIMPLE, 5 }, { _PUSH_FRAME, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBSCR_LIST_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_LIST, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_LIST_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBSCR_LIST_SLICE] = { .nuops = 3, .uops = { { _GUARD_TOS_SLICE, OPARG_SIMPLE, 0 }, { _GUARD_NOS_LIST, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_LIST_SLICE, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBSCR_STR_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_COMPACT_ASCII, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_STR_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBSCR_STR_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_COMPACT_ASCII, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_STR_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_UNICODE, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBSCR_TUPLE_INT] = { .nuops = 6, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_TUPLE, OPARG_SIMPLE, 0 }, { _GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_TUPLE_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBSCR_USTR_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_UNICODE, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBSCR_USTR_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_UNICODE, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBTRACT_FLOAT] = { .nuops = 5, .uops = { { _GUARD_TOS_FLOAT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_FLOAT, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBTRACT_FLOAT, OPARG_SIMPLE, 5 }, { _POP_TOP_FLOAT, OPARG_SIMPLE, 5 }, { _POP_TOP_FLOAT, OPARG_SIMPLE, 5 } } },
[BINARY_OP_SUBTRACT_INT] = { .nuops = 5, .uops = { { _GUARD_TOS_INT, OPARG_SIMPLE, 0 }, { _GUARD_NOS_INT, OPARG_SIMPLE, 0 }, { _BINARY_OP_SUBTRACT_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 }, { _POP_TOP_INT, OPARG_SIMPLE, 5 } } },
[BINARY_SLICE] = { .nuops = 1, .uops = { { _BINARY_SLICE, OPARG_SIMPLE, 0 } } },
@ -1534,6 +1540,7 @@ const char *_PyOpcode_OpName[267] = {
[BINARY_OP_SUBSCR_LIST_SLICE] = "BINARY_OP_SUBSCR_LIST_SLICE",
[BINARY_OP_SUBSCR_STR_INT] = "BINARY_OP_SUBSCR_STR_INT",
[BINARY_OP_SUBSCR_TUPLE_INT] = "BINARY_OP_SUBSCR_TUPLE_INT",
[BINARY_OP_SUBSCR_USTR_INT] = "BINARY_OP_SUBSCR_USTR_INT",
[BINARY_OP_SUBTRACT_FLOAT] = "BINARY_OP_SUBTRACT_FLOAT",
[BINARY_OP_SUBTRACT_INT] = "BINARY_OP_SUBTRACT_INT",
[BINARY_SLICE] = "BINARY_SLICE",
@ -1794,7 +1801,6 @@ const uint8_t _PyOpcode_Deopt[256] = {
[125] = 125,
[126] = 126,
[127] = 127,
[210] = 210,
[211] = 211,
[212] = 212,
[213] = 213,
@ -1831,6 +1837,7 @@ const uint8_t _PyOpcode_Deopt[256] = {
[BINARY_OP_SUBSCR_LIST_SLICE] = BINARY_OP,
[BINARY_OP_SUBSCR_STR_INT] = BINARY_OP,
[BINARY_OP_SUBSCR_TUPLE_INT] = BINARY_OP,
[BINARY_OP_SUBSCR_USTR_INT] = BINARY_OP,
[BINARY_OP_SUBTRACT_FLOAT] = BINARY_OP,
[BINARY_OP_SUBTRACT_INT] = BINARY_OP,
[BINARY_SLICE] = BINARY_SLICE,
@ -2055,7 +2062,6 @@ const uint8_t _PyOpcode_Deopt[256] = {
case 125: \
case 126: \
case 127: \
case 210: \
case 211: \
case 212: \
case 213: \

File diff suppressed because it is too large Load Diff

View File

@ -121,6 +121,7 @@ const uint32_t _PyUop_Flags[MAX_UOP_ID+1] = {
[_BINARY_OP_SUBSCR_LIST_INT] = HAS_DEOPT_FLAG | HAS_ESCAPES_FLAG,
[_BINARY_OP_SUBSCR_LIST_SLICE] = HAS_ERROR_FLAG | HAS_ESCAPES_FLAG,
[_BINARY_OP_SUBSCR_STR_INT] = HAS_DEOPT_FLAG,
[_BINARY_OP_SUBSCR_USTR_INT] = HAS_DEOPT_FLAG,
[_GUARD_NOS_TUPLE] = HAS_EXIT_FLAG,
[_GUARD_TOS_TUPLE] = HAS_EXIT_FLAG,
[_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS] = HAS_DEOPT_FLAG,
@ -1143,6 +1144,15 @@ const _PyUopCachingInfo _PyUop_Caching[MAX_UOP_ID+1] = {
{ -1, -1, -1 },
},
},
[_BINARY_OP_SUBSCR_USTR_INT] = {
.best = { 2, 2, 2, 2 },
.entries = {
{ -1, -1, -1 },
{ -1, -1, -1 },
{ 3, 2, _BINARY_OP_SUBSCR_USTR_INT_r23 },
{ -1, -1, -1 },
},
},
[_GUARD_NOS_TUPLE] = {
.best = { 0, 1, 2, 3 },
.entries = {
@ -3496,6 +3506,7 @@ const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1] = {
[_BINARY_OP_SUBSCR_LIST_INT_r23] = _BINARY_OP_SUBSCR_LIST_INT,
[_BINARY_OP_SUBSCR_LIST_SLICE_r21] = _BINARY_OP_SUBSCR_LIST_SLICE,
[_BINARY_OP_SUBSCR_STR_INT_r23] = _BINARY_OP_SUBSCR_STR_INT,
[_BINARY_OP_SUBSCR_USTR_INT_r23] = _BINARY_OP_SUBSCR_USTR_INT,
[_GUARD_NOS_TUPLE_r02] = _GUARD_NOS_TUPLE,
[_GUARD_NOS_TUPLE_r12] = _GUARD_NOS_TUPLE,
[_GUARD_NOS_TUPLE_r22] = _GUARD_NOS_TUPLE,
@ -4032,6 +4043,8 @@ const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = {
[_BINARY_OP_SUBSCR_TUPLE_INT_r03] = "_BINARY_OP_SUBSCR_TUPLE_INT_r03",
[_BINARY_OP_SUBSCR_TUPLE_INT_r13] = "_BINARY_OP_SUBSCR_TUPLE_INT_r13",
[_BINARY_OP_SUBSCR_TUPLE_INT_r23] = "_BINARY_OP_SUBSCR_TUPLE_INT_r23",
[_BINARY_OP_SUBSCR_USTR_INT] = "_BINARY_OP_SUBSCR_USTR_INT",
[_BINARY_OP_SUBSCR_USTR_INT_r23] = "_BINARY_OP_SUBSCR_USTR_INT_r23",
[_BINARY_OP_SUBTRACT_FLOAT] = "_BINARY_OP_SUBTRACT_FLOAT",
[_BINARY_OP_SUBTRACT_FLOAT_r03] = "_BINARY_OP_SUBTRACT_FLOAT_r03",
[_BINARY_OP_SUBTRACT_FLOAT_r13] = "_BINARY_OP_SUBTRACT_FLOAT_r13",
@ -5201,6 +5214,8 @@ int _PyUop_num_popped(int opcode, int oparg)
return 2;
case _BINARY_OP_SUBSCR_STR_INT:
return 2;
case _BINARY_OP_SUBSCR_USTR_INT:
return 2;
case _GUARD_NOS_TUPLE:
return 0;
case _GUARD_TOS_TUPLE:

139
Include/opcode_ids.h generated
View File

@ -144,75 +144,76 @@ extern "C" {
#define BINARY_OP_SUBSCR_LIST_SLICE 138
#define BINARY_OP_SUBSCR_STR_INT 139
#define BINARY_OP_SUBSCR_TUPLE_INT 140
#define BINARY_OP_SUBTRACT_FLOAT 141
#define BINARY_OP_SUBTRACT_INT 142
#define CALL_ALLOC_AND_ENTER_INIT 143
#define CALL_BOUND_METHOD_EXACT_ARGS 144
#define CALL_BOUND_METHOD_GENERAL 145
#define CALL_BUILTIN_CLASS 146
#define CALL_BUILTIN_FAST 147
#define CALL_BUILTIN_FAST_WITH_KEYWORDS 148
#define CALL_BUILTIN_O 149
#define CALL_ISINSTANCE 150
#define CALL_KW_BOUND_METHOD 151
#define CALL_KW_NON_PY 152
#define CALL_KW_PY 153
#define CALL_LEN 154
#define CALL_LIST_APPEND 155
#define CALL_METHOD_DESCRIPTOR_FAST 156
#define CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 157
#define CALL_METHOD_DESCRIPTOR_NOARGS 158
#define CALL_METHOD_DESCRIPTOR_O 159
#define CALL_NON_PY_GENERAL 160
#define CALL_PY_EXACT_ARGS 161
#define CALL_PY_GENERAL 162
#define CALL_STR_1 163
#define CALL_TUPLE_1 164
#define CALL_TYPE_1 165
#define COMPARE_OP_FLOAT 166
#define COMPARE_OP_INT 167
#define COMPARE_OP_STR 168
#define CONTAINS_OP_DICT 169
#define CONTAINS_OP_SET 170
#define FOR_ITER_GEN 171
#define FOR_ITER_LIST 172
#define FOR_ITER_RANGE 173
#define FOR_ITER_TUPLE 174
#define JUMP_BACKWARD_JIT 175
#define JUMP_BACKWARD_NO_JIT 176
#define LOAD_ATTR_CLASS 177
#define LOAD_ATTR_CLASS_WITH_METACLASS_CHECK 178
#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 179
#define LOAD_ATTR_INSTANCE_VALUE 180
#define LOAD_ATTR_METHOD_LAZY_DICT 181
#define LOAD_ATTR_METHOD_NO_DICT 182
#define LOAD_ATTR_METHOD_WITH_VALUES 183
#define LOAD_ATTR_MODULE 184
#define LOAD_ATTR_NONDESCRIPTOR_NO_DICT 185
#define LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 186
#define LOAD_ATTR_PROPERTY 187
#define LOAD_ATTR_SLOT 188
#define LOAD_ATTR_WITH_HINT 189
#define LOAD_GLOBAL_BUILTIN 190
#define LOAD_GLOBAL_MODULE 191
#define LOAD_SUPER_ATTR_ATTR 192
#define LOAD_SUPER_ATTR_METHOD 193
#define RESUME_CHECK 194
#define SEND_GEN 195
#define STORE_ATTR_INSTANCE_VALUE 196
#define STORE_ATTR_SLOT 197
#define STORE_ATTR_WITH_HINT 198
#define STORE_SUBSCR_DICT 199
#define STORE_SUBSCR_LIST_INT 200
#define TO_BOOL_ALWAYS_TRUE 201
#define TO_BOOL_BOOL 202
#define TO_BOOL_INT 203
#define TO_BOOL_LIST 204
#define TO_BOOL_NONE 205
#define TO_BOOL_STR 206
#define UNPACK_SEQUENCE_LIST 207
#define UNPACK_SEQUENCE_TUPLE 208
#define UNPACK_SEQUENCE_TWO_TUPLE 209
#define BINARY_OP_SUBSCR_USTR_INT 141
#define BINARY_OP_SUBTRACT_FLOAT 142
#define BINARY_OP_SUBTRACT_INT 143
#define CALL_ALLOC_AND_ENTER_INIT 144
#define CALL_BOUND_METHOD_EXACT_ARGS 145
#define CALL_BOUND_METHOD_GENERAL 146
#define CALL_BUILTIN_CLASS 147
#define CALL_BUILTIN_FAST 148
#define CALL_BUILTIN_FAST_WITH_KEYWORDS 149
#define CALL_BUILTIN_O 150
#define CALL_ISINSTANCE 151
#define CALL_KW_BOUND_METHOD 152
#define CALL_KW_NON_PY 153
#define CALL_KW_PY 154
#define CALL_LEN 155
#define CALL_LIST_APPEND 156
#define CALL_METHOD_DESCRIPTOR_FAST 157
#define CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS 158
#define CALL_METHOD_DESCRIPTOR_NOARGS 159
#define CALL_METHOD_DESCRIPTOR_O 160
#define CALL_NON_PY_GENERAL 161
#define CALL_PY_EXACT_ARGS 162
#define CALL_PY_GENERAL 163
#define CALL_STR_1 164
#define CALL_TUPLE_1 165
#define CALL_TYPE_1 166
#define COMPARE_OP_FLOAT 167
#define COMPARE_OP_INT 168
#define COMPARE_OP_STR 169
#define CONTAINS_OP_DICT 170
#define CONTAINS_OP_SET 171
#define FOR_ITER_GEN 172
#define FOR_ITER_LIST 173
#define FOR_ITER_RANGE 174
#define FOR_ITER_TUPLE 175
#define JUMP_BACKWARD_JIT 176
#define JUMP_BACKWARD_NO_JIT 177
#define LOAD_ATTR_CLASS 178
#define LOAD_ATTR_CLASS_WITH_METACLASS_CHECK 179
#define LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN 180
#define LOAD_ATTR_INSTANCE_VALUE 181
#define LOAD_ATTR_METHOD_LAZY_DICT 182
#define LOAD_ATTR_METHOD_NO_DICT 183
#define LOAD_ATTR_METHOD_WITH_VALUES 184
#define LOAD_ATTR_MODULE 185
#define LOAD_ATTR_NONDESCRIPTOR_NO_DICT 186
#define LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 187
#define LOAD_ATTR_PROPERTY 188
#define LOAD_ATTR_SLOT 189
#define LOAD_ATTR_WITH_HINT 190
#define LOAD_GLOBAL_BUILTIN 191
#define LOAD_GLOBAL_MODULE 192
#define LOAD_SUPER_ATTR_ATTR 193
#define LOAD_SUPER_ATTR_METHOD 194
#define RESUME_CHECK 195
#define SEND_GEN 196
#define STORE_ATTR_INSTANCE_VALUE 197
#define STORE_ATTR_SLOT 198
#define STORE_ATTR_WITH_HINT 199
#define STORE_SUBSCR_DICT 200
#define STORE_SUBSCR_LIST_INT 201
#define TO_BOOL_ALWAYS_TRUE 202
#define TO_BOOL_BOOL 203
#define TO_BOOL_INT 204
#define TO_BOOL_LIST 205
#define TO_BOOL_NONE 206
#define TO_BOOL_STR 207
#define UNPACK_SEQUENCE_LIST 208
#define UNPACK_SEQUENCE_TUPLE 209
#define UNPACK_SEQUENCE_TWO_TUPLE 210
#define INSTRUMENTED_END_FOR 233
#define INSTRUMENTED_POP_ITER 234
#define INSTRUMENTED_END_SEND 235

140
Lib/_opcode_metadata.py generated
View File

@ -26,6 +26,7 @@ _specializations = {
"BINARY_OP_SUBSCR_LIST_SLICE",
"BINARY_OP_SUBSCR_TUPLE_INT",
"BINARY_OP_SUBSCR_STR_INT",
"BINARY_OP_SUBSCR_USTR_INT",
"BINARY_OP_SUBSCR_DICT",
"BINARY_OP_SUBSCR_GETITEM",
"BINARY_OP_INPLACE_ADD_UNICODE",
@ -135,75 +136,76 @@ _specialized_opmap = {
'BINARY_OP_SUBSCR_LIST_SLICE': 138,
'BINARY_OP_SUBSCR_STR_INT': 139,
'BINARY_OP_SUBSCR_TUPLE_INT': 140,
'BINARY_OP_SUBTRACT_FLOAT': 141,
'BINARY_OP_SUBTRACT_INT': 142,
'CALL_ALLOC_AND_ENTER_INIT': 143,
'CALL_BOUND_METHOD_EXACT_ARGS': 144,
'CALL_BOUND_METHOD_GENERAL': 145,
'CALL_BUILTIN_CLASS': 146,
'CALL_BUILTIN_FAST': 147,
'CALL_BUILTIN_FAST_WITH_KEYWORDS': 148,
'CALL_BUILTIN_O': 149,
'CALL_ISINSTANCE': 150,
'CALL_KW_BOUND_METHOD': 151,
'CALL_KW_NON_PY': 152,
'CALL_KW_PY': 153,
'CALL_LEN': 154,
'CALL_LIST_APPEND': 155,
'CALL_METHOD_DESCRIPTOR_FAST': 156,
'CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS': 157,
'CALL_METHOD_DESCRIPTOR_NOARGS': 158,
'CALL_METHOD_DESCRIPTOR_O': 159,
'CALL_NON_PY_GENERAL': 160,
'CALL_PY_EXACT_ARGS': 161,
'CALL_PY_GENERAL': 162,
'CALL_STR_1': 163,
'CALL_TUPLE_1': 164,
'CALL_TYPE_1': 165,
'COMPARE_OP_FLOAT': 166,
'COMPARE_OP_INT': 167,
'COMPARE_OP_STR': 168,
'CONTAINS_OP_DICT': 169,
'CONTAINS_OP_SET': 170,
'FOR_ITER_GEN': 171,
'FOR_ITER_LIST': 172,
'FOR_ITER_RANGE': 173,
'FOR_ITER_TUPLE': 174,
'JUMP_BACKWARD_JIT': 175,
'JUMP_BACKWARD_NO_JIT': 176,
'LOAD_ATTR_CLASS': 177,
'LOAD_ATTR_CLASS_WITH_METACLASS_CHECK': 178,
'LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN': 179,
'LOAD_ATTR_INSTANCE_VALUE': 180,
'LOAD_ATTR_METHOD_LAZY_DICT': 181,
'LOAD_ATTR_METHOD_NO_DICT': 182,
'LOAD_ATTR_METHOD_WITH_VALUES': 183,
'LOAD_ATTR_MODULE': 184,
'LOAD_ATTR_NONDESCRIPTOR_NO_DICT': 185,
'LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES': 186,
'LOAD_ATTR_PROPERTY': 187,
'LOAD_ATTR_SLOT': 188,
'LOAD_ATTR_WITH_HINT': 189,
'LOAD_GLOBAL_BUILTIN': 190,
'LOAD_GLOBAL_MODULE': 191,
'LOAD_SUPER_ATTR_ATTR': 192,
'LOAD_SUPER_ATTR_METHOD': 193,
'RESUME_CHECK': 194,
'SEND_GEN': 195,
'STORE_ATTR_INSTANCE_VALUE': 196,
'STORE_ATTR_SLOT': 197,
'STORE_ATTR_WITH_HINT': 198,
'STORE_SUBSCR_DICT': 199,
'STORE_SUBSCR_LIST_INT': 200,
'TO_BOOL_ALWAYS_TRUE': 201,
'TO_BOOL_BOOL': 202,
'TO_BOOL_INT': 203,
'TO_BOOL_LIST': 204,
'TO_BOOL_NONE': 205,
'TO_BOOL_STR': 206,
'UNPACK_SEQUENCE_LIST': 207,
'UNPACK_SEQUENCE_TUPLE': 208,
'UNPACK_SEQUENCE_TWO_TUPLE': 209,
'BINARY_OP_SUBSCR_USTR_INT': 141,
'BINARY_OP_SUBTRACT_FLOAT': 142,
'BINARY_OP_SUBTRACT_INT': 143,
'CALL_ALLOC_AND_ENTER_INIT': 144,
'CALL_BOUND_METHOD_EXACT_ARGS': 145,
'CALL_BOUND_METHOD_GENERAL': 146,
'CALL_BUILTIN_CLASS': 147,
'CALL_BUILTIN_FAST': 148,
'CALL_BUILTIN_FAST_WITH_KEYWORDS': 149,
'CALL_BUILTIN_O': 150,
'CALL_ISINSTANCE': 151,
'CALL_KW_BOUND_METHOD': 152,
'CALL_KW_NON_PY': 153,
'CALL_KW_PY': 154,
'CALL_LEN': 155,
'CALL_LIST_APPEND': 156,
'CALL_METHOD_DESCRIPTOR_FAST': 157,
'CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS': 158,
'CALL_METHOD_DESCRIPTOR_NOARGS': 159,
'CALL_METHOD_DESCRIPTOR_O': 160,
'CALL_NON_PY_GENERAL': 161,
'CALL_PY_EXACT_ARGS': 162,
'CALL_PY_GENERAL': 163,
'CALL_STR_1': 164,
'CALL_TUPLE_1': 165,
'CALL_TYPE_1': 166,
'COMPARE_OP_FLOAT': 167,
'COMPARE_OP_INT': 168,
'COMPARE_OP_STR': 169,
'CONTAINS_OP_DICT': 170,
'CONTAINS_OP_SET': 171,
'FOR_ITER_GEN': 172,
'FOR_ITER_LIST': 173,
'FOR_ITER_RANGE': 174,
'FOR_ITER_TUPLE': 175,
'JUMP_BACKWARD_JIT': 176,
'JUMP_BACKWARD_NO_JIT': 177,
'LOAD_ATTR_CLASS': 178,
'LOAD_ATTR_CLASS_WITH_METACLASS_CHECK': 179,
'LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN': 180,
'LOAD_ATTR_INSTANCE_VALUE': 181,
'LOAD_ATTR_METHOD_LAZY_DICT': 182,
'LOAD_ATTR_METHOD_NO_DICT': 183,
'LOAD_ATTR_METHOD_WITH_VALUES': 184,
'LOAD_ATTR_MODULE': 185,
'LOAD_ATTR_NONDESCRIPTOR_NO_DICT': 186,
'LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES': 187,
'LOAD_ATTR_PROPERTY': 188,
'LOAD_ATTR_SLOT': 189,
'LOAD_ATTR_WITH_HINT': 190,
'LOAD_GLOBAL_BUILTIN': 191,
'LOAD_GLOBAL_MODULE': 192,
'LOAD_SUPER_ATTR_ATTR': 193,
'LOAD_SUPER_ATTR_METHOD': 194,
'RESUME_CHECK': 195,
'SEND_GEN': 196,
'STORE_ATTR_INSTANCE_VALUE': 197,
'STORE_ATTR_SLOT': 198,
'STORE_ATTR_WITH_HINT': 199,
'STORE_SUBSCR_DICT': 200,
'STORE_SUBSCR_LIST_INT': 201,
'TO_BOOL_ALWAYS_TRUE': 202,
'TO_BOOL_BOOL': 203,
'TO_BOOL_INT': 204,
'TO_BOOL_LIST': 205,
'TO_BOOL_NONE': 206,
'TO_BOOL_STR': 207,
'UNPACK_SEQUENCE_LIST': 208,
'UNPACK_SEQUENCE_TUPLE': 209,
'UNPACK_SEQUENCE_TWO_TUPLE': 210,
}
opmap = {

View File

@ -1904,6 +1904,26 @@ class TestUopsOptimization(unittest.TestCase):
self.assertNotIn("_GUARD_TOS_UNICODE", uops)
self.assertIn("_BINARY_OP_ADD_UNICODE", uops)
def test_binary_subcsr_ustr_int_narrows_to_str(self):
def testfunc(n):
x = []
s = "바이트코f드_특수화"
for _ in range(n):
y = s[4] # _BINARY_OP_SUBSCR_USTR_INT
z = "bar" + y # (_GUARD_TOS_UNICODE) + _BINARY_OP_ADD_UNICODE
x.append(z)
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, ["barf"] * TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_BINARY_OP_SUBSCR_USTR_INT", uops)
# _BINARY_OP_SUBSCR_USTR_INT narrows the result to 'str' so
# the unicode guard before _BINARY_OP_ADD_UNICODE is removed.
self.assertNotIn("_GUARD_TOS_UNICODE", uops)
self.assertIn("_BINARY_OP_ADD_UNICODE", uops)
def test_binary_op_subscr_str_int(self):
def testfunc(n):
x = 0
@ -1924,6 +1944,26 @@ class TestUopsOptimization(unittest.TestCase):
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
def test_binary_op_subscr_ustr_int(self):
def testfunc(n):
x = 0
s = "hello바"
for _ in range(n):
c = s[1] # _BINARY_OP_SUBSCR_USTR_INT
if c == 'e':
x += 1
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_BINARY_OP_SUBSCR_USTR_INT", uops)
self.assertIn("_COMPARE_OP_STR", uops)
self.assertIn("_POP_TOP_NOP", uops)
self.assertLessEqual(count_ops(ex, "_POP_TOP"), 2)
self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1)
def test_call_type_1_guards_removed(self):
def testfunc(n):
x = 0

View File

@ -1792,6 +1792,7 @@ class TestSpecializer(TestBase):
self.assertEqual(a[idx], expected)
binary_subscr_str_int_non_compact()
self.assert_specialized(binary_subscr_str_int_non_compact, "BINARY_OP_SUBSCR_USTR_INT")
self.assert_no_opcode(binary_subscr_str_int_non_compact, "BINARY_OP_SUBSCR_STR_INT")
def binary_subscr_getitems():

View File

@ -0,0 +1,2 @@
Add ``BINARY_OP_SUBSCR_USTR_INT`` to specialize reading an ASCII character
from any string. Patch by Chris Eibl.

View File

@ -594,6 +594,7 @@ dummy_func(
BINARY_OP_SUBSCR_LIST_SLICE,
BINARY_OP_SUBSCR_TUPLE_INT,
BINARY_OP_SUBSCR_STR_INT,
BINARY_OP_SUBSCR_USTR_INT,
BINARY_OP_SUBSCR_DICT,
BINARY_OP_SUBSCR_GETITEM,
BINARY_OP_INPLACE_ADD_UNICODE,
@ -945,7 +946,7 @@ dummy_func(
}
macro(BINARY_OP_SUBSCR_STR_INT) =
_GUARD_TOS_INT + _GUARD_NOS_COMPACT_ASCII + unused/5 + _BINARY_OP_SUBSCR_STR_INT + _POP_TOP_INT + POP_TOP;
_GUARD_TOS_INT + _GUARD_NOS_COMPACT_ASCII + unused/5 + _BINARY_OP_SUBSCR_STR_INT + _POP_TOP_INT + _POP_TOP_UNICODE;
op(_BINARY_OP_SUBSCR_STR_INT, (str_st, sub_st -- res, s, i)) {
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
@ -953,16 +954,39 @@ dummy_func(
assert(PyLong_CheckExact(sub));
assert(PyUnicode_CheckExact(str));
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject*)sub));
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(PyUnicode_GET_LENGTH(str) <= index);
uint8_t c = PyUnicode_1BYTE_DATA(str)[index];
assert(c < 128);
STAT_INC(BINARY_OP, hit);
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
INPUTS_DEAD();
s = str_st;
i = sub_st;
INPUTS_DEAD();
res = PyStackRef_FromPyObjectBorrow(res_o);
}
macro(BINARY_OP_SUBSCR_USTR_INT) =
_GUARD_TOS_INT + _GUARD_NOS_UNICODE + unused/5 + _BINARY_OP_SUBSCR_USTR_INT + _POP_TOP_INT + _POP_TOP_UNICODE;
op(_BINARY_OP_SUBSCR_USTR_INT, (str_st, sub_st -- res, s, i)) {
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
assert(PyLong_CheckExact(sub));
assert(PyUnicode_CheckExact(str));
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject*)sub));
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(PyUnicode_GET_LENGTH(str) <= index);
// Specialize for reading an ASCII character from any string:
Py_UCS4 c = PyUnicode_READ_CHAR(str, index);
DEOPT_IF(Py_ARRAY_LENGTH(_Py_SINGLETON(strings).ascii) <= c);
STAT_INC(BINARY_OP, hit);
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
s = str_st;
i = sub_st;
INPUTS_DEAD();
res = PyStackRef_FromPyObjectBorrow(res_o);
}

View File

@ -5306,7 +5306,7 @@
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
assert(PyLong_CheckExact(sub));
assert(PyUnicode_CheckExact(str));
if (!_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
if (!_PyLong_IsNonNegativeCompact((PyLongObject*)sub)) {
UOP_STAT_INC(uopcode, miss);
_tos_cache1 = sub_st;
_tos_cache0 = str_st;
@ -5336,6 +5336,58 @@
break;
}
case _BINARY_OP_SUBSCR_USTR_INT_r23: {
CHECK_CURRENT_CACHED_VALUES(2);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
_PyStackRef sub_st;
_PyStackRef str_st;
_PyStackRef res;
_PyStackRef s;
_PyStackRef i;
_PyStackRef _stack_item_0 = _tos_cache0;
_PyStackRef _stack_item_1 = _tos_cache1;
sub_st = _stack_item_1;
str_st = _stack_item_0;
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
assert(PyLong_CheckExact(sub));
assert(PyUnicode_CheckExact(str));
if (!_PyLong_IsNonNegativeCompact((PyLongObject*)sub)) {
UOP_STAT_INC(uopcode, miss);
_tos_cache1 = sub_st;
_tos_cache0 = str_st;
SET_CURRENT_CACHED_VALUES(2);
JUMP_TO_JUMP_TARGET();
}
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
if (PyUnicode_GET_LENGTH(str) <= index) {
UOP_STAT_INC(uopcode, miss);
_tos_cache1 = sub_st;
_tos_cache0 = str_st;
SET_CURRENT_CACHED_VALUES(2);
JUMP_TO_JUMP_TARGET();
}
Py_UCS4 c = PyUnicode_READ_CHAR(str, index);
if (Py_ARRAY_LENGTH(_Py_SINGLETON(strings).ascii) <= c) {
UOP_STAT_INC(uopcode, miss);
_tos_cache1 = sub_st;
_tos_cache0 = str_st;
SET_CURRENT_CACHED_VALUES(2);
JUMP_TO_JUMP_TARGET();
}
STAT_INC(BINARY_OP, hit);
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
s = str_st;
i = sub_st;
res = PyStackRef_FromPyObjectBorrow(res_o);
_tos_cache2 = i;
_tos_cache1 = s;
_tos_cache0 = res;
SET_CURRENT_CACHED_VALUES(3);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());
break;
}
case _GUARD_NOS_TUPLE_r02: {
CHECK_CURRENT_CACHED_VALUES(0);
assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());

View File

@ -968,7 +968,7 @@
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
assert(PyLong_CheckExact(sub));
assert(PyUnicode_CheckExact(str));
if (!_PyLong_IsNonNegativeCompact((PyLongObject *)sub)) {
if (!_PyLong_IsNonNegativeCompact((PyLongObject*)sub)) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
@ -993,16 +993,15 @@
assert(PyLong_CheckExact(PyStackRef_AsPyObjectBorrow(value)));
PyStackRef_CLOSE_SPECIALIZED(value, _PyLong_ExactDealloc);
}
// _POP_TOP
// _POP_TOP_UNICODE
{
value = s;
stack_pointer[-2] = res;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
_PyFrame_SetStackPointer(frame, stack_pointer);
PyStackRef_XCLOSE(value);
stack_pointer = _PyFrame_GetStackPointer(frame);
assert(PyUnicode_CheckExact(PyStackRef_AsPyObjectBorrow(value)));
PyStackRef_CLOSE_SPECIALIZED(value, _PyUnicode_ExactDealloc);
}
stack_pointer[-2] = res;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
DISPATCH();
}
@ -1098,6 +1097,94 @@
DISPATCH();
}
TARGET(BINARY_OP_SUBSCR_USTR_INT) {
#if _Py_TAIL_CALL_INTERP
int opcode = BINARY_OP_SUBSCR_USTR_INT;
(void)(opcode);
#endif
_Py_CODEUNIT* const this_instr = next_instr;
(void)this_instr;
frame->instr_ptr = next_instr;
next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_SUBSCR_USTR_INT);
static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef value;
_PyStackRef nos;
_PyStackRef str_st;
_PyStackRef sub_st;
_PyStackRef res;
_PyStackRef s;
_PyStackRef i;
// _GUARD_TOS_INT
{
value = stack_pointer[-1];
PyObject *value_o = PyStackRef_AsPyObjectBorrow(value);
if (!_PyLong_CheckExactAndCompact(value_o)) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
}
}
// _GUARD_NOS_UNICODE
{
nos = stack_pointer[-2];
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
if (!PyUnicode_CheckExact(o)) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
}
}
/* Skip 5 cache entries */
// _BINARY_OP_SUBSCR_USTR_INT
{
sub_st = value;
str_st = nos;
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
assert(PyLong_CheckExact(sub));
assert(PyUnicode_CheckExact(str));
if (!_PyLong_IsNonNegativeCompact((PyLongObject*)sub)) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
}
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
if (PyUnicode_GET_LENGTH(str) <= index) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
}
Py_UCS4 c = PyUnicode_READ_CHAR(str, index);
if (Py_ARRAY_LENGTH(_Py_SINGLETON(strings).ascii) <= c) {
UPDATE_MISS_STATS(BINARY_OP);
assert(_PyOpcode_Deopt[opcode] == (BINARY_OP));
JUMP_TO_PREDICTED(BINARY_OP);
}
STAT_INC(BINARY_OP, hit);
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
s = str_st;
i = sub_st;
res = PyStackRef_FromPyObjectBorrow(res_o);
}
// _POP_TOP_INT
{
value = i;
assert(PyLong_CheckExact(PyStackRef_AsPyObjectBorrow(value)));
PyStackRef_CLOSE_SPECIALIZED(value, _PyLong_ExactDealloc);
}
// _POP_TOP_UNICODE
{
value = s;
assert(PyUnicode_CheckExact(PyStackRef_AsPyObjectBorrow(value)));
PyStackRef_CLOSE_SPECIALIZED(value, _PyUnicode_ExactDealloc);
}
stack_pointer[-2] = res;
stack_pointer += -1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
DISPATCH();
}
TARGET(BINARY_OP_SUBTRACT_FLOAT) {
#if _Py_TAIL_CALL_INTERP
int opcode = BINARY_OP_SUBTRACT_FLOAT;

View File

@ -141,6 +141,7 @@ static void *opcode_targets_table[256] = {
&&TARGET_BINARY_OP_SUBSCR_LIST_SLICE,
&&TARGET_BINARY_OP_SUBSCR_STR_INT,
&&TARGET_BINARY_OP_SUBSCR_TUPLE_INT,
&&TARGET_BINARY_OP_SUBSCR_USTR_INT,
&&TARGET_BINARY_OP_SUBTRACT_FLOAT,
&&TARGET_BINARY_OP_SUBTRACT_INT,
&&TARGET_CALL_ALLOC_AND_ENTER_INIT,
@ -232,7 +233,6 @@ static void *opcode_targets_table[256] = {
&&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
&&TARGET_INSTRUMENTED_END_FOR,
&&TARGET_INSTRUMENTED_POP_ITER,
&&TARGET_INSTRUMENTED_END_SEND,
@ -469,7 +469,7 @@ static void *opcode_tracing_targets_table[256] = {
&&TARGET_TRACE_RECORD,
&&TARGET_TRACE_RECORD,
&&TARGET_TRACE_RECORD,
&&_unknown_opcode,
&&TARGET_TRACE_RECORD,
&&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
@ -544,6 +544,7 @@ static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBSCR_LIST_INT(TAIL_C
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBSCR_LIST_SLICE(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBSCR_STR_INT(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBSCR_TUPLE_INT(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBSCR_USTR_INT(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBTRACT_FLOAT(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_OP_SUBTRACT_INT(TAIL_CALL_PARAMS);
static PyObject *Py_PRESERVE_NONE_CC _TAIL_CALL_BINARY_SLICE(TAIL_CALL_PARAMS);
@ -782,6 +783,7 @@ static py_tail_call_funcptr instruction_funcptr_handler_table[256] = {
[BINARY_OP_SUBSCR_LIST_SLICE] = _TAIL_CALL_BINARY_OP_SUBSCR_LIST_SLICE,
[BINARY_OP_SUBSCR_STR_INT] = _TAIL_CALL_BINARY_OP_SUBSCR_STR_INT,
[BINARY_OP_SUBSCR_TUPLE_INT] = _TAIL_CALL_BINARY_OP_SUBSCR_TUPLE_INT,
[BINARY_OP_SUBSCR_USTR_INT] = _TAIL_CALL_BINARY_OP_SUBSCR_USTR_INT,
[BINARY_OP_SUBTRACT_FLOAT] = _TAIL_CALL_BINARY_OP_SUBTRACT_FLOAT,
[BINARY_OP_SUBTRACT_INT] = _TAIL_CALL_BINARY_OP_SUBTRACT_INT,
[BINARY_SLICE] = _TAIL_CALL_BINARY_SLICE,
@ -1001,7 +1003,6 @@ static py_tail_call_funcptr instruction_funcptr_handler_table[256] = {
[125] = _TAIL_CALL_UNKNOWN_OPCODE,
[126] = _TAIL_CALL_UNKNOWN_OPCODE,
[127] = _TAIL_CALL_UNKNOWN_OPCODE,
[210] = _TAIL_CALL_UNKNOWN_OPCODE,
[211] = _TAIL_CALL_UNKNOWN_OPCODE,
[212] = _TAIL_CALL_UNKNOWN_OPCODE,
[213] = _TAIL_CALL_UNKNOWN_OPCODE,
@ -1040,6 +1041,7 @@ static py_tail_call_funcptr instruction_funcptr_tracing_table[256] = {
[BINARY_OP_SUBSCR_LIST_SLICE] = _TAIL_CALL_TRACE_RECORD,
[BINARY_OP_SUBSCR_STR_INT] = _TAIL_CALL_TRACE_RECORD,
[BINARY_OP_SUBSCR_TUPLE_INT] = _TAIL_CALL_TRACE_RECORD,
[BINARY_OP_SUBSCR_USTR_INT] = _TAIL_CALL_TRACE_RECORD,
[BINARY_OP_SUBTRACT_FLOAT] = _TAIL_CALL_TRACE_RECORD,
[BINARY_OP_SUBTRACT_INT] = _TAIL_CALL_TRACE_RECORD,
[BINARY_SLICE] = _TAIL_CALL_TRACE_RECORD,
@ -1259,7 +1261,6 @@ static py_tail_call_funcptr instruction_funcptr_tracing_table[256] = {
[125] = _TAIL_CALL_UNKNOWN_OPCODE,
[126] = _TAIL_CALL_UNKNOWN_OPCODE,
[127] = _TAIL_CALL_UNKNOWN_OPCODE,
[210] = _TAIL_CALL_UNKNOWN_OPCODE,
[211] = _TAIL_CALL_UNKNOWN_OPCODE,
[212] = _TAIL_CALL_UNKNOWN_OPCODE,
[213] = _TAIL_CALL_UNKNOWN_OPCODE,

View File

@ -334,6 +334,12 @@ dummy_func(void) {
i = sub_st;
}
op(_BINARY_OP_SUBSCR_USTR_INT, (str_st, sub_st -- res, s, i)) {
res = sym_new_type(ctx, &PyUnicode_Type);
s = str_st;
i = sub_st;
}
op(_GUARD_BINARY_OP_SUBSCR_TUPLE_INT_BOUNDS, (tuple_st, sub_st -- tuple_st, sub_st)) {
assert(sym_matches_type(tuple_st, &PyTuple_Type));
if (sym_is_const(ctx, sub_st)) {

View File

@ -787,6 +787,26 @@
break;
}
case _BINARY_OP_SUBSCR_USTR_INT: {
JitOptRef sub_st;
JitOptRef str_st;
JitOptRef res;
JitOptRef s;
JitOptRef i;
sub_st = stack_pointer[-1];
str_st = stack_pointer[-2];
res = sym_new_type(ctx, &PyUnicode_Type);
s = str_st;
i = sub_st;
CHECK_STACK_BOUNDS(1);
stack_pointer[-2] = res;
stack_pointer[-1] = s;
stack_pointer[0] = i;
stack_pointer += 1;
ASSERT_WITHIN_STACK_BOUNDS(__FILE__, __LINE__);
break;
}
case _GUARD_NOS_TUPLE: {
JitOptRef nos;
nos = stack_pointer[-2];

View File

@ -2242,9 +2242,14 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
specialize(instr, BINARY_OP_SUBSCR_TUPLE_INT);
return;
}
if (PyUnicode_CheckExact(lhs) && PyUnicode_IS_COMPACT_ASCII(lhs)) {
specialize(instr, BINARY_OP_SUBSCR_STR_INT);
return;
if (PyUnicode_CheckExact(lhs) && _PyLong_IsNonNegativeCompact((PyLongObject*)rhs)) {
if (PyUnicode_IS_COMPACT_ASCII(lhs)) {
specialize(instr, BINARY_OP_SUBSCR_STR_INT);
return;
} else {
specialize(instr, BINARY_OP_SUBSCR_USTR_INT);
return;
}
}
}
if (PyDict_CheckExact(lhs)) {