mirror of
https://github.com/python/cpython.git
synced 2026-03-30 16:41:06 +00:00
GH-132732: Use pure op machinery to optimize COMPARE_OP_INT/FLOAT/STR (#137062)
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
This commit is contained in:
parent
1e69cd1634
commit
f7c380ef67
6 changed files with 237 additions and 39 deletions
|
|
@ -430,31 +430,17 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_COMPARE_OP_INT, (left, right -- res)) {
|
||||
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
|
||||
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
|
||||
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
|
||||
PyObject *tmp = PyObject_RichCompare(sym_get_const(ctx, left),
|
||||
sym_get_const(ctx, right),
|
||||
oparg >> 5);
|
||||
if (tmp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
assert(PyBool_Check(tmp));
|
||||
assert(_Py_IsImmortal(tmp));
|
||||
REPLACE_OP(this_instr, _POP_TWO_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)tmp);
|
||||
res = sym_new_const(ctx, tmp);
|
||||
Py_DECREF(tmp);
|
||||
}
|
||||
else {
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_COMPARE_OP_FLOAT, (left, right -- res)) {
|
||||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
op(_COMPARE_OP_STR, (left, right -- res)) {
|
||||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right);
|
||||
res = sym_new_type(ctx, &PyBool_Type);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue