Skip to content

Commit c754f03

Browse files
osiewiczPiotr Osiewicz
authored andcommitted
Remove limb_width32 and limb_width64 features
Moved dispatch directly into the type system.
1 parent 716cb8f commit c754f03

File tree

4 files changed

+40
-68
lines changed

4 files changed

+40
-68
lines changed

build.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/lexical/math.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
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;
109
use super::num::*;
1110
use super::small_powers::*;
1211
use alloc::vec::Vec;
@@ -36,31 +35,48 @@ use core::{cmp, iter, mem};
3635
// requiring software emulation.
3736
// sparc64 (`UMUL` only supported double-word arguments).
3837

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+
}
4846

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+
}
5158

5259
// 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+
}
5869

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;
6174

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;
6480

6581
/// Cast to limb type.
6682
#[inline]
@@ -391,7 +407,7 @@ mod small {
391407
use super::large::KARATSUBA_CUTOFF;
392408

393409
let small_powers = POW5_LIMB;
394-
let large_powers = large_powers::POW5;
410+
let large_powers = LARGE_POWERS;
395411

396412
if n == 0 {
397413
// No exponent, just return.

src/lexical/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@ mod digit;
2020
mod errors;
2121
pub(crate) mod exponent;
2222
pub(crate) mod float;
23-
mod large_powers;
23+
mod large_powers32;
24+
mod large_powers64;
2425
pub(crate) mod math;
2526
pub(crate) mod num;
2627
pub(crate) mod parse;
2728
pub(crate) mod rounding;
2829
mod shift;
2930
mod small_powers;
3031

31-
#[cfg(limb_width_32)]
32-
mod large_powers32;
33-
34-
#[cfg(limb_width_64)]
35-
mod large_powers64;
36-
3732
// API
3833
pub use self::parse::{parse_concise_float, parse_truncated_float};

src/lexical/small_powers.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
//! Pre-computed small powers.
44
55
// 32 BIT
6-
#[cfg(limb_width_32)]
76
pub(crate) const POW5_32: [u32; 14] = [
87
1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625,
98
1220703125,
109
];
1110

12-
#[cfg(limb_width_32)]
1311
pub(crate) const POW10_32: [u32; 10] = [
1412
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000,
1513
];
1614

1715
// 64 BIT
18-
#[cfg(limb_width_64)]
1916
pub(crate) const POW5_64: [u64; 28] = [
2017
1,
2118
5,

0 commit comments

Comments
 (0)