10000 Expose inline versions of _PyLong_IsCompact & _PyLong_CompactValue by encukou · Pull Request #16 · faster-cpython/cpython · GitHub
[go: up one dir, main page]

Skip to content

Expose inline versions of _PyLong_IsCompact & _PyLong_CompactValue #16

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
PyLong, not PyInt
  • Loading branch information
encukou committed May 15, 2023
commit 3bd201913a09fd1976fb5ed70b85e9a20be8aebc
6 changes: 3 additions & 3 deletions Include/cpython/longintrepr.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ _PyLong_IsCompact(const PyLongObject* op) {
return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
}

#define PyUnstable_Int_IsCompact _PyLong_IsCompact
#define PyUnstable_Long_IsCompact _PyLong_IsCompact

static inline Py_ssize_t
_PyLong_CompactValue(const PyLongObject *op)
{
assert(PyLong_Check(op));
assert(PyUnstable_Int_IsCompact(op));
assert(PyUnstable_Long_IsCompact(op));
Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
return sign * (Py_ssize_t)op->long_value.ob_digit[0];
}

#define PyUnstable_Int_CompactValue _PyLong_CompactValue
#define PyUnstable_Long_CompactValue _PyLong_CompactValue


#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/longobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ PyAPI_FUNC(PyObject *) _PyLong_Rshift(PyObject *, size_t);
PyAPI_FUNC(PyObject *) _PyLong_Lshift(PyObject *, size_t);


PyAPI_FUNC(int) PyUnstable_Int_IsCompact(const PyLongObject* op);
PyAPI_FUNC(Py_ssize_t) PyUnstable_Int_CompactValue(const PyLongObject* op);
PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);
PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);

8 changes: 4 additions & 4 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6367,16 +6367,16 @@ _PyLong_FiniTypes(PyInterpreterState *interp)
_PyStructSequence_FiniBuiltin(interp, &Int_InfoType);
}

#undef PyUnstable_Int_IsCompact
#undef PyUnstable_Long_IsCompact

int
PyUnstable_Int_IsCompact(const PyLongObject* op) {
PyUnstable_Long_IsCompact(const PyLongObject* op) {
return _PyLong_IsCompact(op);
}

#undef PyUnstable_Int_CompactValue
#undef PyUnstable_Long_CompactValue

Py_ssize_t
PyUnstable_Int_CompactValue(const PyLongObject* op) {
PyUnstable_Long_CompactValue(const PyLongObject* op) {
return _PyLong_CompactValue(op);
}
0