Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 37 commits into from
Mar 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0ec07e4
Add functions to hide some internals of long object.
markshannon Jan 25, 2023
292b9d0
Add internal functions to longobject.c for setting sign and digit count.
markshannon Jan 25, 2023
5c54894
Replace Py_SIZE(x) < 0 with _PyLong_IsNegative(x) in longobject.c
markshannon Feb 28, 2023
029aaa4
Replace Py_ABS(Py_SIZE(a)) with _PyLong_DigitCount(a) in longobject.c
markshannon Feb 28, 2023
b56e6da
Remove many uses of Py_SIZE in longobject.c
markshannon Feb 28, 2023
91269fc
Remove _PyLong_AssignValue, as it is no longer used.
markshannon Feb 28, 2023
c48e825
Remove some more uses of Py_SIZE in longobject.c.
markshannon Feb 28, 2023
449c0e2
Remove a few more uses of Py_SIZE in longobject.c.
markshannon Mar 1, 2023
c5ba601
Remove some more uses of Py_SIZE, replacing with _PyLong_UnsignedDigi…
markshannon Mar 1, 2023
4b3a3e8
Replace a few Py_SIZE() with _PyLong_SameSign().
markshannon Mar 1, 2023
9ef9d2c
Remove a few more Py_SIZE() from longobject.c
markshannon Mar 1, 2023
9c408c1
Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsSingleDigit.
markshannon Mar 1, 2023
548d656
Remove most of the remaining uses of Py_SIZE in longobject.c
markshannon Mar 1, 2023
3e3fefd
Replace last remaining uses of Py_SIZE applied to longobject with _Py…
markshannon Mar 1, 2023
391fb51
Don't use _PyObject_InitVar and move a couple of inline functions to …
markshannon Mar 1, 2023
df8c7d3
Correct name of inline function.
markshannon Mar 1, 2023
bc14fa6
Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject.
markshannon Mar 1, 2023
54c6f1b
Change layout of size/sign bits in longobject to support future addit…
markshannon Mar 2, 2023
ce6bfb2
Test pairs of longs together on fast path of add/mul/sub.
markshannon Mar 2, 2023
4c1956b
Tidy up comment and delete commented out code.
markshannon Mar 6, 2023
301158b
Add news.
markshannon Mar 6, 2023
1aa1891
Remove debugging asserts.
markshannon Mar 6, 2023
bf2a9af
Fix storage classes.
markshannon Mar 6, 2023
169f521
Remove development debug functions.
markshannon Mar 6, 2023
90f9072
Avoid casting to smaller int.
markshannon Mar 8, 2023
f143443
Apply suggestions from code review.
markshannon Mar 8, 2023
a0d661e
Widen types to avoid data loss.
markshannon Mar 8, 2023
145a2e4
Fix syntax error.
markshannon Mar 8, 2023
638a98f
Replace 'SingleDigit' with 'Compact' as the term 'single digit' seems…
markshannon Mar 9, 2023
7f5acc0
Address review comments.
markshannon Mar 16, 2023
b06bb6f
Merge branch 'main' into long-rearrange-size-bits
markshannon Mar 16, 2023
a19b0a7
Merge branch 'main' into long-rearrange-size-bits
markshannon Mar 16, 2023
87f49b2
Fix _PyLong_Sign
markshannon Mar 16, 2023
f764aa8
Replace _PyLong_Sign(x) < 0 with _PyLong_IsNegative(x).
markshannon Mar 16, 2023
9843ac0
fix sign check
markshannon Mar 16, 2023
d6cb917
Address some review comments.
markshannon Mar 22, 2023
469d26f
Change asserts on digit counts to asserts on sign where applicable.
markshannon Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove a few more uses of Py_SIZE in longobject.c.
  • Loading branch information
markshannon committed Mar 1, 2023
commit 449c0e2970aad4ae678990a186de0bf345a4b665
34 changes: 16 additions & 18 deletions 34 Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ long_divrem(PyLongObject *a, PyLongObject *b,
return -1;
}
}
if (_PyLong_IsNegative(a) && Py_SIZE(*prem) != 0) {
if (_PyLong_IsNegative(a) && !_PyLong_IsZero(*prem)) {
_PyLong_Negate(prem);
if (*prem == NULL) {
Py_DECREF(z);
Expand Down Expand Up @@ -2916,7 +2916,7 @@ long_rem(PyLongObject *a, PyLongObject *b, PyLongObject **prem)
return -1;
}
/* Set the sign. */
if (_PyLong_IsNegative(a) && Py_SIZE(*prem) != 0) {
if (_PyLong_IsNegative(a) && !_PyLong_IsZero(*prem)) {
_PyLong_Negate(prem);
if (*prem == NULL) {
Py_CLEAR(*prem);
Expand Down Expand Up @@ -3259,18 +3259,16 @@ long_hash(PyLongObject *v)
Py_ssize_t i;
int sign;

i = Py_SIZE(v);
switch(i) {
case -1: return v->long_value.ob_digit[0]==1 ? -2 : -(sdigit)v->long_value.ob_digit[0];
case 0: return 0;
case 1: return v->long_value.ob_digit[0];
if (_PyLong_IsSingleDigit(v)) {
x = _PyLong_SingleDigitValue(v);
if (x == (Py_uhash_t)-1) {
x = (Py_uhash_t)-2;
}
return x;
}
sign = 1;
i = _PyLong_DigitCount(v);
sign = _PyLong_NonZeroSign(v);
x = 0;
if (i < 0) {
sign = -1;
i = -(i);
}
while (--i >= 0) {
/* Here x is a quantity in the range [0, _PyHASH_MODULUS); we
want to compute x * 2**PyLong_SHIFT + v->long_value.ob_digit[i] modulo
Expand Down Expand Up @@ -3454,7 +3452,7 @@ _PyLong_Subtract(PyLongObject *a, PyLongObject *b)
else {
z = x_add(a, b);
if (z != NULL) {
assert(Py_SIZE(z) == 0 || Py_REFCNT(z) == 1);
assert(_PyLong_IsZero(z) || Py_REFCNT(z) == 1);
_PyLong_FlipSign(z);
}
}
Expand Down Expand Up @@ -4583,7 +4581,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)
if (c) {
/* if modulus == 0:
raise ValueError() */
if (Py_SIZE(c) == 0) {
if (_PyLong_IsZero(c)) {
PyErr_SetString(PyExc_ValueError,
"pow() 3rd argument cannot be 0");
goto Error;
Expand Down Expand Up @@ -4992,7 +4990,7 @@ long_rshift(PyObject *a, PyObject *b)
PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL;
}
if (Py_SIZE(a) == 0) {
if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
if (divmod_shift(b, &wordshift, &remshift) < 0)
Expand All @@ -5008,7 +5006,7 @@ _PyLong_Rshift(PyObject *a, size_t shiftby)
digit remshift;

assert(PyLong_Check(a));
if (Py_SIZE(a) == 0) {
if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
wordshift = shiftby / PyLong_SHIFT;
Expand Down Expand Up @@ -5069,7 +5067,7 @@ long_lshift(PyObject *a, PyObject *b)
PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL;
}
if (Py_SIZE(a) == 0) {
if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
if (divmod_shift(b, &wordshift, &remshift) < 0)
Expand All @@ -5085,7 +5083,7 @@ _PyLong_Lshift(PyObject *a, size_t shiftby)
digit remshift;

assert(PyLong_Check(a));
if (Py_SIZE(a) == 0) {
if (_PyLong_IsZero((PyLongObject *)a)) {
return PyLong_FromLong(0);
}
wordshift = shiftby / PyLong_SHIFT;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.