mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-100982: Break up COMPARE_AND_BRANCH (GH-102801)
This commit is contained in:
parent
bd063756b3
commit
0444ae2487
18 changed files with 377 additions and 479 deletions
|
@ -1687,75 +1687,54 @@ dummy_func(
|
|||
Py_DECREF(owner);
|
||||
}
|
||||
|
||||
family(compare_op, INLINE_CACHE_ENTRIES_COMPARE_OP) = {
|
||||
COMPARE_OP,
|
||||
COMPARE_OP_FLOAT,
|
||||
COMPARE_OP_INT,
|
||||
COMPARE_OP_STR,
|
||||
};
|
||||
|
||||
inst(COMPARE_OP, (unused/1, left, right -- res)) {
|
||||
#if ENABLE_SPECIALIZATION
|
||||
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
next_instr--;
|
||||
_Py_Specialize_CompareOp(left, right, next_instr, oparg);
|
||||
DISPATCH_SAME_OPARG();
|
||||
}
|
||||
STAT_INC(COMPARE_OP, deferred);
|
||||
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
assert((oparg >> 4) <= Py_GE);
|
||||
res = PyObject_RichCompare(left, right, oparg>>4);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(res == NULL, error);
|
||||
}
|
||||
|
||||
// No cache size here, since this is a family of super-instructions.
|
||||
family(compare_and_branch) = {
|
||||
COMPARE_AND_BRANCH,
|
||||
COMPARE_AND_BRANCH_FLOAT,
|
||||
COMPARE_AND_BRANCH_INT,
|
||||
COMPARE_AND_BRANCH_STR,
|
||||
};
|
||||
|
||||
inst(COMPARE_AND_BRANCH, (unused/2, left, right -- )) {
|
||||
#if ENABLE_SPECIALIZATION
|
||||
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
next_instr--;
|
||||
_Py_Specialize_CompareAndBranch(left, right, next_instr, oparg);
|
||||
DISPATCH_SAME_OPARG();
|
||||
}
|
||||
STAT_INC(COMPARE_AND_BRANCH, deferred);
|
||||
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
assert((oparg >> 4) <= Py_GE);
|
||||
PyObject *cond = PyObject_RichCompare(left, right, oparg>>4);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(cond == NULL, error);
|
||||
assert(next_instr[1].op.code == POP_JUMP_IF_FALSE ||
|
||||
next_instr[1].op.code == POP_JUMP_IF_TRUE);
|
||||
bool jump_on_true = next_instr[1].op.code == POP_JUMP_IF_TRUE;
|
||||
int offset = next_instr[1].op.arg;
|
||||
int err = PyObject_IsTrue(cond);
|
||||
Py_DECREF(cond);
|
||||
ERROR_IF(err < 0, error);
|
||||
if (jump_on_true == (err != 0)) {
|
||||
JUMPBY(offset);
|
||||
}
|
||||
}
|
||||
|
||||
inst(COMPARE_AND_BRANCH_FLOAT, (unused/2, left, right -- )) {
|
||||
inst(COMPARE_OP_FLOAT, (unused/1, left, right -- res)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_AND_BRANCH);
|
||||
STAT_INC(COMPARE_AND_BRANCH, hit);
|
||||
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyFloat_CheckExact(right), COMPARE_OP);
|
||||
STAT_INC(COMPARE_OP, hit);
|
||||
double dleft = PyFloat_AS_DOUBLE(left);
|
||||
double dright = PyFloat_AS_DOUBLE(right);
|
||||
// 1 if NaN, 2 if <, 4 if >, 8 if ==; this matches low four bits of the oparg
|
||||
int sign_ish = COMPARISON_BIT(dleft, dright);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
if (sign_ish & oparg) {
|
||||
int offset = next_instr[1].op.arg;
|
||||
JUMPBY(offset);
|
||||
}
|
||||
res = (sign_ish & oparg) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
}
|
||||
|
||||
// Similar to COMPARE_AND_BRANCH_FLOAT
|
||||
inst(COMPARE_AND_BRANCH_INT, (unused/2, left, right -- )) {
|
||||
// Similar to COMPARE_OP_FLOAT
|
||||
inst(COMPARE_OP_INT, (unused/1, left, right -- res)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_AND_BRANCH);
|
||||
STAT_INC(COMPARE_AND_BRANCH, hit);
|
||||
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_OP);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_OP);
|
||||
STAT_INC(COMPARE_OP, hit);
|
||||
assert(_PyLong_DigitCount((PyLongObject *)left) <= 1 &&
|
||||
_PyLong_DigitCount((PyLongObject *)right) <= 1);
|
||||
Py_ssize_t ileft = _PyLong_CompactValue((PyLongObject *)left);
|
||||
|
@ -1764,29 +1743,25 @@ dummy_func(
|
|||
int sign_ish = COMPARISON_BIT(ileft, iright);
|
||||
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
|
||||
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
|
||||
if (sign_ish & oparg) {
|
||||
int offset = next_instr[1].op.arg;
|
||||
JUMPBY(offset);
|
||||
}
|
||||
res = (sign_ish & oparg) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
}
|
||||
|
||||
// Similar to COMPARE_AND_BRANCH_FLOAT, but for ==, != only
|
||||
inst(COMPARE_AND_BRANCH_STR, (unused/2, left, right -- )) {
|
||||
// Similar to COMPARE_OP_FLOAT, but for ==, != only
|
||||
inst(COMPARE_OP_STR, (unused/1, left, right -- res)) {
|
||||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_AND_BRANCH);
|
||||
STAT_INC(COMPARE_AND_BRANCH, hit);
|
||||
int res = _PyUnicode_Equal(left, right);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
|
||||
STAT_INC(COMPARE_OP, hit);
|
||||
int eq = _PyUnicode_Equal(left, right);
|
||||
assert((oparg >>4) == Py_EQ || (oparg >>4) == Py_NE);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
|
||||
assert(res == 0 || res == 1);
|
||||
assert(eq == 0 || eq == 1);
|
||||
assert((oparg & 0xf) == COMPARISON_NOT_EQUALS || (oparg & 0xf) == COMPARISON_EQUALS);
|
||||
assert(COMPARISON_NOT_EQUALS + 1 == COMPARISON_EQUALS);
|
||||
if ((res + COMPARISON_NOT_EQUALS) & oparg) {
|
||||
int offset = next_instr[1].op.arg;
|
||||
JUMPBY(offset);
|
||||
}
|
||||
res = ((COMPARISON_NOT_EQUALS + eq) & oparg) ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
}
|
||||
|
||||
inst(IS_OP, (left, right -- b)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue