diff options
author | Daniel Mueller <deso@posteo.net> | 2020-04-04 14:39:19 -0700 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2020-04-04 14:39:19 -0700 |
commit | d0d9683df8398696147e7ee1fcffb2e4e957008c (patch) | |
tree | 4baa76712a76f4d072ee3936c07956580b230820 /rand/src/distributions/integer.rs | |
parent | 203e691f46d591a2cc8acdfd850fa9f5b0fb8a98 (diff) | |
download | nitrocli-d0d9683df8398696147e7ee1fcffb2e4e957008c.tar.gz nitrocli-d0d9683df8398696147e7ee1fcffb2e4e957008c.tar.bz2 |
Remove vendored dependencies
While it appears that by now we actually can get successful builds
without Cargo insisting on Internet access by virtue of using the
--frozen flag, maintaining vendored dependencies is somewhat of a pain
point. This state will also get worse with upcoming changes that replace
argparse in favor of structopt and pull in a slew of new dependencies by
doing so. Then there is also the repository structure aspect, which is
non-standard due to the way we vendor dependencies and a potential
source of confusion.
In order to fix these problems, this change removes all the vendored
dependencies we have.
Delete subrepo argparse/:argparse
Delete subrepo base32/:base32
Delete subrepo cc/:cc
Delete subrepo cfg-if/:cfg-if
Delete subrepo getrandom/:getrandom
Delete subrepo lazy-static/:lazy-static
Delete subrepo libc/:libc
Delete subrepo nitrokey-sys/:nitrokey-sys
Delete subrepo nitrokey/:nitrokey
Delete subrepo rand/:rand
Diffstat (limited to 'rand/src/distributions/integer.rs')
-rw-r--r-- | rand/src/distributions/integer.rs | 184 |
1 files changed, 0 insertions, 184 deletions
diff --git a/rand/src/distributions/integer.rs b/rand/src/distributions/integer.rs deleted file mode 100644 index 5238339..0000000 --- a/rand/src/distributions/integer.rs +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2018 Developers of the Rand project. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The implementations of the `Standard` distribution for integer types. - -use crate::{Rng}; -use crate::distributions::{Distribution, Standard}; -use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; -#[cfg(not(target_os = "emscripten"))] use core::num::NonZeroU128; -#[cfg(feature="simd_support")] -use packed_simd::*; -#[cfg(all(target_arch = "x86", feature="nightly"))] -use core::arch::x86::*; -#[cfg(all(target_arch = "x86_64", feature="nightly"))] -use core::arch::x86_64::*; - -impl Distribution<u8> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u8 { - rng.next_u32() as u8 - } -} - -impl Distribution<u16> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u16 { - rng.next_u32() as u16 - } -} - -impl Distribution<u32> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u32 { - rng.next_u32() - } -} - -impl Distribution<u64> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u64 { - rng.next_u64() - } -} - -#[cfg(not(target_os = "emscripten"))] -impl Distribution<u128> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u128 { - // Use LE; we explicitly generate one value before the next. - let x = u128::from(rng.next_u64()); - let y = u128::from(rng.next_u64()); - (y << 64) | x - } -} - -impl Distribution<usize> for Standard { - #[inline] - #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize { - rng.next_u32() as usize - } - - #[inline] - #[cfg(target_pointer_width = "64")] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> usize { - rng.next_u64() as usize - } -} - -macro_rules! impl_int_from_uint { - ($ty:ty, $uty:ty) => { - impl Distribution<$ty> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $ty { - rng.gen::<$uty>() as $ty - } - } - } -} - -impl_int_from_uint! { i8, u8 } -impl_int_from_uint! { i16, u16 } -impl_int_from_uint! { i32, u32 } -impl_int_from_uint! { i64, u64 } -#[cfg(not(target_os = "emscripten"))] impl_int_from_uint! { i128, u128 } -impl_int_from_uint! { isize, usize } - -macro_rules! impl_nzint { - ($ty:ty, $new:path) => { - impl Distribution<$ty> for Standard { - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $ty { - loop { - if let Some(nz) = $new(rng.gen()) { - break nz; - } - } - } - } - } -} - -impl_nzint!(NonZeroU8, NonZeroU8::new); -impl_nzint!(NonZeroU16, NonZeroU16::new); -impl_nzint!(NonZeroU32, NonZeroU32::new); -impl_nzint!(NonZeroU64, NonZeroU64::new); -#[cfg(not(target_os = "emscripten"))] impl_nzint!(NonZeroU128, NonZeroU128::new); -impl_nzint!(NonZeroUsize, NonZeroUsize::new); - -#[cfg(feature="simd_support")] -macro_rules! simd_impl { - ($(($intrinsic:ident, $vec:ty),)+) => {$( - impl Distribution<$intrinsic> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $intrinsic { - $intrinsic::from_bits(rng.gen::<$vec>()) - } - } - )+}; - - ($bits:expr,) => {}; - ($bits:expr, $ty:ty, $($ty_more:ty,)*) => { - simd_impl!($bits, $($ty_more,)*); - - impl Distribution<$ty> for Standard { - #[inline] - fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> $ty { - let mut vec: $ty = Default::default(); - unsafe { - let ptr = &mut vec; - let b_ptr = &mut *(ptr as *mut $ty as *mut [u8; $bits/8]); - rng.fill_bytes(b_ptr); - } - vec.to_le() - } - } - }; -} - -#[cfg(feature="simd_support")] -simd_impl!(16, u8x2, i8x2,); -#[cfg(feature="simd_support")] -simd_impl!(32, u8x4, i8x4, u16x2, i16x2,); -#[cfg(feature="simd_support")] -simd_impl!(64, u8x8, i8x8, u16x4, i16x4, u32x2, i32x2,); -#[cfg(feature="simd_support")] -simd_impl!(128, u8x16, i8x16, u16x8, i16x8, u32x4, i32x4, u64x2, i64x2,); -#[cfg(feature="simd_support")] -simd_impl!(256, u8x32, i8x32, u16x16, i16x16, u32x8, i32x8, u64x4, i64x4,); -#[cfg(feature="simd_support")] -simd_impl!(512, u8x64, i8x64, u16x32, i16x32, u32x16, i32x16, u64x8, i64x8,); -#[cfg(all(feature="simd_support", feature="nightly", any(target_arch="x86", target_arch="x86_64")))] -simd_impl!((__m64, u8x8), (__m128i, u8x16), (__m256i, u8x32),); - -#[cfg(test)] -mod tests { - use crate::Rng; - use crate::distributions::{Standard}; - - #[test] - fn test_integers() { - let mut rng = crate::test::rng(806); - - rng.sample::<isize, _>(Standard); - rng.sample::<i8, _>(Standard); - rng.sample::<i16, _>(Standard); - rng.sample::<i32, _>(Standard); - rng.sample::<i64, _>(Standard); - #[cfg(not(target_os = "emscripten"))] - rng.sample::<i128, _>(Standard); - - rng.sample::<usize, _>(Standard); - rng.sample::<u8, _>(Standard); - rng.sample::<u16, _>(Standard); - rng.sample::<u32, _>(Standard); - rng.sample::<u64, _>(Standard); - #[cfg(not(target_os = "emscripten"))] - rng.sample::<u128, _>(Standard); - } -} |