|
6 | 6 | //! buffers, so for a `vec![0, 1, 2, 3]`, `3` is the most significant limb,
|
7 | 7 | //! and `0` is the least significant limb.
|
8 | 8 |
|
9 |
| -use super::large_powers; |
10 | 9 | use super::num::*;
|
11 | 10 | use super::small_powers::*;
|
12 | 11 | use alloc::vec::Vec;
|
@@ -36,31 +35,48 @@ use core::{cmp, iter, mem};
|
36 | 35 | // requiring software emulation.
|
37 | 36 | // sparc64 (`UMUL` only supported double-word arguments).
|
38 | 37 |
|
39 |
| -// 32-BIT LIMB |
40 |
| -#[cfg(limb_width_32)] |
41 |
| -pub type Limb = u32; |
42 |
| - |
43 |
| -#[cfg(limb_width_32)] |
44 |
| -pub const POW5_LIMB: &[Limb] = &POW5_32; |
45 |
| - |
46 |
| -#[cfg(limb_width_32)] |
47 |
| -pub const POW10_LIMB: &[Limb] = &POW10_32; |
| 38 | +#[doc(hidden)] |
| 39 | +pub trait LimbConfig { |
| 40 | + type Limb: 'static; |
| 41 | + type Wide: 'static; |
| 42 | + const POW5_LIMB: &'static [Self::Limb]; |
| 43 | + const POW10_LIMB: &'static [Self::Limb]; |
| 44 | + const LARGE_POWERS: &'static [&'static [Self::Limb]]; |
| 45 | +} |
48 | 46 |
|
49 |
| -#[cfg(limb_width_32)] |
50 |
| -type Wide = u64; |
| 47 | +// 32-BIT LIMB |
| 48 | +#[doc(hidden)] |
| 49 | +pub struct LimbConfig32; |
| 50 | + |
| 51 | +impl LimbConfig for LimbConfig32 { |
| 52 | + type Limb = u32; |
| 53 | + type Wide = u64; |
| 54 | + const POW5_LIMB: &'static [Self::Limb] = &POW5_32; |
| 55 | + const POW10_LIMB: &'static [Self::Limb] = &POW10_32; |
| 56 | + const LARGE_POWERS: &'static [&'static [Self::Limb]] = &super::large_powers32::POW5; |
| 57 | +} |
51 | 58 |
|
52 | 59 | // 64-BIT LIMB
|
53 |
| -#[cfg(limb_width_64)] |
54 |
| -pub type Limb = u64; |
55 |
| - |
56 |
| -#[cfg(limb_width_64)] |
57 |
| -pub const POW5_LIMB: &[Limb] = &POW5_64; |
| 60 | +#[doc(hidden)] |
| 61 | +pub struct LimbConfig64; |
| 62 | +impl LimbConfig for LimbConfig64 { |
| 63 | + type Limb = u64; |
| 64 | + type Wide = u128; |
| 65 | + const POW5_LIMB: &'static [Self::Limb] = &POW5_64; |
| 66 | + const POW10_LIMB: &'static [Self::Limb] = &POW10_64; |
| 67 | + const LARGE_POWERS: &'static [&'static [Self::Limb]] = &super::large_powers64::POW5; |
| 68 | +} |
58 | 69 |
|
59 |
| -#[cfg(limb_width_64)] |
60 |
| -pub const POW10_LIMB: &[Limb] = &POW10_64; |
| 70 | +#[cfg(any(target_arch = "aarch64", target_arch = "mips64", target_arch = "powerpc64", target_arch = x86_64))] |
| 71 | +type PlatformLimbConfig = LimbConfig64; |
| 72 | +#[cfg(not(any(target_arch = "aarch64", target_arch = "mips64", target_arch = "powerpc64", target_arch = x86_64)))] |
| 73 | +type PlatformLimbConfig = LimbConfig32; |
61 | 74 |
|
62 |
| -#[cfg(limb_width_64)] |
63 |
| -type Wide = u128; |
| 75 | +pub type Limb = <PlatformLimbConfig as LimbConfig>::Limb; |
| 76 | +type Wide = <PlatformLimbConfig as LimbConfig>::Wide; |
| 77 | +pub const POW5_LIMB: &[Limb] = PlatformLimbConfig::POW5_LIMB; |
| 78 | +pub const POW10_LIMB: &[Limb] = PlatformLimbConfig::POW10_LIMB; |
| 79 | +const LARGE_POWERS: &'static [&'static [Limb]] = PlatformLimbConfig::LARGE_POWERS; |
64 | 80 |
|
65 | 81 | /// Cast to limb type.
|
66 | 82 | #[inline]
|
@@ -391,7 +407,7 @@ mod small {
|
391 | 407 | use super::large::KARATSUBA_CUTOFF;
|
392 | 408 |
|
393 | 409 | let small_powers = POW5_LIMB;
|
394 |
| - let large_powers = large_powers::POW5; |
| 410 | + let large_powers = LARGE_POWERS; |
395 | 411 |
|
396 | 412 | if n == 0 {
|
397 | 413 | // No exponent, just return.
|
|
0 commit comments