mirror of
https://github.com/python/cpython.git
synced 2026-04-14 15:50:50 +00:00
gh-146640: Optimize int operations by mutating uniquely-referenced operands in place (JIT only) (GH-146641)
This commit is contained in:
parent
80ab6d958a
commit
48317feec8
9 changed files with 2331 additions and 1262 deletions
|
|
@ -708,6 +708,63 @@ dummy_func(
|
|||
macro(BINARY_OP_SUBTRACT_INT) =
|
||||
_GUARD_TOS_INT + _GUARD_NOS_INT + unused/5 + _BINARY_OP_SUBTRACT_INT + _POP_TOP_INT + _POP_TOP_INT;
|
||||
|
||||
// Inplace compact int ops: mutate the uniquely-referenced operand
|
||||
// when possible. The op handles decref of TARGET internally so
|
||||
// the following _POP_TOP_INT becomes _POP_TOP_NOP. Tier 2 only.
|
||||
tier2 op(_BINARY_OP_ADD_INT_INPLACE, (left, right -- res, l, r)) {
|
||||
INT_INPLACE_OP(left, right, left, +, _PyCompactLong_Add);
|
||||
EXIT_IF(PyStackRef_IsNull(_int_inplace_res));
|
||||
res = _int_inplace_res;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
tier2 op(_BINARY_OP_SUBTRACT_INT_INPLACE, (left, right -- res, l, r)) {
|
||||
INT_INPLACE_OP(left, right, left, -, _PyCompactLong_Subtract);
|
||||
EXIT_IF(PyStackRef_IsNull(_int_inplace_res));
|
||||
res = _int_inplace_res;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
tier2 op(_BINARY_OP_MULTIPLY_INT_INPLACE, (left, right -- res, l, r)) {
|
||||
INT_INPLACE_OP(left, right, left, *, _PyCompactLong_Multiply);
|
||||
EXIT_IF(PyStackRef_IsNull(_int_inplace_res));
|
||||
res = _int_inplace_res;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
tier2 op(_BINARY_OP_ADD_INT_INPLACE_RIGHT, (left, right -- res, l, r)) {
|
||||
INT_INPLACE_OP(left, right, right, +, _PyCompactLong_Add);
|
||||
EXIT_IF(PyStackRef_IsNull(_int_inplace_res));
|
||||
res = _int_inplace_res;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
tier2 op(_BINARY_OP_SUBTRACT_INT_INPLACE_RIGHT, (left, right -- res, l, r)) {
|
||||
INT_INPLACE_OP(left, right, right, -, _PyCompactLong_Subtract);
|
||||
EXIT_IF(PyStackRef_IsNull(_int_inplace_res));
|
||||
res = _int_inplace_res;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
tier2 op(_BINARY_OP_MULTIPLY_INT_INPLACE_RIGHT, (left, right -- res, l, r)) {
|
||||
INT_INPLACE_OP(left, right, right, *, _PyCompactLong_Multiply);
|
||||
EXIT_IF(PyStackRef_IsNull(_int_inplace_res));
|
||||
res = _int_inplace_res;
|
||||
l = left;
|
||||
r = right;
|
||||
INPUTS_DEAD();
|
||||
}
|
||||
|
||||
op(_GUARD_NOS_FLOAT, (left, unused -- left, unused)) {
|
||||
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
|
||||
EXIT_IF(!PyFloat_CheckExact(left_o));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue