mirror of
https://github.com/python/cpython.git
synced 2026-04-15 00:00:57 +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
|
|
@ -309,21 +309,41 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_ADD_INT, (left, right -- res, l, r)) {
|
||||
res = sym_new_compact_int(ctx);
|
||||
if (PyJitRef_IsUnique(left)) {
|
||||
REPLACE_OP(this_instr, _BINARY_OP_ADD_INT_INPLACE, 0, 0);
|
||||
}
|
||||
else if (PyJitRef_IsUnique(right)) {
|
||||
REPLACE_OP(this_instr, _BINARY_OP_ADD_INT_INPLACE_RIGHT, 0, 0);
|
||||
}
|
||||
// Result may be a unique compact int or a cached small int
|
||||
// at runtime. Mark as unique; inplace ops verify at runtime.
|
||||
res = PyJitRef_MakeUnique(sym_new_compact_int(ctx));
|
||||
l = left;
|
||||
r = right;
|
||||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res, l, r)) {
|
||||
res = sym_new_compact_int(ctx);
|
||||
if (PyJitRef_IsUnique(left)) {
|
||||
REPLACE_OP(this_instr, _BINARY_OP_SUBTRACT_INT_INPLACE, 0, 0);
|
||||
}
|
||||
else if (PyJitRef_IsUnique(right)) {
|
||||
REPLACE_OP(this_instr, _BINARY_OP_SUBTRACT_INT_INPLACE_RIGHT, 0, 0);
|
||||
}
|
||||
res = PyJitRef_MakeUnique(sym_new_compact_int(ctx));
|
||||
l = left;
|
||||
r = right;
|
||||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);
|
||||
}
|
||||
|
||||
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res, l, r)) {
|
||||
res = sym_new_compact_int(ctx);
|
||||
if (PyJitRef_IsUnique(left)) {
|
||||
REPLACE_OP(this_instr, _BINARY_OP_MULTIPLY_INT_INPLACE, 0, 0);
|
||||
}
|
||||
else if (PyJitRef_IsUnique(right)) {
|
||||
REPLACE_OP(this_instr, _BINARY_OP_MULTIPLY_INT_INPLACE_RIGHT, 0, 0);
|
||||
}
|
||||
res = PyJitRef_MakeUnique(sym_new_compact_int(ctx));
|
||||
l = left;
|
||||
r = right;
|
||||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right, res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue