aboutsummaryrefslogtreecommitdiff
path: root/py/mpz.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-03-28 21:45:57 +0000
committerDamien George <damien.p.george@gmail.com>2015-04-03 14:11:13 +0100
commit3f327cc4c61bf7d55a0299009d5f6d3f38e66937 (patch)
tree8a8fe9b8a3cff84e05b4eb4ee2349b4fd4ad2948 /py/mpz.h
parent567184e21e9a6a37fd71153a43874dec7a3f5e0c (diff)
py: Allow MPZ_DIG_SIZE to be optionally configured by a port.
Diffstat (limited to 'py/mpz.h')
-rw-r--r--py/mpz.h33
1 files changed, 24 insertions, 9 deletions
diff --git a/py/mpz.h b/py/mpz.h
index 6bcbc0752..71649aa7f 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -39,22 +39,37 @@
// unsigned versions.
//
// MPZ_DIG_SIZE can be between 4 and 8*sizeof(mpz_dig_t), but it makes most
-// sense to have it as large as possible. Below, the type is auto-detected
-// depending on the machine, but it (and MPZ_DIG_SIZE) can be freely changed so
-// long as the constraints mentioned above are met.
+// sense to have it as large as possible. If MPZ_DIG_SIZE is not already
+// defined then it is auto-detected below, depending on the machine. The types
+// are then set based on the value of MPZ_DIG_SIZE (although they can be freely
+// changed so long as the constraints mentioned above are met).
-#if defined(__x86_64__) || defined(_WIN64)
-// 64-bit machine, using 32-bit storage for digits
+#ifndef MPZ_DIG_SIZE
+ #if defined(__x86_64__) || defined(_WIN64)
+ // 64-bit machine, using 32-bit storage for digits
+ #define MPZ_DIG_SIZE (32)
+ #else
+ // default: 32-bit machine, using 16-bit storage for digits
+ #define MPZ_DIG_SIZE (16)
+ #endif
+#endif
+
+#if MPZ_DIG_SIZE > 16
typedef uint32_t mpz_dig_t;
typedef uint64_t mpz_dbl_dig_t;
typedef int64_t mpz_dbl_dig_signed_t;
-#define MPZ_DIG_SIZE (32)
-#else
-// 32-bit machine, using 16-bit storage for digits
+#elif MPZ_DIG_SIZE > 8
typedef uint16_t mpz_dig_t;
typedef uint32_t mpz_dbl_dig_t;
typedef int32_t mpz_dbl_dig_signed_t;
-#define MPZ_DIG_SIZE (16)
+#elif MPZ_DIG_SIZE > 4
+typedef uint8_t mpz_dig_t;
+typedef uint16_t mpz_dbl_dig_t;
+typedef int16_t mpz_dbl_dig_signed_t;
+#else
+typedef uint8_t mpz_dig_t;
+typedef uint8_t mpz_dbl_dig_t;
+typedef int8_t mpz_dbl_dig_signed_t;
#endif
#ifdef _WIN64