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
This commit is contained in:
parent
58add64ba4
commit
e5a366d07f
@ -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)
|
||||
|
@ -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 }
|
||||
|
@ -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<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]) {
|
||||
}
|
||||
}
|
||||
|
||||
trait Observable: AsBytes + Copy {
|
||||
trait Observable: IntoBytes + NoCell + Copy {
|
||||
fn to_le(self) -> Self;
|
||||
}
|
||||
impl Observable for u32 {
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
||||
@ -1250,6 +1246,7 @@ impl UniformSampler for UniformDuration {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::rngs::mock::StepRng;
|
||||
use crate::distributions::utils::FloatSIMDScalarUtils;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "serde1")]
|
||||
|
@ -228,20 +228,14 @@ pub(crate) trait FloatSIMDUtils {
|
||||
// value, not by retaining the binary representation.
|
||||
type UInt;
|
||||
fn cast_from_int(i: Self::UInt) -> Self;
|
||||
|
||||
type Scalar;
|
||||
fn replace(self, index: usize, new_value: Self::Scalar) -> Self;
|
||||
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;
|
||||
#[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;
|
||||
}
|
||||
|
||||
/// Implement functions on f32/f64 to give them APIs similar to SIMD types
|
||||
@ -265,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 {
|
||||
@ -274,41 +266,12 @@ 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 Scalar = $ty;
|
||||
type UInt = $uty;
|
||||
|
||||
#[inline(always)]
|
||||
@ -351,6 +314,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 +348,6 @@ macro_rules! simd_impl {
|
||||
where LaneCount<LANES>: SupportedLaneCount
|
||||
{
|
||||
type Mask = Mask<<$fty as SimdElement>::Mask, LANES>;
|
||||
type Scalar = $fty;
|
||||
type UInt = Simd<$uty, LANES>;
|
||||
|
||||
#[inline(always)]
|
||||
@ -429,6 +396,14 @@ macro_rules! simd_impl {
|
||||
fn cast_from_int(i: Self::UInt) -> Self {
|
||||
i.cast()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl<const LANES: usize> FloatSIMDScalarUtils for Simd<$fty, LANES>
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
type Scalar = $fty;
|
||||
|
||||
#[inline]
|
||||
fn replace(mut self, index: usize, new_value: Self::Scalar) -> Self {
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user