Skip to content

Commit dcbf804

Browse files
committed
60 bits variant for long type
1 parent e45d535 commit dcbf804

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Include/cpython/longintrepr.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,21 @@ typedef long stwodigits; /* signed variant of twodigits */
5555
#define PyLong_SHIFT 15
5656
#define _PyLong_DECIMAL_SHIFT 4 /* max(e such that 10**e fits in a digit) */
5757
#define _PyLong_DECIMAL_BASE ((digit)10000) /* 10 ** DECIMAL_SHIFT */
58+
#elif PYLONG_BITS_IN_DIGIT == 60
59+
/* 60-bit digits require 128-bit twodigits type for proper arithmetic */
60+
/* This implementation requires compiler support for 128-bit integers */
61+
#if !defined(__SIZEOF_INT128__) || __SIZEOF_INT128__ != 16
62+
#error "60-bit digits require 128-bit integer support (__int128)"
63+
#endif
64+
typedef uint64_t digit;
65+
typedef int64_t sdigit; /* signed variant of digit */
66+
typedef unsigned __int128 twodigits;
67+
typedef __int128 stwodigits; /* signed variant of twodigits */
68+
#define PyLong_SHIFT 60
69+
#define _PyLong_DECIMAL_SHIFT 18 /* max(e such that 10**e fits in a digit) */
70+
#define _PyLong_DECIMAL_BASE ((digit)1000000000000000000) /* 10 ** DECIMAL_SHIFT */
5871
#else
59-
#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
72+
#error "PYLONG_BITS_IN_DIGIT should be 15, 30, or 60"
6073
#endif
6174
#define PyLong_BASE ((digit)1 << PyLong_SHIFT)
6275
#define PyLong_MASK ((digit)(PyLong_BASE - 1))

0 commit comments

Comments
 (0)