diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-08-04 00:40:27 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2021-08-11 20:59:52 +0200 |
| commit | 2323ca16225066187958a003301be6fd3bc181fe (patch) | |
| tree | 3e262c9877e6139780d8fe72ed841fe1e7b9c800 | |
| parent | fc0a92f8ace0e8a6f42d7666b8d4cb92cfb0df3e (diff) | |
big: Add `MATH_BIG_FORCE_64/32_BIT` flags.
| -rw-r--r-- | core/math/big/basic.odin | 2 | ||||
| -rw-r--r-- | core/math/big/common.odin | 8 | ||||
| -rw-r--r-- | core/math/big/helpers.odin | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/core/math/big/basic.odin b/core/math/big/basic.odin index 5470bf917..69520a76c 100644 --- a/core/math/big/basic.odin +++ b/core/math/big/basic.odin @@ -1672,7 +1672,7 @@ _int_gcd_lcm :: proc(res_gcd, res_lcm, a, b: ^Int) -> (err: Error) { }
-when size_of(rawptr) == 8 {
+when MATH_BIG_FORCE_64_BIT || (!MATH_BIG_FORCE_32_BIT && size_of(rawptr) == 8) {
_factorial_table := [35]_WORD{
/* f(00): */ 1,
/* f(01): */ 1,
diff --git a/core/math/big/common.odin b/core/math/big/common.odin index 7943c0e4b..1b76c9520 100644 --- a/core/math/big/common.odin +++ b/core/math/big/common.odin @@ -19,6 +19,12 @@ import "core:intrinsics" /* Tunables */ + +MATH_BIG_FORCE_64_BIT :: false; +MATH_BIG_FORCE_32_BIT :: false; +when (MATH_BIG_FORCE_32_BIT && MATH_BIG_FORCE_64_BIT) { #panic("Cannot force 32-bit and 64-bit big backend simultaneously."); }; + + _LOW_MEMORY :: #config(BIGINT_SMALL_MEMORY, false); when _LOW_MEMORY { _DEFAULT_DIGIT_COUNT :: 8; @@ -140,7 +146,7 @@ _MIN_DIGIT_COUNT :: max(3, ((size_of(u128) + _DIGIT_BITS) - 1) / _DIGIT_BITS); _MAX_BIT_COUNT :: (max(int) - 2); _MAX_DIGIT_COUNT :: _MAX_BIT_COUNT / _DIGIT_BITS; -when size_of(rawptr) == 8 { +when MATH_BIG_FORCE_64_BIT || (!MATH_BIG_FORCE_32_BIT && size_of(rawptr) == 8) { /* We can use u128 as an intermediary. */ diff --git a/core/math/big/helpers.odin b/core/math/big/helpers.odin index d4b5d0220..a326b960b 100644 --- a/core/math/big/helpers.odin +++ b/core/math/big/helpers.odin @@ -549,7 +549,7 @@ int_random_digit :: proc(r: ^rnd.Rand = nil) -> (res: DIGIT) { when _DIGIT_BITS == 60 { // DIGIT = u64 return DIGIT(rnd.uint64(r)) & _MASK; } else when _DIGIT_BITS == 28 { // DIGIT = u32 - return DIGIT(rand.uint32(r)) & _MASK; + return DIGIT(rnd.uint32(r)) & _MASK; } else { panic("Unsupported DIGIT size."); } |