diff options
| author | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 15:51:55 +0000 |
|---|---|---|
| committer | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 15:51:55 +0000 |
| commit | 753b6be78c735e3e80acc058e8b2375092032bb6 (patch) | |
| tree | a9453cf3fcf8635d7f5b255706adb992273e0582 /Include/pyport.h | |
| parent | f373e2ab2b24f52a2f4bcf73fc6846e3bf3b80d2 (diff) | |
| download | cpython-753b6be78c735e3e80acc058e8b2375092032bb6.tar.gz | |
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Backport of r70459.
Diffstat (limited to 'Include/pyport.h')
| -rw-r--r-- | Include/pyport.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Include/pyport.h b/Include/pyport.h index 54411f2597..53352f16f6 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -80,6 +80,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 |
