mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
gh-116381: Specialize CONTAINS_OP (GH-116385)
* Specialize CONTAINS_OP * 📜🤖 Added by blurb_it. * Add PyAPI_FUNC for JIT --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
73807eb634
commit
7114cf20c0
21 changed files with 645 additions and 194 deletions
|
@ -2237,13 +2237,75 @@ dummy_func(
|
|||
b = res ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
inst(CONTAINS_OP, (left, right -- b)) {
|
||||
family(CONTAINS_OP, INLINE_CACHE_ENTRIES_CONTAINS_OP) = {
|
||||
CONTAINS_OP_LIST,
|
||||
CONTAINS_OP_SET,
|
||||
CONTAINS_OP_TUPLE,
|
||||
CONTAINS_OP_DICT,
|
||||
CONTAINS_OP_STR,
|
||||
};
|
||||
|
||||
op(_CONTAINS_OP, (left, right -- b)) {
|
||||
int res = PySequence_Contains(right, left);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
specializing op(_SPECIALIZE_CONTAINS_OP, (counter/1, left, right -- left, right)) {
|
||||
#if ENABLE_SPECIALIZATION
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(counter)) {
|
||||
next_instr = this_instr;
|
||||
_Py_Specialize_ContainsOp(right, next_instr);
|
||||
DISPATCH_SAME_OPARG();
|
||||
}
|
||||
STAT_INC(CONTAINS_OP, deferred);
|
||||
DECREMENT_ADAPTIVE_COUNTER(this_instr[1].cache);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
}
|
||||
|
||||
macro(CONTAINS_OP) = _SPECIALIZE_CONTAINS_OP + _CONTAINS_OP;
|
||||
|
||||
inst(CONTAINS_OP_LIST, (unused/1, left, right -- b)) {
|
||||
DEOPT_IF(!PyList_CheckExact(right));
|
||||
int res = _PyList_Contains(right, left);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
inst(CONTAINS_OP_SET, (unused/1, left, right -- b)) {
|
||||
DEOPT_IF(!PySet_CheckExact(right));
|
||||
int res = _PySet_Contains((PySetObject *)right, left);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
inst(CONTAINS_OP_TUPLE, (unused/1, left, right -- b)) {
|
||||
DEOPT_IF(!PyTuple_CheckExact(right));
|
||||
int res = _PyTuple_Contains((PyTupleObject *)right, left);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
inst(CONTAINS_OP_DICT, (unused/1, left, right -- b)) {
|
||||
DEOPT_IF(!PyDict_CheckExact(right));
|
||||
int res = PyDict_Contains(right, left);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
inst(CONTAINS_OP_STR, (unused/1, left, right -- b)) {
|
||||
DEOPT_IF(!PyUnicode_CheckExact(right));
|
||||
int res = PyUnicode_Contains(right, left);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res < 0, error);
|
||||
b = (res ^ oparg) ? Py_True : Py_False;
|
||||
}
|
||||
|
||||
inst(CHECK_EG_MATCH, (exc_value, match_type -- rest, match)) {
|
||||
if (_PyEval_CheckExceptStarTypeValid(tstate, match_type) < 0) {
|
||||
DECREF_INPUTS();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue