From da7a8ec1483e46e8880becba37e39183c9d0c757 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 13 Feb 2024 09:37:18 +0000 Subject: [PATCH 1/6] Remove mention of stdsimd This is no longer needed (likely since rust#117372). --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8ade2881d5..dc9e29d627 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ #![deny(missing_debug_implementations)] #![doc(test(attr(allow(unused_variables), deny(warnings))))] #![no_std] -#![cfg_attr(feature = "simd_support", feature(stdsimd, portable_simd))] +#![cfg_attr(feature = "simd_support", feature(portable_simd))] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![allow( clippy::float_cmp, From 34006c59fbd939e7d6d992013960530794071a5e Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 13 Feb 2024 09:41:20 +0000 Subject: [PATCH 2/6] Move fns FloatSIMDUtils::replace, extract to new cfg-gated trait FloatSIMDScalarUtils --- src/distributions/uniform.rs | 1 + src/distributions/utils.rs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 879d8ea258..4bb9931c18 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -1250,6 +1250,7 @@ impl UniformSampler for UniformDuration { mod tests { use super::*; use crate::rngs::mock::StepRng; + use crate::distributions::utils::FloatSIMDScalarUtils; #[test] #[cfg(feature = "serde1")] diff --git a/src/distributions/utils.rs b/src/distributions/utils.rs index f3b3089d7e..0b4b46ff0e 100644 --- a/src/distributions/utils.rs +++ b/src/distributions/utils.rs @@ -228,8 +228,12 @@ pub(crate) trait FloatSIMDUtils { // value, not by retaining the binary representation. type UInt; fn cast_from_int(i: Self::UInt) -> Self; +} +#[cfg(test)] +pub(crate) trait FloatSIMDScalarUtils: FloatSIMDUtils { type Scalar; + fn replace(self, index: usize, new_value: Self::Scalar) -> Self; fn extract(self, index: usize) -> Self::Scalar; } @@ -308,7 +312,6 @@ macro_rules! scalar_float_impl { impl FloatSIMDUtils for $ty { type Mask = bool; - type Scalar = $ty; type UInt = $uty; #[inline(always)] @@ -351,6 +354,11 @@ macro_rules! scalar_float_impl { fn cast_from_int(i: Self::UInt) -> Self { i as $ty } + } + + #[cfg(test)] + impl FloatSIMDScalarUtils for $ty { + type Scalar = $ty; #[inline] fn replace(self, index: usize, new_value: Self::Scalar) -> Self { @@ -380,7 +388,6 @@ macro_rules! simd_impl { where LaneCount: SupportedLaneCount { type Mask = Mask<<$fty as SimdElement>::Mask, LANES>; - type Scalar = $fty; type UInt = Simd<$uty, LANES>; #[inline(always)] @@ -429,6 +436,14 @@ macro_rules! simd_impl { fn cast_from_int(i: Self::UInt) -> Self { i.cast() } + } + + #[cfg(test)] + impl FloatSIMDScalarUtils for Simd<$fty, LANES> + where + LaneCount: SupportedLaneCount, + { + type Scalar = $fty; #[inline] fn replace(mut self, index: usize, new_value: Self::Scalar) -> Self { From 73651f41784c0a91c224a169629272c6f9e4e27a Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 13 Feb 2024 09:46:05 +0000 Subject: [PATCH 3/6] Remove unused utility methods on floats, bool --- src/distributions/utils.rs | 40 -------------------------------------- 1 file changed, 40 deletions(-) diff --git a/src/distributions/utils.rs b/src/distributions/utils.rs index 0b4b46ff0e..e3ef5bcdb8 100644 --- a/src/distributions/utils.rs +++ b/src/distributions/utils.rs @@ -238,16 +238,6 @@ pub(crate) trait FloatSIMDScalarUtils: FloatSIMDUtils { fn extract(self, index: usize) -> Self::Scalar; } -/// Implement functions available in std builds but missing from core primitives -#[cfg(not(std))] -// False positive: We are following `std` here. -#[allow(clippy::wrong_self_convention)] -pub(crate) trait Float: Sized { - fn is_nan(self) -> bool; - fn is_infinite(self) -> bool; - fn is_finite(self) -> bool; -} - /// Implement functions on f32/f64 to give them APIs similar to SIMD types pub(crate) trait FloatAsSIMD: Sized { const LEN: usize = 1; @@ -269,8 +259,6 @@ impl IntAsSIMD for u64 {} pub(crate) trait BoolAsSIMD: Sized { fn any(self) -> bool; - fn all(self) -> bool; - fn none(self) -> bool; } impl BoolAsSIMD for bool { @@ -278,38 +266,10 @@ impl BoolAsSIMD for bool { fn any(self) -> bool { self } - - #[inline(always)] - fn all(self) -> bool { - self - } - - #[inline(always)] - fn none(self) -> bool { - !self - } } macro_rules! scalar_float_impl { ($ty:ident, $uty:ident) => { - #[cfg(not(std))] - impl Float for $ty { - #[inline] - fn is_nan(self) -> bool { - self != self - } - - #[inline] - fn is_infinite(self) -> bool { - self == ::core::$ty::INFINITY || self == ::core::$ty::NEG_INFINITY - } - - #[inline] - fn is_finite(self) -> bool { - !(self.is_nan() || self.is_infinite()) - } - } - impl FloatSIMDUtils for $ty { type Mask = bool; type UInt = $uty; From 38fdd548a697d33a2eab6a036623276c218eadbc Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 13 Feb 2024 09:46:28 +0000 Subject: [PATCH 4/6] Remove unused import --- rand_distr/tests/pdf.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rand_distr/tests/pdf.rs b/rand_distr/tests/pdf.rs index 14db18153a..b4fd781092 100644 --- a/rand_distr/tests/pdf.rs +++ b/rand_distr/tests/pdf.rs @@ -9,7 +9,7 @@ #![allow(clippy::float_cmp)] use average::Histogram; -use rand::{Rng, SeedableRng}; +use rand::Rng; use rand_distr::{Normal, SkewNormal}; const HIST_LEN: usize = 100; From e4e03437861b6a0ae9f364795721be99812392b9 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 13 Feb 2024 08:49:23 +0000 Subject: [PATCH 5/6] Update to zerocopy 0.8.0-alpha.5 --- Cargo.toml | 2 +- rand_core/Cargo.toml | 2 +- rand_core/src/impls.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index da14228a54..b2c7f3d616 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ rand_core = { path = "rand_core", version = "0.7.0", default-features = false } log = { version = "0.4.4", optional = true } serde = { version = "1.0.103", features = ["derive"], optional = true } rand_chacha = { path = "rand_chacha", version = "0.4.0", default-features = false, optional = true } -zerocopy = { version = "0.7.20", default-features = false, features = ["simd"] } +zerocopy = { version = "=0.8.0-alpha.5", default-features = false, features = ["simd"] } [target.'cfg(unix)'.dependencies] # Used for fork protection (reseeding.rs) diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index 8c9d902a70..b53a01634b 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -32,4 +32,4 @@ serde1 = ["serde"] # enables serde for BlockRng wrapper [dependencies] serde = { version = "1", features = ["derive"], optional = true } getrandom = { version = "0.2", optional = true } -zerocopy = { version = "0.7.20", default-features = false } +zerocopy = { version = "=0.8.0-alpha.5", default-features = false } diff --git a/rand_core/src/impls.rs b/rand_core/src/impls.rs index d7dcd3457d..a8fc1a7e8c 100644 --- a/rand_core/src/impls.rs +++ b/rand_core/src/impls.rs @@ -19,7 +19,7 @@ use crate::RngCore; use core::cmp::min; -use zerocopy::AsBytes; +use zerocopy::{IntoBytes, NoCell}; /// Implement `next_u64` via `next_u32`, little-endian order. pub fn next_u64_via_u32(rng: &mut R) -> u64 { @@ -53,7 +53,7 @@ pub fn fill_bytes_via_next(rng: &mut R, dest: &mut [u8]) { } } -trait Observable: AsBytes + Copy { +trait Observable: IntoBytes + NoCell + Copy { fn to_le(self) -> Self; } impl Observable for u32 { From d3bae4d400fbf739865a7244708d91d21d1b4b43 Mon Sep 17 00:00:00 2001 From: Diggory Hardy Date: Tue, 13 Feb 2024 10:04:08 +0000 Subject: [PATCH 6/6] Remove unneeded import of Float --- src/distributions/uniform.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index 4bb9931c18..5e6b6ae3f9 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -115,10 +115,6 @@ use crate::distributions::Distribution; use crate::distributions::Standard; use crate::{Rng, RngCore}; -#[cfg(not(feature = "std"))] -#[allow(unused_imports)] // rustc doesn't detect that this is actually used -use crate::distributions::utils::Float; - #[cfg(feature = "simd_support")] use core::simd::prelude::*; #[cfg(feature = "simd_support")] use core::simd::{LaneCount, SupportedLaneCount};