-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Changes from all commits
ed9be47
ba70518
34315cb
0ef383c
c00ba8c
2b5163f
955bb37
237b8b9
11ad06f
c25b910
37a5c9a
2cb1aec
99c5420
2724758
2a8692d
70d85f1
af410e0
5a9e201
5760c95
1f81b87
f4d74d2
File filter
Filter by extension
Conversations
Jump to
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; \ | ||
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? 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. 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. 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.