diff options
author | Ken Jin <kenjin@python.org> | 2024-03-06 19:30:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-06 19:30:11 (GMT) |
commit | 7114cf20c015b99123b32c1ba4f5475b7a6c3a13 (patch) | |
tree | 1c5392c31ac5d921cfb0b5856ff2df66cdfd4682 /Python/bytecodes.c | |
parent | 73807eb634315f70a464a18feaae33d9e065de09 (diff) | |
download | cpython-7114cf20c015b99123b32c1ba4f5475b7a6c3a13.zip cpython-7114cf20c015b99123b32c1ba4f5475b7a6c3a13.tar.gz cpython-7114cf20c015b99123b32c1ba4f5475b7a6c3a13.tar.bz2 |
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>
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r-- | Python/bytecodes.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index ad4ea4e..bf0583d 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -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(); |