8000 Draft: gh-127119: Faster check for small ints in long_dealloc (debug) by eendebakpt · Pull Request #128187 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Draft: gh-127119: Faster check for small ints in long_dealloc (debug) #128187

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

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cfb70cb
Faster check for small ints in long_dealloc
eendebakpt Dec 4, 2024
426dd09
📜🤖 Added by blurb_it.
blurb-it[bot] Dec 4, 2024
4639642
Use int immortality bit for small int check
eendebakpt Dec 5, 2024
d9c26d3
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 5, 2024
2f73d47
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 5, 2024
3b6e1fe
fix compiler warnings
eendebakpt Dec 5, 2024
03184a7
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 5, 2024
5eca812
compiler warnings
eendebakpt Dec 5, 2024
fedc102
some documentation updates
eendebakpt Dec 5, 2024
c733d25
Update Objects/longobject.c
eendebakpt Dec 5, 2024
829a595
Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 5, 2024
39da0ea
Update Tools/gdb/libpython.py
eendebakpt Dec 5, 2024
5058e53
tests!
eendebakpt Dec 5, 2024
8a3d00f
tests!
eendebakpt Dec 5, 2024
878207a
update _PyLong_IsNonNegativeCompact
eendebakpt Dec 5, 2024
068a16a
Apply suggestions from code review
eendebakpt Dec 11, 2024
a65ec5a
review comments
eendebakpt Dec 11, 2024
38fe25f
8000 Merge branch 'small_int_immortal_v2' of github.com:eendebakpt/cpython…
eendebakpt Dec 11, 2024
32b6e44
spacing
eendebakpt Dec 11, 2024
8543c78
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 11, 2024
e232ca4
Update Tools/gdb/libpython.py
eendebakpt Dec 11, 2024
f1ce753
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 13, 2024
99a2fc7
whitespace
eendebakpt Dec 13, 2024
f6a76b0
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 17, 2024
9894866
Apply suggestions from code review
eendebakpt Dec 17, 2024
7834406
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 18, 2024
d91b6e3
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 20, 2024
ebc7e17
Update Modules/_testcapi/immortal.c
eendebakpt Dec 22, 2024
aaf110b
Update Modules/_testcapi/immortal.c
eendebakpt Dec 22, 2024
8fcc1d0
Update Include/cpython/longintrepr.h
eendebakpt Dec 22, 2024
aff8812
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 22, 2024
ebb0bca
review comments
eendebakpt Dec 22, 2024
8d8e794
include pycore_long.h
eendebakpt Dec 22, 2024
4a07ba1
header
eendebakpt Dec 22, 2024
1d5b2e0
include pycore_long.h
eendebakpt Dec 22, 2024
cfb9120
debug build failure
eendebakpt Dec 22, 2024
b606c09
Merge branch 'main' into small_int_immortal_v2
eendebakpt Dec 23, 2024
b4c8444
fix bug when copying the immortal bit
eendebakpt Dec 23, 2024
3a553d1
test small int test
eendebakpt Dec 23, 2024
62939d1
print
eendebakpt Dec 23, 2024
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
Use int immortality bit for small int check
  • Loading branch information
eendebakpt committed Dec 5, 2024
commit 46396428b45085d9643b99e33f51d1491163cb3c
7 changes: 5 additions & 2 deletions Include/internal/pycore_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);

/* Long value tag bits:
* 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1.
* 2: Reserved for immortality bit
* 2: Reserved for immortality bit. Set to 1 for the small ints
* 3+ Unsigned digit count
*/
#define SIGN_MASK 3
#define SIGN_ZERO 1
#define SIGN_NEGATIVE 2
#define NON_SIZE_BITS 3
#define IMMORTALITY_BIT_MASK (1 << 2)

/* The functions _PyLong_IsCompact and _PyLong_CompactValue are defined
* in Include/cpython/longobject.h, since they need to be inline.
Expand Down Expand Up @@ -262,6 +263,8 @@ _PyLong_SameSign(const PyLongObject *a, const PyLongObject *b)
return (a->long_value.lv_tag & SIGN_MASK) == (b->long_value.lv_tag & SIGN_MASK);
}

#define IMMORTAL_BIT(val) ((_PY_NSMALLNEGINTS <= val < _PY_NSMALLPOSINTS) * IMMORTALITY_BIT_MASK)

#define TAG_FROM_SIGN_AND_SIZE(sign, size) \
((uintptr_t)(1 - (sign)) | ((uintptr_t)(size) << NON_SIZE_BITS))

Expand Down Expand Up @@ -296,7 +299,7 @@ _PyLong_FlipSign(PyLongObject *op) {
.long_value = { \
.lv_tag = TAG_FROM_SIGN_AND_SIZE( \
(val) == 0 ? 0 : ((val) < 0 ? -1 : 1), \
(val) == 0 ? 0 : 1), \
(val) == 0 ? 0 : 1) | IMMORTAL_BIT(val), \
{ ((val) >= 0 ? (val) : -(val)) }, \
} \
}
Expand Down
10 changes: 9 additions & 1 deletion Modules/_testcapi/immortal.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ static PyObject *
test_immortal_small_ints(PyObject *self, PyObject *Py_UNUSED(ignored))
{
for (int i = -5; i <= 256; i++) {
assert(verify_immortality(PyLong_FromLong(i)));
PyObject *obj = PyLong_FromLong(i);
assert(verify_immortality(obj));
int has_int_immortal_bit = ((PyLongObject *)obj)->long_value.lv_tag & (1 << 2);
assert(has_int_immortal_bit);
}
for (int i = 257; i <= 260; i++) {
PyObject *obj = PyLong_FromLong(i);
int has_int_immortal_bit = ((PyLongObject *)obj)->long_value.lv_tag & (1 << 2);
assert(!has_int_immortal_bit);
}
Py_RETURN_NONE;
}
Expand Down
6 changes: 4 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3615,9 +3615,11 @@ static inline int
/// Return 1 if the object is one of the immortal small ints
_long_is_small_int(PyObject *op)
{
return (((PyObject *)(&_PyLong_SMALL_INTS[0]) <= op)
&& (op <= (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS +_PY_NSMALLPOSINTS]));
PyLongObject *long_object = (PyLongObject *)op;

return long_object->long_value.lv_tag | IMMORTALITY_BIT_MASK;
}

static void
long_dealloc(PyObject *self)
{
Expand Down
0