-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-129149: Add Missing fast path in PYLONG_FROM_UINT macro for compact integers #129168
Conversation
srinivasreddy
commented
Jan 22, 2025
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Missing fast path in PyLong_From*() functions for compact integers #129149
This comment was marked as resolved.
This comment was marked as resolved.
…IGNED. And also added a blurb about the changes
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
…e-129149.wAYu43.rst Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
…e-129149.wAYu43.rst Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
…e-129149.wAYu43.rst
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I second on comment on declarations in *_FROM_SIGNED. Also, I don't think that PYLONG_FROM_UINT should be moved.
Co-authored-by: Yan Yanchii <yyanchiy@gmail.com>
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the code was only moved around and there's no new fast path, I would prefer to do it in a separate PR rather than in this one.
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
Action plan for PRs.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you misread me. Refactoring change (conversion PyLong_FromLongLong and PyLong_FromLong to macro) doesn't require a news entry. But this change - does.
This reverts commit af410e0.
@skirpichev Done. |
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit and LGTM.
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
…e-129149.wAYu43.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz Done 👍🏾 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine but I'll @vstinner have a look as I'm not very familiar with this performance part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Misc/NEWS.d/next/Core_and_Builtins/2025-01-22-14-24-44.gh-issue-129149.wAYu43.rst
Outdated
Show resolved
Hide resolved
…e-129149.wAYu43.rst Co-authored-by: Victor Stinner <vstinner@python.org>
Merged, thanks @srinivasreddy! |
/* Count the number of Python digits. */ \ | ||
Py_ssize_t ndigits = 0; \ | ||
INT_TYPE t = (ival); \ | ||
Py_ssize_t ndigits = 2; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the INT_TYPE
the value of ndigits can only be 2 or 3. We can replace the while loop with a single if statement. E.g.
main...eendebakpt:cpython:fast_digit_count
@srinivasreddy Would you be interested in benchmarking this approach and making a PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Absolutely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or 3
I do not think this works on a platform where e.g. long long
is 128 bit? Or for PYLONG_BITS_IN_DIGIT=15
and long long
being 64bit?
Maybe both hypothetical, but not impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. We would need some guards for that. Whether that bit of complexity is worth is, depends on the benchmark results.