66//! buffers, so for a `vec![0, 1, 2, 3]`, `3` is the most significant limb,
77//! and `0` is the least significant limb.
88
9+ use super :: large_powers;
910use super :: num:: * ;
1011use super :: small_powers:: * ;
1112use alloc:: vec:: Vec ;
@@ -35,58 +36,31 @@ use core::{cmp, iter, mem};
3536// requiring software emulation.
3637// sparc64 (`UMUL` only supported double-word arguments).
3738
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- }
46-
4739// 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- }
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 ;
48+
49+ #[ cfg( limb_width_32) ]
50+ type Wide = u64 ;
5851
5952// 64-BIT LIMB
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- }
53+ #[ cfg( limb_width_64) ]
54+ pub type Limb = u64 ;
55+
56+ #[ cfg( limb_width_64) ]
57+ pub const POW5_LIMB : & [ Limb ] = & POW5_64 ;
58+
59+ #[ cfg( limb_width_64) ]
60+ pub const POW10_LIMB : & [ Limb ] = & POW10_64 ;
6961
70- #[ cfg( any(
71- target_arch = "aarch64" ,
72- target_arch = "mips64" ,
73- target_arch = "powerpc64" ,
74- target_arch = "x86_64"
75- ) ) ]
76- type PlatformLimbConfig = LimbConfig64 ;
77- #[ cfg( not( any(
78- target_arch = "aarch64" ,
79- target_arch = "mips64" ,
80- target_arch = "powerpc64" ,
81- target_arch = "x86_64"
82- ) ) ) ]
83- type PlatformLimbConfig = LimbConfig32 ;
84-
85- pub type Limb = <PlatformLimbConfig as LimbConfig >:: Limb ;
86- type Wide = <PlatformLimbConfig as LimbConfig >:: Wide ;
87- pub const POW5_LIMB : & [ Limb ] = PlatformLimbConfig :: POW5_LIMB ;
88- pub const POW10_LIMB : & [ Limb ] = PlatformLimbConfig :: POW10_LIMB ;
89- const LARGE_POWERS : & ' static [ & ' static [ Limb ] ] = PlatformLimbConfig :: LARGE_POWERS ;
62+ #[ cfg( limb_width_64) ]
63+ type Wide = u128 ;
9064
9165/// Cast to limb type.
9266#[ inline]
@@ -105,24 +79,14 @@ fn as_wide<T: Integer>(t: T) -> Wide {
10579
10680/// Split u64 into limbs, in little-endian order.
10781#[ inline]
108- #[ cfg( not( any(
109- target_arch = "aarch64" ,
110- target_arch = "mips64" ,
111- target_arch = "powerpc64" ,
112- target_arch = "x86_64"
113- ) ) ) ]
82+ #[ cfg( limb_width_32) ]
11483fn split_u64 ( x : u64 ) -> [ Limb ; 2 ] {
11584 [ as_limb ( x) , as_limb ( x >> 32 ) ]
11685}
11786
11887/// Split u64 into limbs, in little-endian order.
11988#[ inline]
120- #[ cfg( any(
121- target_arch = "aarch64" ,
122- target_arch = "mips64" ,
123- target_arch = "powerpc64" ,
124- target_arch = "x86_64"
125- ) ) ]
89+ #[ cfg( limb_width_64) ]
12690fn split_u64 ( x : u64 ) -> [ Limb ; 1 ] {
12791 [ as_limb ( x) ]
12892}
@@ -427,7 +391,7 @@ mod small {
427391 use super :: large:: KARATSUBA_CUTOFF ;
428392
429393 let small_powers = POW5_LIMB ;
430- let large_powers = LARGE_POWERS ;
394+ let large_powers = large_powers :: POW5 ;
431395
432396 if n == 0 {
433397 // No exponent, just return.
0 commit comments