gh-135474: Specialize arithmetic only on compact ints#135479
gh-135474: Specialize arithmetic only on compact ints#135479Fidget-Spinner merged 4 commits intopython:mainfrom
Conversation
markshannon
left a comment
There was a problem hiding this comment.
This looks good.
As a refinement, we can remove the additional check in the action micro-ops, narrowing the test in the guard micro-ops.
I'll start a benchmark run, just to check.
| PyObject *right_o = PyStackRef_AsPyObjectBorrow(right); | ||
| assert(PyLong_CheckExact(left_o)); | ||
| assert(PyLong_CheckExact(right_o)); | ||
| DEOPT_IF(!_PyLong_BothAreCompact((PyLongObject *)left_o, (PyLongObject *)right_o)); |
There was a problem hiding this comment.
If you narrow the checks in _GUARD_TOS_INT and _GUARD_NOS_INT to check for compact ints, we can drop the check here. That way we keep the guard and action in separate micro-ops.
Likewise for + and -. The only complexity is that optimizer_bytecodes.c will need updating to handle compact ints differently.
This change is fine for now though, if you want to do the more sophisticated change in another PR.
There was a problem hiding this comment.
Sure, I can do that.
There was a problem hiding this comment.
On second thought, it's best to leave this to another PR. We need to introduce a new type altogether (one separate from the sym_set_type(&PyLong_Type), and I want to keep this PR's change confined to longobject.c).
|
So the benchmark results are in: it's consistently faster on most platforms, ignoring the strange fluctuations on macOS https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20250614-3.15.0a0-4019a15 |
…-135479) Specialize arithmetic only on compact ints. This also makes int operations non-escaping in the JIT and in tier 1.
…-135479) Specialize arithmetic only on compact ints. This also makes int operations non-escaping in the JIT and in tier 1.
…-135479) Specialize arithmetic only on compact ints. This also makes int operations non-escaping in the JIT and in tier 1.
…-135479) Specialize arithmetic only on compact ints. This also makes int operations non-escaping in the JIT and in tier 1.
📚 Documentation preview 📚: https://cpython-previews--135479.org.readthedocs.build/