Skip to content

Commit ffc4a43

Browse files
committed
Improve cfg names for fast arithmetic
1 parent 4b1048d commit ffc4a43

File tree

7 files changed

+24
-25
lines changed

7 files changed

+24
-25
lines changed

build.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::env;
33
fn main() {
44
println!("cargo:rerun-if-changed=build.rs");
55

6-
println!("cargo:rustc-check-cfg=cfg(arithmetic32)");
7-
println!("cargo:rustc-check-cfg=cfg(arithmetic64)");
6+
println!("cargo:rustc-check-cfg=cfg(fast_arithmetic, values(\"32\", \"64\"))");
87

98
// Decide ideal limb width for arithmetic in the float parser and string
109
// parser.
@@ -23,8 +22,8 @@ fn main() {
2322
// pointer width. Examples include aarch64-unknown-linux-gnu_ilp32 and
2423
// x86_64-unknown-linux-gnux32. So our choice of limb width is not
2524
// equivalent to using usize everywhere.
26-
println!("cargo:rustc-cfg=arithmetic64");
25+
println!("cargo:rustc-cfg=fast_arithmetic=\"64\"");
2726
} else {
28-
println!("cargo:rustc-cfg=arithmetic32");
27+
println!("cargo:rustc-cfg=fast_arithmetic=\"32\"");
2928
}
3029
}

src/lexical/large_powers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
//! Precalculated large powers for limbs.
44
5-
#[cfg(arithmetic32)]
5+
#[cfg(fast_arithmetic = "32")]
66
pub(crate) use super::large_powers32::*;
77

8-
#[cfg(arithmetic64)]
8+
#[cfg(fast_arithmetic = "64")]
99
pub(crate) use super::large_powers64::*;

src/lexical/math.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,29 @@ use core::{cmp, iter, mem};
3737
// sparc64 (`UMUL` only supported double-word arguments).
3838

3939
// 32-BIT LIMB
40-
#[cfg(arithmetic32)]
40+
#[cfg(fast_arithmetic = "32")]
4141
pub type Limb = u32;
4242

43-
#[cfg(arithmetic32)]
43+
#[cfg(fast_arithmetic = "32")]
4444
pub const POW5_LIMB: &[Limb] = &POW5_32;
4545

46-
#[cfg(arithmetic32)]
46+
#[cfg(fast_arithmetic = "32")]
4747
pub const POW10_LIMB: &[Limb] = &POW10_32;
4848

49-
#[cfg(arithmetic32)]
49+
#[cfg(fast_arithmetic = "32")]
5050
type Wide = u64;
5151

5252
// 64-BIT LIMB
53-
#[cfg(arithmetic64)]
53+
#[cfg(fast_arithmetic = "64")]
5454
pub type Limb = u64;
5555

56-
#[cfg(arithmetic64)]
56+
#[cfg(fast_arithmetic = "64")]
5757
pub const POW5_LIMB: &[Limb] = &POW5_64;
5858

59-
#[cfg(arithmetic64)]
59+
#[cfg(fast_arithmetic = "64")]
6060
pub const POW10_LIMB: &[Limb] = &POW10_64;
6161

62-
#[cfg(arithmetic64)]
62+
#[cfg(fast_arithmetic = "64")]
6363
type Wide = u128;
6464

6565
/// Cast to limb type.
@@ -79,14 +79,14 @@ fn as_wide<T: Integer>(t: T) -> Wide {
7979

8080
/// Split u64 into limbs, in little-endian order.
8181
#[inline]
82-
#[cfg(arithmetic32)]
82+
#[cfg(fast_arithmetic = "32")]
8383
fn split_u64(x: u64) -> [Limb; 2] {
8484
[as_limb(x), as_limb(x >> 32)]
8585
}
8686

8787
/// Split u64 into limbs, in little-endian order.
8888
#[inline]
89-
#[cfg(arithmetic64)]
89+
#[cfg(fast_arithmetic = "64")]
9090
fn split_u64(x: u64) -> [Limb; 1] {
9191
[as_limb(x)]
9292
}

src/lexical/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ pub(crate) mod rounding;
2828
mod shift;
2929
mod small_powers;
3030

31-
#[cfg(arithmetic32)]
31+
#[cfg(fast_arithmetic = "32")]
3232
mod large_powers32;
3333

34-
#[cfg(arithmetic64)]
34+
#[cfg(fast_arithmetic = "64")]
3535
mod large_powers64;
3636

3737
// API

src/lexical/small_powers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
//! Pre-computed small powers.
44
55
// 32 BIT
6-
#[cfg(arithmetic32)]
6+
#[cfg(fast_arithmetic = "32")]
77
pub(crate) const POW5_32: [u32; 14] = [
88
1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625,
99
1220703125,
1010
];
1111

12-
#[cfg(arithmetic32)]
12+
#[cfg(fast_arithmetic = "32")]
1313
pub(crate) const POW10_32: [u32; 10] = [
1414
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000,
1515
];
1616

1717
// 64 BIT
18-
#[cfg(arithmetic64)]
18+
#[cfg(fast_arithmetic = "64")]
1919
pub(crate) const POW5_64: [u64; 28] = [
2020
1,
2121
5,

src/read.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ impl<'a> SliceRead<'a> {
446446
// benchmarks and it's cross-platform, so probably the right fit.
447447
// [1]: https://groups.google.com/forum/#!original/comp.lang.c/2HtQXvg7iKc/xOJeipH6KLMJ
448448

449-
#[cfg(arithmetic64)]
449+
#[cfg(fast_arithmetic = "64")]
450450
type Chunk = u64;
451-
#[cfg(arithmetic32)]
451+
#[cfg(fast_arithmetic = "32")]
452452
type Chunk = u32;
453453

454454
const STEP: usize = mem::size_of::<Chunk>();

tests/lexical/math.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ impl Math for Bigint {
1818
}
1919
}
2020

21-
#[cfg(arithmetic32)]
21+
#[cfg(fast_arithmetic = "32")]
2222
pub(crate) fn from_u32(x: &[u32]) -> Vec<Limb> {
2323
x.iter().cloned().collect()
2424
}
2525

26-
#[cfg(arithmetic64)]
26+
#[cfg(fast_arithmetic = "64")]
2727
pub(crate) fn from_u32(x: &[u32]) -> Vec<Limb> {
2828
let mut v = Vec::<Limb>::default();
2929
for xi in x.chunks(2) {

0 commit comments

Comments
 (0)