-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-127119: Faster check for small ints in long_dealloc #127620
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 8 commits
cfb70cb
426dd09
4639642
d9c26d3
2f73d47
3b6e1fe
03184a7
5eca812
fedc102
c733d25
829a595
39da0ea
5058e53
8a3d00f
878207a
068a16a
a65ec5a
38fe25f
32b6e44
8543c78
e232ca4
f1ce753
99a2fc7
f6a76b0
9894866
7834406
d91b6e3
ebc7e17
aaf110b
8fcc1d0
aff8812
ebb0bca
8d8e794
4a07ba1
1d5b2e0
cfb9120
b606c09
b4c8444
f76c0e2
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 |
---|---|---|
|
@@ -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. | ||
|
@@ -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) && (val < _PY_NSMALLPOSINTS)) * IMMORTALITY_BIT_MASK) | ||
|
||
#define TAG_FROM_SIGN_AND_SIZE(sign, size) \ | ||
((uintptr_t)(1 - (sign)) | ((uintptr_t)(size) << NON_SIZE_BITS)) | ||
|
||
|
@@ -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), \ | ||
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.
|
||
{ ((val) >= 0 ? (val) : -(val)) }, \ | ||
} \ | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Slightly optimize the :class:`int` deallocator. | ||
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. Maybe include the benchmarks results (it's a 4% improvement which is still noticable IMO). You should mention that it only concerns PGO builds as well. |
Uh oh!
There was an error while loading. Please reload this page.