mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-100239: replace BINARY_SUBSCR & family by BINARY_OP with oparg NB_SUBSCR (#129700)
This commit is contained in:
parent
2248a9c153
commit
a1417b211f
30 changed files with 1281 additions and 1447 deletions
|
@ -537,6 +537,11 @@ dummy_func(
|
|||
BINARY_OP_ADD_FLOAT,
|
||||
BINARY_OP_SUBTRACT_FLOAT,
|
||||
BINARY_OP_ADD_UNICODE,
|
||||
BINARY_OP_SUBSCR_LIST_INT,
|
||||
BINARY_OP_SUBSCR_TUPLE_INT,
|
||||
BINARY_OP_SUBSCR_STR_INT,
|
||||
BINARY_OP_SUBSCR_DICT,
|
||||
BINARY_OP_SUBSCR_GETITEM,
|
||||
// BINARY_OP_INPLACE_ADD_UNICODE, // See comments at that opcode.
|
||||
BINARY_OP_EXTEND,
|
||||
};
|
||||
|
@ -787,39 +792,6 @@ dummy_func(
|
|||
macro(BINARY_OP_INPLACE_ADD_UNICODE) =
|
||||
_GUARD_BOTH_UNICODE + unused/5 + _BINARY_OP_INPLACE_ADD_UNICODE;
|
||||
|
||||
family(BINARY_SUBSCR, INLINE_CACHE_ENTRIES_BINARY_SUBSCR) = {
|
||||
BINARY_SUBSCR_DICT,
|
||||
BINARY_SUBSCR_GETITEM,
|
||||
BINARY_SUBSCR_LIST_INT,
|
||||
BINARY_SUBSCR_STR_INT,
|
||||
BINARY_SUBSCR_TUPLE_INT,
|
||||
};
|
||||
|
||||
specializing op(_SPECIALIZE_BINARY_SUBSCR, (counter/1, container, sub -- container, sub)) {
|
||||
#if ENABLE_SPECIALIZATION_FT
|
||||
assert(frame->stackpointer == NULL);
|
||||
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
|
||||
next_instr = this_instr;
|
||||
_Py_Specialize_BinarySubscr(container, sub, next_instr);
|
||||
DISPATCH_SAME_OPARG();
|
||||
}
|
||||
OPCODE_DEFERRED_INC(BINARY_SUBSCR);
|
||||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
|
||||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
|
||||
op(_BINARY_SUBSCR, (container, sub -- res)) {
|
||||
PyObject *container_o = PyStackRef_AsPyObjectBorrow(container);
|
||||
PyObject *sub_o = PyStackRef_AsPyObjectBorrow(sub);
|
||||
|
||||
PyObject *res_o = PyObject_GetItem(container_o, sub_o);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res_o == NULL, error);
|
||||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
macro(BINARY_SUBSCR) = _SPECIALIZE_BINARY_SUBSCR + _BINARY_SUBSCR;
|
||||
|
||||
specializing op(_SPECIALIZE_BINARY_SLICE, (container, start, stop -- container, start, stop)) {
|
||||
// Placeholder until we implement BINARY_SLICE specialization
|
||||
#if ENABLE_SPECIALIZATION
|
||||
|
@ -871,7 +843,7 @@ dummy_func(
|
|||
|
||||
macro(STORE_SLICE) = _SPECIALIZE_STORE_SLICE + _STORE_SLICE;
|
||||
|
||||
inst(BINARY_SUBSCR_LIST_INT, (unused/1, list_st, sub_st -- res)) {
|
||||
inst(BINARY_OP_SUBSCR_LIST_INT, (unused/5, list_st, sub_st -- res)) {
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *list = PyStackRef_AsPyObjectBorrow(list_st);
|
||||
|
||||
|
@ -884,10 +856,10 @@ dummy_func(
|
|||
#ifdef Py_GIL_DISABLED
|
||||
PyObject *res_o = _PyList_GetItemRef((PyListObject*)list, index);
|
||||
DEOPT_IF(res_o == NULL);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
#else
|
||||
DEOPT_IF(index >= PyList_GET_SIZE(list));
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *res_o = PyList_GET_ITEM(list, index);
|
||||
assert(res_o != NULL);
|
||||
Py_INCREF(res_o);
|
||||
|
@ -898,7 +870,7 @@ dummy_func(
|
|||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
inst(BINARY_SUBSCR_STR_INT, (unused/1, str_st, sub_st -- res)) {
|
||||
inst(BINARY_OP_SUBSCR_STR_INT, (unused/5, str_st, sub_st -- res)) {
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *str = PyStackRef_AsPyObjectBorrow(str_st);
|
||||
|
||||
|
@ -910,7 +882,7 @@ dummy_func(
|
|||
// 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_SUBSCR, hit);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *res_o = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
|
||||
PyStackRef_CLOSE_SPECIALIZED(sub_st, _PyLong_ExactDealloc);
|
||||
DEAD(sub_st);
|
||||
|
@ -918,7 +890,7 @@ dummy_func(
|
|||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
inst(BINARY_SUBSCR_TUPLE_INT, (unused/1, tuple_st, sub_st -- res)) {
|
||||
inst(BINARY_OP_SUBSCR_TUPLE_INT, (unused/5, tuple_st, sub_st -- res)) {
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *tuple = PyStackRef_AsPyObjectBorrow(tuple_st);
|
||||
|
||||
|
@ -929,7 +901,7 @@ dummy_func(
|
|||
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple));
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *res_o = PyTuple_GET_ITEM(tuple, index);
|
||||
assert(res_o != NULL);
|
||||
Py_INCREF(res_o);
|
||||
|
@ -939,12 +911,12 @@ dummy_func(
|
|||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
inst(BINARY_SUBSCR_DICT, (unused/1, dict_st, sub_st -- res)) {
|
||||
inst(BINARY_OP_SUBSCR_DICT, (unused/5, dict_st, sub_st -- res)) {
|
||||
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
|
||||
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);
|
||||
|
||||
DEOPT_IF(!PyDict_CheckExact(dict));
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
PyObject *res_o;
|
||||
int rc = PyDict_GetItemRef(dict, sub, &res_o);
|
||||
if (rc == 0) {
|
||||
|
@ -955,7 +927,7 @@ dummy_func(
|
|||
res = PyStackRef_FromPyObjectSteal(res_o);
|
||||
}
|
||||
|
||||
op(_BINARY_SUBSCR_CHECK_FUNC, (container, unused -- container, unused, getitem)) {
|
||||
op(_BINARY_OP_SUBSCR_CHECK_FUNC, (container, unused -- container, unused, getitem)) {
|
||||
PyTypeObject *tp = Py_TYPE(PyStackRef_AsPyObjectBorrow(container));
|
||||
DEOPT_IF(!PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE));
|
||||
PyHeapTypeObject *ht = (PyHeapTypeObject *)tp;
|
||||
|
@ -968,10 +940,10 @@ dummy_func(
|
|||
assert(code->co_argcount == 2);
|
||||
DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize));
|
||||
getitem = PyStackRef_FromPyObjectNew(getitem_o);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
STAT_INC(BINARY_OP, hit);
|
||||
}
|
||||
|
||||
op(_BINARY_SUBSCR_INIT_CALL, (container, sub, getitem -- new_frame: _PyInterpreterFrame* )) {
|
||||
op(_BINARY_OP_SUBSCR_INIT_CALL, (container, sub, getitem -- new_frame: _PyInterpreterFrame* )) {
|
||||
new_frame = _PyFrame_PushUnchecked(tstate, getitem, 2, frame);
|
||||
new_frame->localsplus[0] = container;
|
||||
new_frame->localsplus[1] = sub;
|
||||
|
@ -979,11 +951,11 @@ dummy_func(
|
|||
frame->return_offset = INSTRUCTION_SIZE;
|
||||
}
|
||||
|
||||
macro(BINARY_SUBSCR_GETITEM) =
|
||||
unused/1 + // Skip over the counter
|
||||
macro(BINARY_OP_SUBSCR_GETITEM) =
|
||||
unused/5 + // Skip over the counter and cache
|
||||
_CHECK_PEP_523 +
|
||||
_BINARY_SUBSCR_CHECK_FUNC +
|
||||
_BINARY_SUBSCR_INIT_CALL +
|
||||
_BINARY_OP_SUBSCR_CHECK_FUNC +
|
||||
_BINARY_OP_SUBSCR_INIT_CALL +
|
||||
_PUSH_FRAME;
|
||||
|
||||
inst(LIST_APPEND, (list, unused[oparg-1], v -- list, unused[oparg-1])) {
|
||||
|
@ -4816,7 +4788,7 @@ dummy_func(
|
|||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
|
||||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
assert(NB_ADD <= oparg);
|
||||
assert(oparg <= NB_INPLACE_XOR);
|
||||
assert(oparg <= NB_OPARG_LAST);
|
||||
}
|
||||
|
||||
op(_BINARY_OP, (lhs, rhs -- res)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue