From ffc4a43453029cdc5603cfe3ef08414488fd45de Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 23 Aug 2024 12:41:44 -0700 Subject: [PATCH] Improve cfg names for fast arithmetic --- build.rs | 7 +++---- src/lexical/large_powers.rs | 4 ++-- src/lexical/math.rs | 20 ++++++++++---------- src/lexical/mod.rs | 4 ++-- src/lexical/small_powers.rs | 6 +++--- src/read.rs | 4 ++-- tests/lexical/math.rs | 4 ++-- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/build.rs b/build.rs index 2b7815ee4..29907eaf7 100644 --- a/build.rs +++ b/build.rs @@ -3,8 +3,7 @@ use std::env; fn main() { println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rustc-check-cfg=cfg(arithmetic32)"); - println!("cargo:rustc-check-cfg=cfg(arithmetic64)"); + println!("cargo:rustc-check-cfg=cfg(fast_arithmetic, values(\"32\", \"64\"))"); // Decide ideal limb width for arithmetic in the float parser and string // parser. @@ -23,8 +22,8 @@ fn main() { // pointer width. Examples include aarch64-unknown-linux-gnu_ilp32 and // x86_64-unknown-linux-gnux32. So our choice of limb width is not // equivalent to using usize everywhere. - println!("cargo:rustc-cfg=arithmetic64"); + println!("cargo:rustc-cfg=fast_arithmetic=\"64\""); } else { - println!("cargo:rustc-cfg=arithmetic32"); + println!("cargo:rustc-cfg=fast_arithmetic=\"32\""); } } diff --git a/src/lexical/large_powers.rs b/src/lexical/large_powers.rs index f96ea79c1..af2c8a6a9 100644 --- a/src/lexical/large_powers.rs +++ b/src/lexical/large_powers.rs @@ -2,8 +2,8 @@ //! Precalculated large powers for limbs. -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub(crate) use super::large_powers32::*; -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] pub(crate) use super::large_powers64::*; diff --git a/src/lexical/math.rs b/src/lexical/math.rs index a8d1d294a..adacb42e1 100644 --- a/src/lexical/math.rs +++ b/src/lexical/math.rs @@ -37,29 +37,29 @@ use core::{cmp, iter, mem}; // sparc64 (`UMUL` only supported double-word arguments). // 32-BIT LIMB -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub type Limb = u32; -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub const POW5_LIMB: &[Limb] = &POW5_32; -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub const POW10_LIMB: &[Limb] = &POW10_32; -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] type Wide = u64; // 64-BIT LIMB -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] pub type Limb = u64; -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] pub const POW5_LIMB: &[Limb] = &POW5_64; -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] pub const POW10_LIMB: &[Limb] = &POW10_64; -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] type Wide = u128; /// Cast to limb type. @@ -79,14 +79,14 @@ fn as_wide(t: T) -> Wide { /// Split u64 into limbs, in little-endian order. #[inline] -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] fn split_u64(x: u64) -> [Limb; 2] { [as_limb(x), as_limb(x >> 32)] } /// Split u64 into limbs, in little-endian order. #[inline] -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] fn split_u64(x: u64) -> [Limb; 1] { [as_limb(x)] } diff --git a/src/lexical/mod.rs b/src/lexical/mod.rs index f5ff13cee..aeed4065e 100644 --- a/src/lexical/mod.rs +++ b/src/lexical/mod.rs @@ -28,10 +28,10 @@ pub(crate) mod rounding; mod shift; mod small_powers; -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] mod large_powers32; -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] mod large_powers64; // API diff --git a/src/lexical/small_powers.rs b/src/lexical/small_powers.rs index 51d638a13..29b83a159 100644 --- a/src/lexical/small_powers.rs +++ b/src/lexical/small_powers.rs @@ -3,19 +3,19 @@ //! Pre-computed small powers. // 32 BIT -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub(crate) const POW5_32: [u32; 14] = [ 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625, 1220703125, ]; -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub(crate) const POW10_32: [u32; 10] = [ 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, ]; // 64 BIT -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] pub(crate) const POW5_64: [u64; 28] = [ 1, 5, diff --git a/src/read.rs b/src/read.rs index e16b99fdc..b84ec223a 100644 --- a/src/read.rs +++ b/src/read.rs @@ -446,9 +446,9 @@ impl<'a> SliceRead<'a> { // benchmarks and it's cross-platform, so probably the right fit. // [1]: https://groups.google.com/forum/#!original/comp.lang.c/2HtQXvg7iKc/xOJeipH6KLMJ - #[cfg(arithmetic64)] + #[cfg(fast_arithmetic = "64")] type Chunk = u64; - #[cfg(arithmetic32)] + #[cfg(fast_arithmetic = "32")] type Chunk = u32; const STEP: usize = mem::size_of::(); diff --git a/tests/lexical/math.rs b/tests/lexical/math.rs index b758339df..454eaa606 100644 --- a/tests/lexical/math.rs +++ b/tests/lexical/math.rs @@ -18,12 +18,12 @@ impl Math for Bigint { } } -#[cfg(arithmetic32)] +#[cfg(fast_arithmetic = "32")] pub(crate) fn from_u32(x: &[u32]) -> Vec { x.iter().cloned().collect() } -#[cfg(arithmetic64)] +#[cfg(fast_arithmetic = "64")] pub(crate) fn from_u32(x: &[u32]) -> Vec { let mut v = Vec::::default(); for xi in x.chunks(2) {