Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-129149: Add Missing fast path in PYLONG_FROM_UINT macro for compact integers#129168
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
ed9be47ba7051834315cb0ef383cc00ba8c2b5163f955bb37237b8b911ad06fc25b91037a5c9a2cb1aec99c542027247582a8692d70d85f1af410e05a9e2015760c951f81b87f4d74d2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add fast path for medium-size integers in :c:func:`PyLong_FromUnsignedLong`, | ||
| :c:func:`PyLong_FromUnsignedLongLong` and :c:func:`PyLong_FromSize_t`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -359,9 +359,13 @@ PyLong_FromLong(long ival) | ||
| if (IS_SMALL_UINT(ival)) { \ | ||
| return get_small_int((sdigit)(ival)); \ | ||
| } \ | ||
| if ((ival) <= PyLong_MASK) { \ | ||
| return _PyLong_FromMedium((sdigit)(ival)); \ | ||
| } \ | ||
| /* Do shift in two steps to avoid possible undefined behavior. */ \ | ||
| INT_TYPE t = (ival) >> PyLong_SHIFT >> PyLong_SHIFT; \ | ||
| /* Count the number of Python digits. */ \ | ||
| Py_ssize_t ndigits = 0; \ | ||
| INT_TYPE t = (ival); \ | ||
| Py_ssize_t ndigits = 2; \ | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on the main...eendebakpt:cpython:fast_digit_count @srinivasreddy Would you be interested in benchmarking this approach and making a PR? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Absolutely. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I do not think this works on a platform where e.g. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| while (t) { \ | ||
| ++ndigits; \ | ||
| t >>= PyLong_SHIFT; \ | ||
Uh oh!
There was an error while loading. Please reload this page.