1 //! `FromBits` and `IntoBits` between portable vector types and the
2 //! architecture-specific vector types.
3 #[rustfmt::skip]
4 
5 // FIXME: MIPS FromBits/IntoBits
6 
7 #[allow(unused)]
8 use crate::*;
9 
10 /// This macro implements FromBits for the portable and the architecture
11 /// specific vector types.
12 ///
13 /// The "leaf" case is at the bottom, and the most generic case is at the top.
14 /// The generic case is split into smaller cases recursively.
15 macro_rules! impl_arch {
16     ([$arch_head_i:ident[$arch_head_tt:tt]: $($arch_head_ty:ident),*],
17      $([$arch_tail_i:ident[$arch_tail_tt:tt]: $($arch_tail_ty:ident),*]),* |
18      from: $($from_ty:ident),* | into: $($into_ty:ident),* |
19      test: $test_tt:tt) => {
20         impl_arch!(
21             [$arch_head_i[$arch_head_tt]: $($arch_head_ty),*] |
22             from: $($from_ty),* |
23             into: $($into_ty),* |
24             test: $test_tt
25         );
26         impl_arch!(
27             $([$arch_tail_i[$arch_tail_tt]: $($arch_tail_ty),*]),* |
28             from: $($from_ty),* |
29             into: $($into_ty),* |
30             test: $test_tt
31         );
32     };
33     ([$arch:ident[$arch_tt:tt]: $($arch_ty:ident),*] |
34      from: $($from_ty:ident),* | into: $($into_ty:ident),* |
35      test: $test_tt:tt) => {
36         // note: if target is "arm", "+v7,+neon" must be enabled
37         // and the std library must be recompiled with them
38         #[cfg(any(
39             not(target_arch = "arm"),
40             all(target_feature = "v7", target_feature = "neon",
41                 any(feature = "core_arch", libcore_neon)))
42         )]
43         // note: if target is "powerpc", "altivec" must be enabled
44         // and the std library must be recompiled with it
45         #[cfg(any(
46             not(target_arch = "powerpc"),
47             all(target_feature = "altivec", feature = "core_arch"),
48         ))]
49         #[cfg(target_arch = $arch_tt)]
50         use crate::arch::$arch::{
51             $($arch_ty),*
52         };
53 
54         #[cfg(any(
55             not(target_arch = "arm"),
56             all(target_feature = "v7", target_feature = "neon",
57                 any(feature = "core_arch", libcore_neon)))
58         )]
59         #[cfg(any(
60             not(target_arch = "powerpc"),
61             all(target_feature = "altivec", feature = "core_arch"),
62         ))]
63         #[cfg(target_arch = $arch_tt)]
64         impl_arch!($($arch_ty),* | $($from_ty),* | $($into_ty),* |
65                    test: $test_tt);
66     };
67     ($arch_head:ident, $($arch_tail:ident),* | $($from_ty:ident),*
68      | $($into_ty:ident),* | test: $test_tt:tt) => {
69         impl_arch!($arch_head | $($from_ty),* | $($into_ty),* |
70                    test: $test_tt);
71         impl_arch!($($arch_tail),* | $($from_ty),* | $($into_ty),* |
72                    test: $test_tt);
73     };
74     ($arch_head:ident | $($from_ty:ident),* | $($into_ty:ident),* |
75      test: $test_tt:tt) => {
76         impl_from_bits!($arch_head[$test_tt]: $($from_ty),*);
77         impl_into_bits!($arch_head[$test_tt]: $($into_ty),*);
78     };
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 // Implementations for the 64-bit wide vector types:
83 
84 // FIXME: 64-bit single element types
85 // FIXME: arm/aarch float16x4_t missing
86 impl_arch!(
87     [
88         arm["arm"]: int8x8_t,
89         uint8x8_t,
90         poly8x8_t,
91         int16x4_t,
92         uint16x4_t,
93         poly16x4_t,
94         int32x2_t,
95         uint32x2_t,
96         float32x2_t,
97         int64x1_t,
98         uint64x1_t
99     ],
100     [
101         aarch64["aarch64"]: int8x8_t,
102         uint8x8_t,
103         poly8x8_t,
104         int16x4_t,
105         uint16x4_t,
106         poly16x4_t,
107         int32x2_t,
108         uint32x2_t,
109         float32x2_t,
110         int64x1_t,
111         uint64x1_t,
112         float64x1_t
113     ] | from: i8x8,
114     u8x8,
115     m8x8,
116     i16x4,
117     u16x4,
118     m16x4,
119     i32x2,
120     u32x2,
121     f32x2,
122     m32x2 | into: i8x8,
123     u8x8,
124     i16x4,
125     u16x4,
126     i32x2,
127     u32x2,
128     f32x2 | test: test_v64
129 );
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 // Implementations for the 128-bit wide vector types:
133 
134 // FIXME: arm/aarch float16x8_t missing
135 // FIXME: ppc vector_pixel missing
136 // FIXME: ppc64 vector_Float16 missing
137 // FIXME: ppc64 vector_signed_long_long missing
138 // FIXME: ppc64 vector_unsigned_long_long missing
139 // FIXME: ppc64 vector_bool_long_long missing
140 // FIXME: ppc64 vector_signed___int128 missing
141 // FIXME: ppc64 vector_unsigned___int128 missing
142 impl_arch!(
143     [x86["x86"]: __m128, __m128i, __m128d],
144     [x86_64["x86_64"]: __m128, __m128i, __m128d],
145     [
146         arm["arm"]: int8x16_t,
147         uint8x16_t,
148         poly8x16_t,
149         int16x8_t,
150         uint16x8_t,
151         poly16x8_t,
152         int32x4_t,
153         uint32x4_t,
154         float32x4_t,
155         int64x2_t,
156         uint64x2_t
157     ],
158     [
159         aarch64["aarch64"]: int8x16_t,
160         uint8x16_t,
161         poly8x16_t,
162         int16x8_t,
163         uint16x8_t,
164         poly16x8_t,
165         int32x4_t,
166         uint32x4_t,
167         float32x4_t,
168         int64x2_t,
169         uint64x2_t,
170         float64x2_t
171     ],
172     [
173         powerpc["powerpc"]: vector_signed_char,
174         vector_unsigned_char,
175         vector_signed_short,
176         vector_unsigned_short,
177         vector_signed_int,
178         vector_unsigned_int,
179         vector_float
180     ],
181     [
182         powerpc64["powerpc64"]: vector_signed_char,
183         vector_unsigned_char,
184         vector_signed_short,
185         vector_unsigned_short,
186         vector_signed_int,
187         vector_unsigned_int,
188         vector_float,
189         vector_signed_long,
190         vector_unsigned_long,
191         vector_double
192     ] | from: i8x16,
193     u8x16,
194     m8x16,
195     i16x8,
196     u16x8,
197     m16x8,
198     i32x4,
199     u32x4,
200     f32x4,
201     m32x4,
202     i64x2,
203     u64x2,
204     f64x2,
205     m64x2,
206     i128x1,
207     u128x1,
208     m128x1 | into: i8x16,
209     u8x16,
210     i16x8,
211     u16x8,
212     i32x4,
213     u32x4,
214     f32x4,
215     i64x2,
216     u64x2,
217     f64x2,
218     i128x1,
219     u128x1 | test: test_v128
220 );
221 
222 impl_arch!(
223     [powerpc["powerpc"]: vector_bool_char],
224     [powerpc64["powerpc64"]: vector_bool_char] | from: m8x16,
225     m16x8,
226     m32x4,
227     m64x2,
228     m128x1 | into: i8x16,
229     u8x16,
230     i16x8,
231     u16x8,
232     i32x4,
233     u32x4,
234     f32x4,
235     i64x2,
236     u64x2,
237     f64x2,
238     i128x1,
239     u128x1,
240     // Masks:
241     m8x16 | test: test_v128
242 );
243 
244 impl_arch!(
245     [powerpc["powerpc"]: vector_bool_short],
246     [powerpc64["powerpc64"]: vector_bool_short] | from: m16x8,
247     m32x4,
248     m64x2,
249     m128x1 | into: i8x16,
250     u8x16,
251     i16x8,
252     u16x8,
253     i32x4,
254     u32x4,
255     f32x4,
256     i64x2,
257     u64x2,
258     f64x2,
259     i128x1,
260     u128x1,
261     // Masks:
262     m8x16,
263     m16x8 | test: test_v128
264 );
265 
266 impl_arch!(
267     [powerpc["powerpc"]: vector_bool_int],
268     [powerpc64["powerpc64"]: vector_bool_int] | from: m32x4,
269     m64x2,
270     m128x1 | into: i8x16,
271     u8x16,
272     i16x8,
273     u16x8,
274     i32x4,
275     u32x4,
276     f32x4,
277     i64x2,
278     u64x2,
279     f64x2,
280     i128x1,
281     u128x1,
282     // Masks:
283     m8x16,
284     m16x8,
285     m32x4 | test: test_v128
286 );
287 
288 impl_arch!(
289     [powerpc64["powerpc64"]: vector_bool_long] | from: m64x2,
290     m128x1 | into: i8x16,
291     u8x16,
292     i16x8,
293     u16x8,
294     i32x4,
295     u32x4,
296     f32x4,
297     i64x2,
298     u64x2,
299     f64x2,
300     i128x1,
301     u128x1,
302     // Masks:
303     m8x16,
304     m16x8,
305     m32x4,
306     m64x2 | test: test_v128
307 );
308 
309 ////////////////////////////////////////////////////////////////////////////////
310 // Implementations for the 256-bit wide vector types
311 
312 impl_arch!(
313     [x86["x86"]: __m256, __m256i, __m256d],
314     [x86_64["x86_64"]: __m256, __m256i, __m256d] | from: i8x32,
315     u8x32,
316     m8x32,
317     i16x16,
318     u16x16,
319     m16x16,
320     i32x8,
321     u32x8,
322     f32x8,
323     m32x8,
324     i64x4,
325     u64x4,
326     f64x4,
327     m64x4,
328     i128x2,
329     u128x2,
330     m128x2 | into: i8x32,
331     u8x32,
332     i16x16,
333     u16x16,
334     i32x8,
335     u32x8,
336     f32x8,
337     i64x4,
338     u64x4,
339     f64x4,
340     i128x2,
341     u128x2 | test: test_v256
342 );
343 
344 ////////////////////////////////////////////////////////////////////////////////
345 // FIXME: Implementations for the 512-bit wide vector types
346