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
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
    }
}