summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-03-18 20:06:12 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-03-18 20:06:12 (GMT)
commitbd7926478de92a2a0ef4440e1a9ae61b706a80d2 (patch)
treef92ef0133e96195e1875cc74b046474aeb7be155 /Include/pyport.h
parente7f45b8e5948d7367c3754b0506b082d1296138f (diff)
downloadcpython-bd7926478de92a2a0ef4440e1a9ae61b706a80d2.zip
cpython-bd7926478de92a2a0ef4440e1a9ae61b706a80d2.tar.gz
cpython-bd7926478de92a2a0ef4440e1a9ae61b706a80d2.tar.bz2
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
- new configure option --enable-big-digits - new structseq sys.int_info giving information about the internal format By default, 30-bit digits are enabled on 64-bit machines but disabled on 32-bit machines.
Diffstat (limited to 'Include/pyport.h')
-rw-r--r--Include/pyport.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index 97cc68d..9449b5f 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -69,6 +69,57 @@ Used in: PY_LONG_LONG
#endif
#endif /* HAVE_LONG_LONG */
+/* a build with 30-bit digits for Python long integers needs an exact-width
+ * 32-bit unsigned integer type to store those digits. (We could just use
+ * type 'unsigned long', but that would be wasteful on a system where longs
+ * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
+ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
+ * However, it doesn't set HAVE_UINT32_T, so we do that here.
+ */
+#if (defined UINT32_MAX || defined uint32_t)
+#ifndef PY_UINT32_T
+#define HAVE_UINT32_T 1
+#define PY_UINT32_T uint32_t
+#endif
+#endif
+
+/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
+ * long integer implementation, when 30-bit digits are enabled.
+ */
+#if (defined UINT64_MAX || defined uint64_t)
+#ifndef PY_UINT64_T
+#define HAVE_UINT64_T 1
+#define PY_UINT64_T uint64_t
+#endif
+#endif
+
+/* Signed variants of the above */
+#if (defined INT32_MAX || defined int32_t)
+#ifndef PY_INT32_T
+#define HAVE_INT32_T 1
+#define PY_INT32_T int32_t
+#endif
+#endif
+#if (defined INT64_MAX || defined int64_t)
+#ifndef PY_INT64_T
+#define HAVE_INT64_T 1
+#define PY_INT64_T int64_t
+#endif
+#endif
+
+/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
+ the necessary integer types are available, and we're on a 64-bit platform
+ (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
+
+#ifndef PYLONG_BITS_IN_DIGIT
+#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
+ defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
+#define PYLONG_BITS_IN_DIGIT 30
+#else
+#define PYLONG_BITS_IN_DIGIT 15
+#endif
+#endif
+
/* uintptr_t is the C9X name for an unsigned integral type such that a
* legitimate void* can be cast to uintptr_t and then back to void* again
* without loss of information. Similarly for intptr_t, wrt a signed