-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathalias.rs
More file actions
302 lines (263 loc) · 6.55 KB
/
Copy pathalias.rs
File metadata and controls
302 lines (263 loc) · 6.55 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
macro_rules! number {
{ 1 } => { "one" };
{ 2 } => { "two" };
{ 4 } => { "four" };
{ 8 } => { "eight" };
{ $x:literal } => { stringify!($x) };
}
macro_rules! plural {
{ 1 } => { "" };
{ $x:literal } => { "s" };
}
macro_rules! alias {
{
$(
$element_ty:ty = {
$($alias:ident $num_elements:tt)*
}
)*
} => {
$(
$(
#[doc = concat!("A SIMD vector with ", number!($num_elements), " element", plural!($num_elements), " of type [`", stringify!($element_ty), "`].")]
#[allow(non_camel_case_types)]
pub type $alias = $crate::simd::Simd<$element_ty, $num_elements>;
)*
)*
}
}
macro_rules! mask_alias {
{
$(
$element_ty:ty : $size:literal = {
$($alias:ident $num_elements:tt)*
}
)*
} => {
$(
$(
#[doc = concat!("A SIMD mask with ", number!($num_elements), " element", plural!($num_elements), " for vectors with ", $size, " element types.")]
///
#[doc = concat!(
"The layout of this type is unspecified, and may change between platforms and/or Rust versions, and code should not assume that it is equivalent to `[",
stringify!($element_ty), "; ", $num_elements, "]`."
)]
#[allow(non_camel_case_types)]
pub type $alias = $crate::simd::Mask<$element_ty, $num_elements>;
)*
)*
}
}
alias! {
i8 = {
i8x1 1
i8x2 2
i8x4 4
i8x8 8
i8x16 16
i8x32 32
i8x64 64
}
i16 = {
i16x1 1
i16x2 2
i16x4 4
i16x8 8
i16x16 16
i16x32 32
i16x64 64
}
i32 = {
i32x1 1
i32x2 2
i32x4 4
i32x8 8
i32x16 16
i32x32 32
i32x64 64
}
i64 = {
i64x1 1
i64x2 2
i64x4 4
i64x8 8
i64x16 16
i64x32 32
i64x64 64
}
isize = {
isizex1 1
isizex2 2
isizex4 4
isizex8 8
isizex16 16
isizex32 32
isizex64 64
}
u8 = {
u8x1 1
u8x2 2
u8x4 4
u8x8 8
u8x16 16
u8x32 32
u8x64 64
}
u16 = {
u16x1 1
u16x2 2
u16x4 4
u16x8 8
u16x16 16
u16x32 32
u16x64 64
}
u32 = {
u32x1 1
u32x2 2
u32x4 4
u32x8 8
u32x16 16
u32x32 32
u32x64 64
}
u64 = {
u64x1 1
u64x2 2
u64x4 4
u64x8 8
u64x16 16
u64x32 32
u64x64 64
}
usize = {
usizex1 1
usizex2 2
usizex4 4
usizex8 8
usizex16 16
usizex32 32
usizex64 64
}
f32 = {
f32x1 1
f32x2 2
f32x4 4
f32x8 8
f32x16 16
f32x32 32
f32x64 64
}
f64 = {
f64x1 1
f64x2 2
f64x4 4
f64x8 8
f64x16 16
f64x32 32
f64x64 64
}
}
mask_alias! {
i8 : "8-bit" = {
mask8x1 1
mask8x2 2
mask8x4 4
mask8x8 8
mask8x16 16
mask8x32 32
mask8x64 64
}
i16 : "16-bit" = {
mask16x1 1
mask16x2 2
mask16x4 4
mask16x8 8
mask16x16 16
mask16x32 32
mask16x64 64
}
i32 : "32-bit" = {
mask32x1 1
mask32x2 2
mask32x4 4
mask32x8 8
mask32x16 16
mask32x32 32
mask32x64 64
}
i64 : "64-bit" = {
mask64x1 1
mask64x2 2
mask64x4 4
mask64x8 8
mask64x16 16
mask64x32 32
mask64x64 64
}
isize : "pointer-sized" = {
masksizex1 1
masksizex2 2
masksizex4 4
masksizex8 8
masksizex16 16
masksizex32 32
masksizex64 64
}
}
// Generic SIMD type aliases for writing code generic over lane count.
//
// Use these when writing functions that work with any lane count N (1-64).
// Example: fn dot_product<const N: usize>(a: f32xN<N>, b: f32xN<N>) -> f32
/// Generic `Simd<i8, N>` vector type.
#[allow(non_camel_case_types)]
pub type i8xN<const N: usize> = crate::simd::Simd<i8, N>;
/// Generic `Simd<i16, N>` vector type.
#[allow(non_camel_case_types)]
pub type i16xN<const N: usize> = crate::simd::Simd<i16, N>;
/// Generic `Simd<i32, N>` vector type.
#[allow(non_camel_case_types)]
pub type i32xN<const N: usize> = crate::simd::Simd<i32, N>;
/// Generic `Simd<i64, N>` vector type.
#[allow(non_camel_case_types)]
pub type i64xN<const N: usize> = crate::simd::Simd<i64, N>;
/// Generic `Simd<isize, N>` vector type.
#[allow(non_camel_case_types)]
pub type isizexN<const N: usize> = crate::simd::Simd<isize, N>;
/// Generic `Simd<u8, N>` vector type.
#[allow(non_camel_case_types)]
pub type u8xN<const N: usize> = crate::simd::Simd<u8, N>;
/// Generic `Simd<u16, N>` vector type.
#[allow(non_camel_case_types)]
pub type u16xN<const N: usize> = crate::simd::Simd<u16, N>;
/// Generic `Simd<u32, N>` vector type.
#[allow(non_camel_case_types)]
pub type u32xN<const N: usize> = crate::simd::Simd<u32, N>;
/// Generic `Simd<u64, N>` vector type.
#[allow(non_camel_case_types)]
pub type u64xN<const N: usize> = crate::simd::Simd<u64, N>;
/// Generic `Simd<usize, N>` vector type.
#[allow(non_camel_case_types)]
pub type usizexN<const N: usize> = crate::simd::Simd<usize, N>;
/// Generic `Simd<f32, N>` vector type.
#[allow(non_camel_case_types)]
pub type f32xN<const N: usize> = crate::simd::Simd<f32, N>;
/// Generic `Simd<f64, N>` vector type.
#[allow(non_camel_case_types)]
pub type f64xN<const N: usize> = crate::simd::Simd<f64, N>;
// Generic mask type aliases
/// Generic `Mask<i8, N>` mask type for 8-bit lanes.
#[allow(non_camel_case_types)]
pub type mask8xN<const N: usize> = crate::simd::Mask<i8, N>;
/// Generic `Mask<i16, N>` mask type for 16-bit lanes.
#[allow(non_camel_case_types)]
pub type mask16xN<const N: usize> = crate::simd::Mask<i16, N>;
/// Generic `Mask<i32, N>` mask type for 32-bit lanes.
#[allow(non_camel_case_types)]
pub type mask32xN<const N: usize> = crate::simd::Mask<i32, N>;
/// Generic `Mask<i64, N>` mask type for 64-bit lanes.
#[allow(non_camel_case_types)]
pub type mask64xN<const N: usize> = crate::simd::Mask<i64, N>;
/// Generic `Mask<isize, N>` mask type for pointer-sized lanes.
#[allow(non_camel_case_types)]
pub type masksizexN<const N: usize> = crate::simd::Mask<isize, N>;