Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Unreleased
- `rand` dependency updated to 0.9.

## Release v0.9.1 (05 Sept. 2025)
- `into_arr`, `from_arr`, `map`, `zip_map` are now public on `WideF32x4`, `WideF32x8` and `WideF64x4`.
- `from_arr` and `into_arr` are now public on `WideBoolF32x4`, `WideBoolF32x8`, `WideBoolF64x4`.
Expand Down Expand Up @@ -94,4 +97,4 @@ vectorization, if it can.
- Add the `libm_force` cargo feature that forces the use of `libm`, even when we don't target `no-std`.
- Add `copysign` to copy the sign from one number to another.
- Add `simd_horizontal_min`, `simd_horizontal_max` to compute the min/max among the lanes of a single SIMD number.
- Wrap all SIMD bools from `packed_simd` into our own `Simd<_>` newtype.
- Wrap all SIMD bools from `packed_simd` into our own `Simd<_>` newtype.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ wide = { version = "0.7", default-features = false, optional = true }
fixed = { version = "1", optional = true }
cordic = { version = "0.1", optional = true }
paste = "1.0"
rand = { version = "0.8", optional = true }
rand = { version = "0.9", optional = true }
serde = { version = "1", default-features = false, optional = true }
rkyv = { version = "0.7", optional = true }
libm_force = { package = "libm", version = "0.2", optional = true }
Expand Down
8 changes: 4 additions & 4 deletions src/scalar/fixed_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ macro_rules! impl_fixed_type (
}

#[cfg(feature = "rand")]
impl<Fract: $LeEqDim> rand::distributions::Distribution<$FixedI<Fract>> for rand::distributions::Standard {
impl<Fract: $LeEqDim> rand::distr::Distribution<$FixedI<Fract>> for rand::distr::StandardUniform {
#[inline]
fn sample<'a, G: rand::Rng + ?Sized>(&self, rng: &mut G) -> $FixedI<Fract> {
let bits = rng.gen();
let bits = rng.random();
$FixedI(fixed::$FixedI::from_bits(bits))
}
}

#[cfg(feature = "rand")]
impl<Fract: $LeEqDim> rand::distributions::Distribution<$FixedI<Fract>> for rand::distributions::OpenClosed01 {
impl<Fract: $LeEqDim> rand::distr::Distribution<$FixedI<Fract>> for rand::distr::OpenClosed01 {
#[inline]
fn sample<'a, G: rand::Rng + ?Sized>(&self, rng: &mut G) -> $FixedI<Fract> {
let val: f64 = rng.gen();
let val: f64 = rng.random();
$FixedI(fixed::$FixedI::from_num(val))
}
}
Expand Down
91 changes: 76 additions & 15 deletions src/simd/rand_impl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use core::mem::{size_of, MaybeUninit};
use core::slice;

use crate::simd::*;

// Given two token streams in the format `ignore_snd!([first_token_tree], [second])` will simply
Expand All @@ -9,7 +12,7 @@ macro_rules! ignore_snd (

macro_rules! impl_rand_auto_simd (
($($t: ty, $($i: ident),*;)*) => ($(
impl rand::distributions::Distribution<AutoSimd<$t>> for rand::distributions::Standard {
impl rand::distr::Distribution<AutoSimd<$t>> for rand::distr::StandardUniform {
#[inline(always)]
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> AutoSimd<$t> {
AutoSimd::<$t>::new($(
Expand Down Expand Up @@ -49,9 +52,6 @@ impl_rand_auto_simd!(
[i8; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
[i8; 32], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
// [i8; 64], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63;
[isize; 2], _0, _1;
[isize; 4], _0, _1, _2, _3;
[isize; 8], _0, _1, _2, _3, _4, _5, _6, _7;
[u128; 1], _0;
[u128; 2], _0, _1;
[u128; 4], _0, _1, _2, _3;
Expand All @@ -73,9 +73,6 @@ impl_rand_auto_simd!(
[u8; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
[u8; 32], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
// [u8; 64], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63;
[usize; 2], _0, _1;
[usize; 4], _0, _1, _2, _3;
[usize; 8], _0, _1, _2, _3, _4, _5, _6, _7;
[bool; 1], _0;
[bool; 2], _0, _1;
[bool; 4], _0, _1, _2, _3;
Expand All @@ -85,10 +82,32 @@ impl_rand_auto_simd!(
// [bool; 64], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63;
);

macro_rules! impl_rand_auto_simd_xsize (
($($t: ty, $sampler: ident, $($i: ident),*;)*) => ($(
impl rand::distr::Distribution<AutoSimd<$t>> for rand::distr::StandardUniform {
#[inline(always)]
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> AutoSimd<$t> {
AutoSimd::<$t>::new($(
ignore_snd!([$sampler(rng)], [$i])
),*)
}
}
)*)
);

impl_rand_auto_simd_xsize!(
[isize; 2], sample_isize, _0, _1;
[isize; 4], sample_isize, _0, _1, _2, _3;
[isize; 8], sample_isize, _0, _1, _2, _3, _4, _5, _6, _7;
[usize; 2], sample_usize, _0, _1;
[usize; 4], sample_usize, _0, _1, _2, _3;
[usize; 8], sample_usize, _0, _1, _2, _3, _4, _5, _6, _7;
);

#[cfg(feature = "wide")]
macro_rules! impl_rand_wide_simd (
($($t: ident, $wrapped: ty, $arr: ty;)*) => ($(
impl rand::distributions::Distribution<$t> for rand::distributions::Standard {
impl rand::distr::Distribution<$t> for rand::distr::StandardUniform {
#[inline(always)]
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $t {
$t(<$wrapped as From<$arr>>::from(self.sample(rng)))
Expand All @@ -107,7 +126,7 @@ impl_rand_wide_simd!(
#[cfg(feature = "portable_simd")]
macro_rules! impl_rand_portable_simd (
($($wrapped: ty, $($i: ident),*;)*) => ($(
impl rand::distributions::Distribution<$wrapped> for rand::distributions::Standard {
impl rand::distr::Distribution<$wrapped> for rand::distr::StandardUniform {
#[inline(always)]
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $wrapped {
<$wrapped>::new($(
Expand Down Expand Up @@ -145,9 +164,6 @@ impl_rand_portable_simd!(
i8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
i8x32, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
i8x64, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63;
isizex2, _0, _1;
isizex4, _0, _1, _2, _3;
isizex8, _0, _1, _2, _3, _4, _5, _6, _7;
u16x2, _0, _1;
u16x4, _0, _1, _2, _3;
u16x8, _0, _1, _2, _3, _4, _5, _6, _7;
Expand All @@ -166,9 +182,6 @@ impl_rand_portable_simd!(
u8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
u8x32, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31;
u8x64, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63;
usizex2, _0, _1;
usizex4, _0, _1, _2, _3;
usizex8, _0, _1, _2, _3, _4, _5, _6, _7;
mask16x2, _0, _1;
mask16x4, _0, _1, _2, _3;
mask16x8, _0, _1, _2, _3, _4, _5, _6, _7;
Expand All @@ -191,3 +204,51 @@ impl_rand_portable_simd!(
masksizex4, _0, _1, _2, _3;
masksizex8, _0, _1, _2, _3, _4, _5, _6, _7;
);

#[cfg(feature = "portable_simd")]
macro_rules! impl_rand_portable_simd_xsize (
($($wrapped: ty, $sampler: ident, $($i: ident),*;)*) => ($(
impl rand::distr::Distribution<$wrapped> for rand::distr::StandardUniform {
#[inline(always)]
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $wrapped {
<$wrapped>::new($(
ignore_snd!([$sampler(rng)], [$i])
),*)
}
}
)*)
);

#[cfg(feature = "portable_simd")]
impl_rand_portable_simd_xsize!(
isizex2, sample_isize, _0, _1;
isizex4, sample_isize, _0, _1, _2, _3;
isizex8, sample_isize, _0, _1, _2, _3, _4, _5, _6, _7;
usizex2, sample_usize, _0, _1;
usizex4, sample_usize, _0, _1, _2, _3;
usizex8, sample_usize, _0, _1, _2, _3, _4, _5, _6, _7;
);

#[inline(always)]
fn sample_isize<R: rand::Rng + ?Sized>(rng: &mut R) -> isize {
let mut result: MaybeUninit<isize> = MaybeUninit::uninit();
unsafe {
rng.fill_bytes(slice::from_raw_parts_mut(
result.as_mut_ptr().cast(),
size_of::<isize>(),
));
result.assume_init()
}
}

#[inline(always)]
fn sample_usize<R: rand::Rng + ?Sized>(rng: &mut R) -> usize {
let mut result: MaybeUninit<usize> = MaybeUninit::uninit();
unsafe {
rng.fill_bytes(slice::from_raw_parts_mut(
result.as_mut_ptr().cast(),
size_of::<usize>(),
));
result.assume_init()
}
}