Skip to content

Commit e5a366d

Browse files
authored
Update zerocopy; trim unused methods (#1393)
* Remove mention of stdsimd * Move fns FloatSIMDUtils::replace, extract to new cfg-gated trait FloatSIMDScalarUtils * Remove unused utility methods on floats, bool * Remove unused import * Update to zerocopy 0.8.0-alpha.5 * Remove unneeded import of Float
1 parent 58add64 commit e5a366d

File tree

7 files changed

+24
-52
lines changed

7 files changed

+24
-52
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ rand_core = { path = "rand_core", version = "0.7.0", default-features = false }
6969
log = { version = "0.4.4", optional = true }
7070
serde = { version = "1.0.103", features = ["derive"], optional = true }
7171
rand_chacha = { path = "rand_chacha", version = "0.4.0", default-features = false, optional = true }
72-
zerocopy = { version = "0.7.20", default-features = false, features = ["simd"] }
72+
zerocopy = { version = "=0.8.0-alpha.5", default-features = false, features = ["simd"] }
7373

7474
[target.'cfg(unix)'.dependencies]
7575
# Used for fork protection (reseeding.rs)

rand_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ serde1 = ["serde"] # enables serde for BlockRng wrapper
3232
[dependencies]
3333
serde = { version = "1", features = ["derive"], optional = true }
3434
getrandom = { version = "0.2", optional = true }
35-
zerocopy = { version = "0.7.20", default-features = false }
35+
zerocopy = { version = "=0.8.0-alpha.5", default-features = false }

rand_core/src/impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use crate::RngCore;
2121
use core::cmp::min;
22-
use zerocopy::AsBytes;
22+
use zerocopy::{IntoBytes, NoCell};
2323

2424
/// Implement `next_u64` via `next_u32`, little-endian order.
2525
pub fn next_u64_via_u32<R: RngCore + ?Sized>(rng: &mut R) -> u64 {
@@ -53,7 +53,7 @@ pub fn fill_bytes_via_next<R: RngCore + ?Sized>(rng: &mut R, dest: &mut [u8]) {
5353
}
5454
}
5555

56-
trait Observable: AsBytes + Copy {
56+
trait Observable: IntoBytes + NoCell + Copy {
5757
fn to_le(self) -> Self;
5858
}
5959
impl Observable for u32 {

rand_distr/tests/pdf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![allow(clippy::float_cmp)]
1010

1111
use average::Histogram;
12-
use rand::{Rng, SeedableRng};
12+
use rand::Rng;
1313
use rand_distr::{Normal, SkewNormal};
1414

1515
const HIST_LEN: usize = 100;

src/distributions/uniform.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ use crate::distributions::Distribution;
115115
use crate::distributions::Standard;
116116
use crate::{Rng, RngCore};
117117

118-
#[cfg(not(feature = "std"))]
119-
#[allow(unused_imports)] // rustc doesn't detect that this is actually used
120-
use crate::distributions::utils::Float;
121-
122118
#[cfg(feature = "simd_support")] use core::simd::prelude::*;
123119
#[cfg(feature = "simd_support")] use core::simd::{LaneCount, SupportedLaneCount};
124120

@@ -1250,6 +1246,7 @@ impl UniformSampler for UniformDuration {
12501246
mod tests {
12511247
use super::*;
12521248
use crate::rngs::mock::StepRng;
1249+
use crate::distributions::utils::FloatSIMDScalarUtils;
12531250

12541251
#[test]
12551252
#[cfg(feature = "serde1")]

src/distributions/utils.rs

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,16 @@ pub(crate) trait FloatSIMDUtils {
228228
// value, not by retaining the binary representation.
229229
type UInt;
230230
fn cast_from_int(i: Self::UInt) -> Self;
231+
}
231232

233+
#[cfg(test)]
234+
pub(crate) trait FloatSIMDScalarUtils: FloatSIMDUtils {
232235
type Scalar;
236+
233237
fn replace(self, index: usize, new_value: Self::Scalar) -> Self;
234238
fn extract(self, index: usize) -> Self::Scalar;
235239
}
236240

237-
/// Implement functions available in std builds but missing from core primitives
238-
#[cfg(not(std))]
239-
// False positive: We are following `std` here.
240-
#[allow(clippy::wrong_self_convention)]
241-
pub(crate) trait Float: Sized {
242-
fn is_nan(self) -> bool;
243-
fn is_infinite(self) -> bool;
244-
fn is_finite(self) -> bool;
245-
}
246-
247241
/// Implement functions on f32/f64 to give them APIs similar to SIMD types
248242
pub(crate) trait FloatAsSIMD: Sized {
249243
const LEN: usize = 1;
@@ -265,50 +259,19 @@ impl IntAsSIMD for u64 {}
265259

266260
pub(crate) trait BoolAsSIMD: Sized {
267261
fn any(self) -> bool;
268-
fn all(self) -> bool;
269-
fn none(self) -> bool;
270262
}
271263

272264
impl BoolAsSIMD for bool {
273265
#[inline(always)]
274266
fn any(self) -> bool {
275267
self
276268
}
277-
278-
#[inline(always)]
279-
fn all(self) -> bool {
280-
self
281-
}
282-
283-
#[inline(always)]
284-
fn none(self) -> bool {
285-
!self
286-
}
287269
}
288270

289271
macro_rules! scalar_float_impl {
290272
($ty:ident, $uty:ident) => {
291-
#[cfg(not(std))]
292-
impl Float for $ty {
293-
#[inline]
294-
fn is_nan(self) -> bool {
295-
self != self
296-
}
297-
298-
#[inline]
299-
fn is_infinite(self) -> bool {
300-
self == ::core::$ty::INFINITY || self == ::core::$ty::NEG_INFINITY
301-
}
302-
303-
#[inline]
304-
fn is_finite(self) -> bool {
305-
!(self.is_nan() || self.is_infinite())
306-
}
307-
}
308-
309273
impl FloatSIMDUtils for $ty {
310274
type Mask = bool;
311-
type Scalar = $ty;
312275
type UInt = $uty;
313276

314277
#[inline(always)]
@@ -351,6 +314,11 @@ macro_rules! scalar_float_impl {
351314
fn cast_from_int(i: Self::UInt) -> Self {
352315
i as $ty
353316
}
317+
}
318+
319+
#[cfg(test)]
320+
impl FloatSIMDScalarUtils for $ty {
321+
type Scalar = $ty;
354322

355323
#[inline]
356324
fn replace(self, index: usize, new_value: Self::Scalar) -> Self {
@@ -380,7 +348,6 @@ macro_rules! simd_impl {
380348
where LaneCount<LANES>: SupportedLaneCount
381349
{
382350
type Mask = Mask<<$fty as SimdElement>::Mask, LANES>;
383-
type Scalar = $fty;
384351
type UInt = Simd<$uty, LANES>;
385352

386353
#[inline(always)]
@@ -429,6 +396,14 @@ macro_rules! simd_impl {
429396
fn cast_from_int(i: Self::UInt) -> Self {
430397
i.cast()
431398
}
399+
}
400+
401+
#[cfg(test)]
402+
impl<const LANES: usize> FloatSIMDScalarUtils for Simd<$fty, LANES>
403+
where
404+
LaneCount<LANES>: SupportedLaneCount,
405+
{
406+
type Scalar = $fty;
432407

433408
#[inline]
434409
fn replace(mut self, index: usize, new_value: Self::Scalar) -> Self {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#![deny(missing_debug_implementations)]
5050
#![doc(test(attr(allow(unused_variables), deny(warnings))))]
5151
#![no_std]
52-
#![cfg_attr(feature = "simd_support", feature(stdsimd, portable_simd))]
52+
#![cfg_attr(feature = "simd_support", feature(portable_simd))]
5353
#![cfg_attr(doc_cfg, feature(doc_cfg))]
5454
#![allow(
5555
clippy::float_cmp,

0 commit comments

Comments
 (0)