1+ use core:: mem:: { size_of, MaybeUninit } ;
2+ use core:: slice;
3+
14use crate :: simd:: * ;
25
36// Given two token streams in the format `ignore_snd!([first_token_tree], [second])` will simply
@@ -9,7 +12,7 @@ macro_rules! ignore_snd (
912
1013macro_rules! impl_rand_auto_simd (
1114 ( $( $t: ty, $( $i: ident) ,* ; ) * ) => ( $(
12- impl rand:: distributions :: Distribution <AutoSimd <$t>> for rand:: distributions :: Standard {
15+ impl rand:: distr :: Distribution <AutoSimd <$t>> for rand:: distr :: StandardUniform {
1316 #[ inline( always) ]
1417 fn sample<R : rand:: Rng + ?Sized >( & self , rng: & mut R ) -> AutoSimd <$t> {
1518 AutoSimd :: <$t>:: new( $(
@@ -49,9 +52,6 @@ impl_rand_auto_simd!(
4952 [ i8 ; 16 ] , _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
5053 [ 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;
5154 // [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;
52- [ isize ; 2 ] , _0, _1;
53- [ isize ; 4 ] , _0, _1, _2, _3;
54- [ isize ; 8 ] , _0, _1, _2, _3, _4, _5, _6, _7;
5555 [ u128 ; 1 ] , _0;
5656 [ u128 ; 2 ] , _0, _1;
5757 [ u128 ; 4 ] , _0, _1, _2, _3;
@@ -73,9 +73,6 @@ impl_rand_auto_simd!(
7373 [ u8 ; 16 ] , _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
7474 [ 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;
7575 // [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;
76- [ usize ; 2 ] , _0, _1;
77- [ usize ; 4 ] , _0, _1, _2, _3;
78- [ usize ; 8 ] , _0, _1, _2, _3, _4, _5, _6, _7;
7976 [ bool ; 1 ] , _0;
8077 [ bool ; 2 ] , _0, _1;
8178 [ bool ; 4 ] , _0, _1, _2, _3;
@@ -85,10 +82,32 @@ impl_rand_auto_simd!(
8582 // [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;
8683) ;
8784
85+ macro_rules! impl_rand_auto_simd_xsize (
86+ ( $( $t: ty, $sampler: ident, $( $i: ident) ,* ; ) * ) => ( $(
87+ impl rand:: distr:: Distribution <AutoSimd <$t>> for rand:: distr:: StandardUniform {
88+ #[ inline( always) ]
89+ fn sample<R : rand:: Rng + ?Sized >( & self , rng: & mut R ) -> AutoSimd <$t> {
90+ AutoSimd :: <$t>:: new( $(
91+ ignore_snd!( [ $sampler( rng) ] , [ $i] )
92+ ) ,* )
93+ }
94+ }
95+ ) * )
96+ ) ;
97+
98+ impl_rand_auto_simd_xsize ! (
99+ [ isize ; 2 ] , sample_isize, _0, _1;
100+ [ isize ; 4 ] , sample_isize, _0, _1, _2, _3;
101+ [ isize ; 8 ] , sample_isize, _0, _1, _2, _3, _4, _5, _6, _7;
102+ [ usize ; 2 ] , sample_usize, _0, _1;
103+ [ usize ; 4 ] , sample_usize, _0, _1, _2, _3;
104+ [ usize ; 8 ] , sample_usize, _0, _1, _2, _3, _4, _5, _6, _7;
105+ ) ;
106+
88107#[ cfg( feature = "wide" ) ]
89108macro_rules! impl_rand_wide_simd (
90109 ( $( $t: ident, $wrapped: ty, $arr: ty; ) * ) => ( $(
91- impl rand:: distributions :: Distribution <$t> for rand:: distributions :: Standard {
110+ impl rand:: distr :: Distribution <$t> for rand:: distr :: StandardUniform {
92111 #[ inline( always) ]
93112 fn sample<R : rand:: Rng + ?Sized >( & self , rng: & mut R ) -> $t {
94113 $t( <$wrapped as From <$arr>>:: from( self . sample( rng) ) )
@@ -107,7 +126,7 @@ impl_rand_wide_simd!(
107126#[ cfg( feature = "portable_simd" ) ]
108127macro_rules! impl_rand_portable_simd (
109128 ( $( $wrapped: ty, $( $i: ident) ,* ; ) * ) => ( $(
110- impl rand:: distributions :: Distribution <$wrapped> for rand:: distributions :: Standard {
129+ impl rand:: distr :: Distribution <$wrapped> for rand:: distr :: StandardUniform {
111130 #[ inline( always) ]
112131 fn sample<R : rand:: Rng + ?Sized >( & self , rng: & mut R ) -> $wrapped {
113132 <$wrapped>:: new( $(
@@ -145,9 +164,6 @@ impl_rand_portable_simd!(
145164 i8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
146165 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;
147166 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;
148- isizex2, _0, _1;
149- isizex4, _0, _1, _2, _3;
150- isizex8, _0, _1, _2, _3, _4, _5, _6, _7;
151167 u16x2, _0, _1;
152168 u16x4, _0, _1, _2, _3;
153169 u16x8, _0, _1, _2, _3, _4, _5, _6, _7;
@@ -166,9 +182,6 @@ impl_rand_portable_simd!(
166182 u8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
167183 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;
168184 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;
169- usizex2, _0, _1;
170- usizex4, _0, _1, _2, _3;
171- usizex8, _0, _1, _2, _3, _4, _5, _6, _7;
172185 mask16x2, _0, _1;
173186 mask16x4, _0, _1, _2, _3;
174187 mask16x8, _0, _1, _2, _3, _4, _5, _6, _7;
@@ -191,3 +204,51 @@ impl_rand_portable_simd!(
191204 masksizex4, _0, _1, _2, _3;
192205 masksizex8, _0, _1, _2, _3, _4, _5, _6, _7;
193206) ;
207+
208+ #[ cfg( feature = "portable_simd" ) ]
209+ macro_rules! impl_rand_portable_simd_xsize (
210+ ( $( $wrapped: ty, $sampler: ident, $( $i: ident) ,* ; ) * ) => ( $(
211+ impl rand:: distr:: Distribution <$wrapped> for rand:: distr:: StandardUniform {
212+ #[ inline( always) ]
213+ fn sample<R : rand:: Rng + ?Sized >( & self , rng: & mut R ) -> $wrapped {
214+ <$wrapped>:: new( $(
215+ ignore_snd!( [ $sampler( rng) ] , [ $i] )
216+ ) ,* )
217+ }
218+ }
219+ ) * )
220+ ) ;
221+
222+ #[ cfg( feature = "portable_simd" ) ]
223+ impl_rand_portable_simd_xsize ! (
224+ isizex2, sample_isize, _0, _1;
225+ isizex4, sample_isize, _0, _1, _2, _3;
226+ isizex8, sample_isize, _0, _1, _2, _3, _4, _5, _6, _7;
227+ usizex2, sample_usize, _0, _1;
228+ usizex4, sample_usize, _0, _1, _2, _3;
229+ usizex8, sample_usize, _0, _1, _2, _3, _4, _5, _6, _7;
230+ ) ;
231+
232+ #[ inline( always) ]
233+ fn sample_isize < R : rand:: Rng + ?Sized > ( rng : & mut R ) -> isize {
234+ let mut result: MaybeUninit < isize > = MaybeUninit :: uninit ( ) ;
235+ unsafe {
236+ rng. fill_bytes ( slice:: from_raw_parts_mut (
237+ result. as_mut_ptr ( ) . cast ( ) ,
238+ size_of :: < isize > ( ) ,
239+ ) ) ;
240+ result. assume_init ( )
241+ }
242+ }
243+
244+ #[ inline( always) ]
245+ fn sample_usize < R : rand:: Rng + ?Sized > ( rng : & mut R ) -> usize {
246+ let mut result: MaybeUninit < usize > = MaybeUninit :: uninit ( ) ;
247+ unsafe {
248+ rng. fill_bytes ( slice:: from_raw_parts_mut (
249+ result. as_mut_ptr ( ) . cast ( ) ,
250+ size_of :: < usize > ( ) ,
251+ ) ) ;
252+ result. assume_init ( )
253+ }
254+ }
0 commit comments