8000 GH-101291: Rearrange the size bits in PyLongObject by markshannon · Pull Request #102464 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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
Show file tree
Hide file tree
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
Correct name of inline function.
  • Loading branch information
markshannon committed Mar 1, 2023
commit df8c7d3f8563aeee1bb69c1b5780f491c217b093
3 changes: 2 additions & 1 deletion Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
int base,
int alternate);


/* Return 1 if the argument is positive single digit int */
static inline int
_PyLong_IsPositiveSingleDigit(const PyLongObject* op) {
_PyLong_IsNonNegativeSingleDigit(const PyLongObject* op) {
/* For a positive single digit int, the value of Py_SIZE(sub) is 0 or 1.

We perform a fast check using a single comparison by casting from int
Expand Down
12 changes: 6 additions & 6 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ PyLong_AsUnsignedLong(PyObject *vv)
}

v = (PyLongObject *)vv;
if (_PyLong_IsPositiveSingleDigit(v)) {
if (_PyLong_IsNonNegativeSingleDigit(v)) {
return _PyLong_SingleDigitValue(v);
}
if (_PyLong_IsNegative(v)) {
Expand Down Expand Up @@ -659,7 +659,7 @@ PyLong_AsSize_t(PyObject *vv)
}

v = (PyLongObject *)vv;
if (_PyLong_IsPositiveSingleDigit(v)) {
if (_PyLong_IsNonNegativeSingleDigit(v)) {
return _PyLong_SingleDigitValue(v);
}
if (_PyLong_IsNegative(v)) {
Expand Down Expand Up @@ -696,7 +696,7 8000 @@ _PyLong_AsUnsignedLongMask(PyObject *vv)
return (unsigned long) -1;
}
v = (PyLongObject *)vv;
if (_PyLong_IsPositiveSingleDigit(v)) {
if (_PyLong_IsNonNegativeSingleDigit(v)) {
return _PyLong_SingleDigitValue(v);
}
i = _PyLong_DigitCount(v);
Expand Down Expand Up @@ -1228,7 +1228,7 @@ PyLong_AsUnsignedLongLong(PyObject *vv)
}

v = (PyLongObject*)vv;
if (_PyLong_IsPositiveSingleDigit(v)) {
if (_PyLong_IsNonNegativeSingleDigit(v)) {
res = 0;
bytes = _PyLong_SingleDigitValue(v);
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ _PyLong_AsUnsignedLongLongMask(PyObject *vv)
return (unsigned long long) -1;
}
v = (PyLongObject *)vv;
if (_PyLong_IsPositiveSingleDigit(v)) {
if (_PyLong_IsNonNegativeSingleDigit(v)) {
return _PyLong_SingleDigitValue(v);
}
i = _PyLong_DigitCount(v);
Expand Down Expand Up @@ -4582,7 +4582,7 @@ long_pow(PyObject *v, PyObject *w, PyObject *x)

/* if modulus == 1:
return 0 */
if (_PyLong_IsPositiveSingleDigit(c) && (c->long_value.ob_digit[0] == 1)) {
if (_PyLong_IsNonNegativeSingleDigit(c) && (c->long_value.ob_digit[0] == 1)) {
z = (PyLongObject *)PyLong_FromLong(0L);
goto Done;
}
Expand Down
6 changes: 3 additions & 3 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ dummy_func(
DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);

// Deopt unless 0 <= sub < PyList_Size(list)
DEOPT_IF(!_PyLong_IsPositiveSingleDigit((PyLongObject *)sub), BINARY_SUBSCR);
DEOPT_IF(!_PyLong_IsNonNegativeSingleDigit((PyLongObject *)sub), BINARY_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(index >= PyList_GET_SIZE(list), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
Expand All @@ -373,7 +373,7 @@ dummy_func(
DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);

// Deopt unless 0 <= sub < PyTuple_Size(list)
DEOPT_IF(!_PyLong_IsPositiveSingleDigit((PyLongObject *)sub), BINARY_SUBSCR);
DEOPT_IF(!_PyLong_IsNonNegativeSingleDigit((PyLongObject *)sub), BINARY_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple), BINARY_SUBSCR);
STAT_INC(BINARY_SUBSCR, hit);
Expand Down Expand Up @@ -466,7 +466,7 @@ dummy_func(
DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);

// Ensure nonnegative, zero-or-one-digit ints.
DEOPT_IF(!_PyLong_IsPositiveSingleDigit((PyLongObject *)sub), STORE_SUBSCR);
DEOPT_IF(!_PyLong_IsNonNegativeSingleDigit((PyLongObject *)sub), STORE_SUBSCR);
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
// Ensure index < len(list)
DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR);
Expand Down
6 changes: 3 additions & 3 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ _Py_Specialize_BinarySubscr(
PyTypeObject *container_type = Py_TYPE(container);
if (container_type == &PyList_Type) {
if (PyLong_CheckExact(sub)) {
if (_PyLong_IsPositiveSingleDigit((PyLongObject *)sub)) {
if (_PyLong_IsNonNegativeSingleDigit((PyLongObject *)sub)) {
instr->op.code = BINARY_SUBSCR_LIST_INT;
goto success;
}
Expand All @@ -1307,7 +1307,7 @@ _Py_Specialize_BinarySubscr(
}
if (container_type == &PyTuple_Type) {
if (PyLong_CheckExact(sub)) {
if (_PyLong_IsPositiveSingleDigit((PyLongObject *)sub)) {
if (_PyLong_IsNonNegativeSingleDigit((PyLongObject *)sub)) {
instr->op.code = BINARY_SUBSCR_TUPLE_INT;
goto success;
}
Expand Down Expand Up @@ -1375,7 +1375,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins
PyTypeObject *container_type = Py_TYPE(container);
if (container_type == &PyList_Type) {
if (PyLong_CheckExact(sub)) {
if (_PyLong_IsPositiveSingleDigit((PyLongObject *)sub)
if (_PyLong_IsNonNegativeSingleDigit((PyLongObject *)sub)
&& ((PyLongObject *)sub)->long_value.ob_digit[0] < (size_t)PyList_GET_SIZE(container))
{
instr->op.code = STORE_SUBSCR_LIST_INT;
Expand Down
0