Debian Codegraph @

debian/missing-sources/simba/src/simd/rand_impl.rs

raw
1 use crate::simd::*;
2
3 // Given two token streams in the format `ignore_snd!([first_token_tree], [second])` will simply
4 // expand to the first one. This is useful in order to allow the repetition of some statement
5 // according to some repetition variable, without using the repetition variables.
6 macro_rules! ignore_snd (
7 ([$($fst: tt)*], [$($snd: tt)*]) => ($($fst)*)
8 );
9
10 macro_rules! impl_rand_auto_simd (
11 ($($t: ty, $($i: ident),*;)*) => ($(
12 impl rand::distributions::Distribution<AutoSimd<$t>> for rand::distributions::Standard {
13 #[inline(always)]
14 fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> AutoSimd<$t> {
15 AutoSimd::<$t>::new($(
16 ignore_snd!([self.sample(rng)], [$i])
17 ),*)
18 }
19 }
20 )*)
21 );
22
23 impl_rand_auto_simd!(
24 [f32; 2], _0, _1;
25 [f32; 4], _0, _1, _2, _3;
26 [f32; 8], _0, _1, _2, _3, _4, _5, _6, _7;
27 [f32; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
28 [f64; 2], _0, _1;
29 [f64; 4], _0, _1, _2, _3;
30 [f64; 8], _0, _1, _2, _3, _4, _5, _6, _7;
31 [i128; 1], _0;
32 [i128; 2], _0, _1;
33 [i128; 4], _0, _1, _2, _3;
34 [i16; 2], _0, _1;
35 [i16; 4], _0, _1, _2, _3;
36 [i16; 8], _0, _1, _2, _3, _4, _5, _6, _7;
37 [i16; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
38 [i16; 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;
39 [i32; 2], _0, _1;
40 [i32; 4], _0, _1, _2, _3;
41 [i32; 8], _0, _1, _2, _3, _4, _5, _6, _7;
42 [i32; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
43 [i64; 2], _0, _1;
44 [i64; 4], _0, _1, _2, _3;
45 [i64; 8], _0, _1, _2, _3, _4, _5, _6, _7;
46 [i8; 2], _0, _1;
47 [i8; 4], _0, _1, _2, _3;
48 [i8; 8], _0, _1, _2, _3, _4, _5, _6, _7;
49 [i8; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
50 [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;
51 // [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;
55 [u128; 1], _0;
56 [u128; 2], _0, _1;
57 [u128; 4], _0, _1, _2, _3;
58 [u16; 2], _0, _1;
59 [u16; 4], _0, _1, _2, _3;
60 [u16; 8], _0, _1, _2, _3, _4, _5, _6, _7;
61 [u16; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
62 [u16; 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;
63 [u32; 2], _0, _1;
64 [u32; 4], _0, _1, _2, _3;
65 [u32; 8], _0, _1, _2, _3, _4, _5, _6, _7;
66 [u32; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
67 [u64; 2], _0, _1;
68 [u64; 4], _0, _1, _2, _3;
69 [u64; 8], _0, _1, _2, _3, _4, _5, _6, _7;
70 [u8; 2], _0, _1;
71 [u8; 4], _0, _1, _2, _3;
72 [u8; 8], _0, _1, _2, _3, _4, _5, _6, _7;
73 [u8; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
74 [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;
75 // [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;
79 [bool; 1], _0;
80 [bool; 2], _0, _1;
81 [bool; 4], _0, _1, _2, _3;
82 [bool; 8], _0, _1, _2, _3, _4, _5, _6, _7;
83 [bool; 16], _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
84 [bool; 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;
85 // [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;
86 );
87
88 #[cfg(feature = "wide")]
89 macro_rules! impl_rand_wide_simd (
90 ($($t: ident, $wrapped: ty, $arr: ty;)*) => ($(
91 impl rand::distributions::Distribution<$t> for rand::distributions::Standard {
92 #[inline(always)]
93 fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $t {
94 $t(<$wrapped as From<$arr>>::from(self.sample(rng)))
95 }
96 }
97 )*)
98 );
99
100 #[cfg(feature = "wide")]
101 impl_rand_wide_simd!(
102 WideF32x4, wide::f32x4, [f32; 4];
103 WideF64x4, wide::f64x4, [f64; 4];
104 WideF32x8, wide::f32x8, [f32; 8];
105 );
106
107 #[cfg(feature = "portable_simd")]
108 macro_rules! impl_rand_portable_simd (
109 ($($wrapped: ty, $($i: ident),*;)*) => ($(
110 impl rand::distributions::Distribution<$wrapped> for rand::distributions::Standard {
111 #[inline(always)]
112 fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $wrapped {
113 <$wrapped>::new($(
114 ignore_snd!([self.sample(rng)], [$i])
115 ),*)
116 }
117 }
118 )*)
119 );
120
121 #[cfg(feature = "portable_simd")]
122 impl_rand_portable_simd!(
123 f32x2, _0, _1;
124 f32x4, _0, _1, _2, _3;
125 f32x8, _0, _1, _2, _3, _4, _5, _6, _7;
126 f32x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
127 f64x2, _0, _1;
128 f64x4, _0, _1, _2, _3;
129 f64x8, _0, _1, _2, _3, _4, _5, _6, _7;
130 i16x2, _0, _1;
131 i16x4, _0, _1, _2, _3;
132 i16x8, _0, _1, _2, _3, _4, _5, _6, _7;
133 i16x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
134 i16x32, _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;
135 i32x2, _0, _1;
136 i32x4, _0, _1, _2, _3;
137 i32x8, _0, _1, _2, _3, _4, _5, _6, _7;
138 i32x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
139 i64x2, _0, _1;
140 i64x4, _0, _1, _2, _3;
141 i64x8, _0, _1, _2, _3, _4, _5, _6, _7;
142 i8x2, _0, _1;
143 i8x4, _0, _1, _2, _3;
144 i8x8, _0, _1, _2, _3, _4, _5, _6, _7;
145 i8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
146 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;
147 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;
151 u16x2, _0, _1;
152 u16x4, _0, _1, _2, _3;
153 u16x8, _0, _1, _2, _3, _4, _5, _6, _7;
154 u16x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
155 u16x32, _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;
156 u32x2, _0, _1;
157 u32x4, _0, _1, _2, _3;
158 u32x8, _0, _1, _2, _3, _4, _5, _6, _7;
159 u32x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
160 u64x2, _0, _1;
161 u64x4, _0, _1, _2, _3;
162 u64x8, _0, _1, _2, _3, _4, _5, _6, _7;
163 u8x2, _0, _1;
164 u8x4, _0, _1, _2, _3;
165 u8x8, _0, _1, _2, _3, _4, _5, _6, _7;
166 u8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
167 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;
168 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;
172 mask16x2, _0, _1;
173 mask16x4, _0, _1, _2, _3;
174 mask16x8, _0, _1, _2, _3, _4, _5, _6, _7;
175 mask16x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
176 mask16x32, _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;
177 mask32x2, _0, _1;
178 mask32x4, _0, _1, _2, _3;
179 mask32x8, _0, _1, _2, _3, _4, _5, _6, _7;
180 mask32x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
181 mask64x2, _0, _1;
182 mask64x4, _0, _1, _2, _3;
183 mask64x8, _0, _1, _2, _3, _4, _5, _6, _7;
184 mask8x2, _0, _1;
185 mask8x4, _0, _1, _2, _3;
186 mask8x8, _0, _1, _2, _3, _4, _5, _6, _7;
187 mask8x16, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
188 mask8x32, _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;
189 mask8x64, _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;
190 masksizex2, _0, _1;
191 masksizex4, _0, _1, _2, _3;
192 masksizex8, _0, _1, _2, _3, _4, _5, _6, _7;
193 );