mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
GH-101291: Rearrange the size bits in PyLongObject (GH-102464)
* Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
This commit is contained in:
parent
713df2c534
commit
7559f5fda9
25 changed files with 982 additions and 898 deletions
|
@ -345,8 +345,7 @@ dummy_func(
|
|||
DEOPT_IF(!PyList_CheckExact(list), BINARY_SUBSCR);
|
||||
|
||||
// Deopt unless 0 <= sub < PyList_Size(list)
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
|
||||
DEOPT_IF(!_PyLong_IsNonNegativeCompact((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);
|
||||
|
@ -363,8 +362,7 @@ dummy_func(
|
|||
DEOPT_IF(!PyTuple_CheckExact(tuple), BINARY_SUBSCR);
|
||||
|
||||
// Deopt unless 0 <= sub < PyTuple_Size(list)
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
|
||||
DEOPT_IF(!_PyLong_IsNonNegativeCompact((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);
|
||||
|
@ -456,7 +454,7 @@ dummy_func(
|
|||
DEOPT_IF(!PyList_CheckExact(list), STORE_SUBSCR);
|
||||
|
||||
// Ensure nonnegative, zero-or-one-digit ints.
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), STORE_SUBSCR);
|
||||
DEOPT_IF(!_PyLong_IsNonNegativeCompact((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);
|
||||
|
@ -1755,12 +1753,13 @@ dummy_func(
|
|||
assert(cframe.use_tracing == 0);
|
||||
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF((size_t)(Py_SIZE(left) + 1) > 2, COMPARE_AND_BRANCH);
|
||||
DEOPT_IF((size_t)(Py_SIZE(right) + 1) > 2, COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)left), COMPARE_AND_BRANCH);
|
||||
DEOPT_IF(!_PyLong_IsCompact((PyLongObject *)right), COMPARE_AND_BRANCH);
|
||||
STAT_INC(COMPARE_AND_BRANCH, hit);
|
||||
assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
|
||||
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->long_value.ob_digit[0];
|
||||
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->long_value.ob_digit[0];
|
||||
assert(_PyLong_DigitCount((PyLongObject *)left) <= 1 &&
|
||||
_PyLong_DigitCount((PyLongObject *)right) <= 1);
|
||||
Py_ssize_t ileft = _PyLong_CompactValue((PyLongObject *)left);
|
||||
Py_ssize_t iright = _PyLong_CompactValue((PyLongObject *)right);
|
||||
// 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
|
||||
int sign_ish = COMPARISON_BIT(ileft, iright);
|
||||
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue