-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
GH-101291: Rearrange the size bits in PyLongObject #102464
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 1 commit
0ec07e4
292b9d0
5c54894
029aaa4
b56e6da
91269fc
c48e825
449c0e2
c5ba601
4b3a3e8
9ef9d2c
9c408c1
548d656
3e3fefd
391fb51
df8c7d3
b
8000
c14fa6
54c6f1b
ce6bfb2
4c1956b
301158b
1aa1891
bf2a9af
169f521
90f9072
f143443
a0d661e
145a2e4
638a98f
7f5acc0
b06bb6f
a19b0a7
87f49b2
f764aa8
9843ac0
d6cb917
469d26f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3216,6 +3216,9 @@ PyLong_AsDouble(PyObject *v) | |
static Py_ssize_t | ||
long_compare(PyLongObject *a, PyLongObject *b) | ||
{ | ||
if (_PyLong_BothAreSingleDigit(a, b)) { | ||
return _PyLong_SingleDigitValue(a) - _PyLong_SingleDigitValue(b); | ||
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. This doesn't work well in the case where a is 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. If the values fit in a "single digit", then they have at least one bit to spare, so that |
||
} | ||
Py_ssize_t sign = _PyLong_SignedDigitCount(a) - _PyLong_SignedDigitCount(b); | ||
markshannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (sign == 0) { | ||
Py_ssize_t i = _PyLong_DigitCount(a); | ||
|
@@ -3392,7 +3395,7 @@ x_sub(PyLongObject *a, PyLongObject *b) | |
PyObject * | ||
_PyLong_Add(PyLongObject *a, PyLongObject *b) | ||
{ | ||
if (_PyLong_IsSingleDigit(a) && _PyLong_IsSingleDigit(b)) { | ||
if (_PyLong_BothAreSingleDigit(a, b)) { | ||
return _PyLong_FromSTwoDigits(medium_value(a) + medium_value(b)); | ||
} | ||
|
||
|
@@ -3433,7 +3436,7 @@ _PyLong_Subtract(PyLongObject *a, PyLongObject *b) | |
{ | ||
PyLongObject *z; | ||
|
||
if (_PyLong_IsSingleDigit(a) && _PyLong_IsSingleDigit(b)) { | ||
if (_PyLong_BothAreSingleDigit(a, b)) { | ||
return _PyLong_FromSTwoDigits(medium_value(a) - medium_value(b)); | ||
} | ||
if (_PyLong_IsNegative(a)) { | ||
|
@@ -3885,7 +3888,7 @@ _PyLong_Multiply(PyLongObject *a, PyLongObject *b) | |
PyLongObject *z; | ||
|
||
/* fast path for single-digit multiplication */ | ||
if (_PyLong_IsSingleDigit(a) && _PyLong_IsSingleDigit(b)) { | ||
if (_PyLong_BothAreSingleDigit(a, b)) { | ||
stwodigits v = medium_value(a) * medium_value(b); | ||
return _PyLong_FromSTwoDigits(v); | ||
} | ||
|
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.