GH-135379: Specialize int operations for compact ints only#135668
GH-135379: Specialize int operations for compact ints only#135668markshannon merged 4 commits intopython:mainfrom
Conversation
…tion in case of overflow
|
Can you please add tests for the new synbol to optimizer_symbols.c? |
Fidget-Spinner
left a comment
There was a problem hiding this comment.
Need tests and one comment. Otherwise LGTM.
| return; | ||
| case JIT_SYM_KNOWN_VALUE_TAG: | ||
| if (!PyLong_CheckCompact(sym->value.value)) { | ||
| Py_CLEAR(sym->value.value); |
There was a problem hiding this comment.
I don't think you need to clear things here? It's automatically cleared on finalization of the whole optimizer I think.
There was a problem hiding this comment.
We need to do it here (we do the same in _Py_uop_sym_set_type) as we are changing the tag, so the finalization won't know there was an object there.
There was a problem hiding this comment.
AH ok that's very tricky! Good observation.
|
Performance is about neutral, all within noise:
Which is good, as the main point of this PR is to ultimately improve tier 2 performance as this will enable better TOS caching and easier implementation of tagged ints. |
|
|
|
|
| static inline int | ||
| PyLong_CheckCompact(const PyObject *op) | ||
| { | ||
| return PyLong_CheckExact(op) && _PyLong_IsCompact((PyLongObject *)op); |
There was a problem hiding this comment.
Seems like the cast here should be (const PyLongObject *) instead due to some strict compilers. Let me put up a PR.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This changes the way we handle ints during specialization.
Instead of handling all ints we only specialize for compact ints.
Since compact ints represent the large majority of ints we get a faster common path, at the cost of a few more de-optimizations.
Using compact ints only, and de-optimizing in the extremely rare no-memory case, we can simplify the performance critical paths for integer operations.
This is helpful for top-of-stack caching as the newer simpler instructions to not escape or need to handle errors, so avoids the need to spill to memory.
This also gives us the potential to use
BINARY_OP_EXTENDfor multi-digit ints in the future.