summaryrefslogtreecommitdiffstats
path: root/Include/cpython/longintrepr.h
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-05-21 13:45:48 (GMT)
committerGitHub <noreply@github.com>2023-05-21 13:45:48 (GMT)
commit93923793f602ea9117f13bfac8cbe01a864eeb01 (patch)
tree33657460417c68e16479212566385144a0d9d30a /Include/cpython/longintrepr.h
parentab71acd67b5b09926498b8c7f855bdb28ac0ec2f (diff)
downloadcpython-93923793f602ea9117f13bfac8cbe01a864eeb01.zip
cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.tar.gz
cpython-93923793f602ea9117f13bfac8cbe01a864eeb01.tar.bz2
GH-101291: Add low level, unstable API for pylong (GH-101685)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Include/cpython/longintrepr.h')
-rw-r--r--Include/cpython/longintrepr.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/Include/cpython/longintrepr.h b/Include/cpython/longintrepr.h
index c4cf820..0f56993 100644
--- a/Include/cpython/longintrepr.h
+++ b/Include/cpython/longintrepr.h
@@ -98,6 +98,32 @@ PyAPI_FUNC(PyLongObject *)
_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits);
+/* Inline some internals for speed. These should be in pycore_long.h
+ * if user code didn't need them inlined. */
+
+#define _PyLong_SIGN_MASK 3
+#define _PyLong_NON_SIZE_BITS 3
+
+static inline int
+_PyLong_IsCompact(const PyLongObject* op) {
+ assert(PyLong_Check(op));
+ return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
+}
+
+#define PyUnstable_Long_IsCompact _PyLong_IsCompact
+
+static inline Py_ssize_t
+_PyLong_CompactValue(const PyLongObject *op)
+{
+ assert(PyLong_Check(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_Long_CompactValue _PyLong_CompactValue
+
+
#ifdef __cplusplus
}
#endif