mirror of
https://github.com/serde-rs/json.git
synced 2025-09-27 13:00:52 +00:00
Improve cfg names for fast arithmetic
This commit is contained in:
parent
4b1048d0ec
commit
ffc4a43453
7
build.rs
7
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\"");
|
||||
}
|
||||
}
|
||||
|
@ -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::*;
|
||||
|
@ -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: Integer>(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)]
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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::<Chunk>();
|
||||
|
@ -18,12 +18,12 @@ impl Math for Bigint {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(arithmetic32)]
|
||||
#[cfg(fast_arithmetic = "32")]
|
||||
pub(crate) fn from_u32(x: &[u32]) -> Vec<Limb> {
|
||||
x.iter().cloned().collect()
|
||||
}
|
||||
|
||||
#[cfg(arithmetic64)]
|
||||
#[cfg(fast_arithmetic = "64")]
|
||||
pub(crate) fn from_u32(x: &[u32]) -> Vec<Limb> {
|
||||
let mut v = Vec::<Limb>::default();
|
||||
for xi in x.chunks(2) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user