mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-135474: Specialize arithmetic only on compact ints (GH-135479)
Specialize arithmetic only on compact ints. This also makes int operations non-escaping in the JIT and in tier 1.
This commit is contained in:
parent
c8319a3fea
commit
7b15873ed0
12 changed files with 81 additions and 155 deletions
|
@ -222,60 +222,15 @@ dummy_func(void) {
|
|||
}
|
||||
|
||||
op(_BINARY_OP_ADD_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 *temp = _PyLong_Add((PyLongObject *)sym_get_const(ctx, left),
|
||||
(PyLongObject *)sym_get_const(ctx, right));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and add tests!
|
||||
}
|
||||
else {
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
|
||||
op(_BINARY_OP_SUBTRACT_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 *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(ctx, left),
|
||||
(PyLongObject *)sym_get_const(ctx, right));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and add tests!
|
||||
}
|
||||
else {
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
|
||||
op(_BINARY_OP_MULTIPLY_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 *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(ctx, left),
|
||||
(PyLongObject *)sym_get_const(ctx, right));
|
||||
if (temp == NULL) {
|
||||
goto error;
|
||||
}
|
||||
res = sym_new_const(ctx, temp);
|
||||
Py_DECREF(temp);
|
||||
// TODO gh-115506:
|
||||
// replace opcode with constant propagated one and add tests!
|
||||
}
|
||||
else {
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
res = sym_new_type(ctx, &PyLong_Type);
|
||||
}
|
||||
|
||||
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue